_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q239500
|
Routes.getRoutes
|
train
|
protected function getRoutes(): array
{
uasort($this->routes, function (RouteInterface $left, RouteInterface $right) {
if ($left instanceof GroupRoute || $right instanceof GroupRoute) {
return 1;
}
return 0;
});
return $this->routes;
}
|
php
|
{
"resource": ""
}
|
q239501
|
HydrationFailed.encountered
|
train
|
public static function encountered(
Throwable $exception,
object $target
): CannotHydrate {
return new HydrationFailed(withMessage(
'Could not hydrate the `%s`: %s',
theClassOfThe($target),
$exception->getMessage()
), 0, $exception);
}
|
php
|
{
"resource": ""
}
|
q239502
|
Configuration.getWebResourceClassName
|
train
|
public function getWebResourceClassName($contentType)
{
return ($this->hasMappedWebResourceClassName($contentType))
? $this->contentTypeWebResourceMap[(string)$contentType]
: self::DEFAULT_WEB_RESOURCE_MODEL;
}
|
php
|
{
"resource": ""
}
|
q239503
|
Loader.setConfig
|
train
|
public function setConfig($config)
{
$configObject = $this->getConfig();
if (is_object($config)) {
$config = get_object_vars($config);
}
foreach ((array)$config as $key => $value) {
$configObject->$key = $value;
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239504
|
Loader.registerAssetBundle
|
train
|
public function registerAssetBundle($name)
{
if (($bundle = $this->getAssetBundleFromView($name)) === false) {
return $bundle;
}
$config = $this->getConfig();
if (!($module = $config->getModule($name))) {
$module = $config->addModule($name);
}
$options = $bundle->jsOptions;
if (!isset($options['position'])) {
$options['position'] = View::POS_END;
}
$options['baseUrl'] = $bundle->baseUrl;
$module->setOptions($options);
// TODO: think about optimization
foreach ($bundle->depends as $dependency) {
if (($dependency = $this->registerAssetBundle($dependency)) !== false) {
$module->addDependency($dependency);
}
}
$this->importJsFilesFromBundle($bundle, $module);
return $module;
}
|
php
|
{
"resource": ""
}
|
q239505
|
Loader.processAssets
|
train
|
public function processAssets()
{
$jsExpressions = [];
foreach ([
View::POS_HEAD,
View::POS_BEGIN,
View::POS_END,
View::POS_LOAD,
View::POS_READY
] as $position
) {
if ($this->ignoredPositions->match($position)) {
continue;
}
if (($jsExpression = $this->createJsExpression($position)) === null) {
continue;
}
$jsExpressions[$position] = $jsExpression;
}
$this->doRender($jsExpressions);
}
|
php
|
{
"resource": ""
}
|
q239506
|
ArrayCache.set
|
train
|
public function set($key, $data, $ttl = null)
{
if ($ttl) {
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$expire = (int) $now->format('U') + $ttl;
} else {
$expire = 0;
}
$entry = array(
'expire' => $expire,
'value' => $data
);
$this->storage[$key] = $entry;
return true;
}
|
php
|
{
"resource": ""
}
|
q239507
|
Stop.json
|
train
|
public static function json($var, $continue = false, $hide = false, $return = false){
$Stop = new \Stop\Dumper\Json($hide, $continue, $return, Dumper\AbstractDumper::FORMAT_JSON);
$Stop->var_dump($var);
}
|
php
|
{
"resource": ""
}
|
q239508
|
StatementAbstract.buildSql
|
train
|
protected function buildSql(array $settings)/*# : string */
{
$result = $this->getType(); // type
$settings['join'] = $settings['seperator'] . $settings['indent'];
$result .= $this->buildBeforeAfter('AFTER', 'TYPE', $settings); // hint
foreach ($this->getConfigs() as $pos => $prefix) {
// before
$result .= $this->buildBeforeAfter('BEFORE', $pos, $settings);
$method = 'build' . ucfirst(strtolower($pos));
$result .= $this->{$method}($prefix, $settings);
// after
$result .= $this->buildBeforeAfter('AFTER', $pos, $settings);
}
$result .= $this->buildBeforeAfter('AFTER', 'STMT', $settings);
return $result;
}
|
php
|
{
"resource": ""
}
|
q239509
|
CrudController.getFormEntity
|
train
|
protected function getFormEntity(Request $request)
{
if ($this->formEntity === null) {
$entityId = $request->get('id');
$repository = $this->getRepository();
$entity = null;
$id = 0;
if (!empty($entityId) && $entityId !== null) {
$entity = $repository->findOneById($entityId);
$id = $entity->getId();
}
if (!is_object($entity) || empty($id)) {
// new form, return empty entity
$entity_class_name = $repository->getClassName();
$entity = new $entity_class_name();
}
$this->formEntity = $entity;
}
return $this->formEntity;
}
|
php
|
{
"resource": ""
}
|
q239510
|
BaseFlysystemProvider.getFilesystem
|
train
|
protected function getFilesystem()
{
if (!isset($this->filesystem)) {
$this->filesystem = new Filesystem($this->getAdapter());
}
return $this->filesystem;
}
|
php
|
{
"resource": ""
}
|
q239511
|
GnuplotFactory.create
|
train
|
public function create($template)
{
if (!isset($this->plotters[$template])) {
throw new \InvalidArgumentException("Unknown template [$template]");
}
$className = $this->plotters[$template];
return new $className($this->finderFactory);
}
|
php
|
{
"resource": ""
}
|
q239512
|
TypedUtils.groupByType
|
train
|
public static function groupByType(array $objects)
{
$perType = [];
foreach ($objects as $object) {
$type = $object->getType();
if (!isset($perType[$type])) {
$perType[$type] = [];
}
$perType[$type][] = $object;
}
return $perType;
}
|
php
|
{
"resource": ""
}
|
q239513
|
RESTLyte.request
|
train
|
public function request($verb, $path, $accept, array $customCURLOptions=[])
{
$verb = strtoupper(
trim(
$verb
)
);
$instantiateClass = "\\Lamoni\\RESTLyte\\RESTLyteRequest\\RESTLyteRequest{$this->getResponseType()}";
$request = new $instantiateClass(
$this->getServer(),
$verb,
$path,
$this->getAuthCredentials(),
$accept,
$this->getVerifySSLPeer(),
$this->getHTTPHeaders(),
$customCURLOptions
);
return $request->getResponse();
}
|
php
|
{
"resource": ""
}
|
q239514
|
RESTLyte.post
|
train
|
public function post($path, $postData, $accept="")
{
return $this->request(
'POST',
$path,
$accept,
[
CURLOPT_POSTFIELDS => $postData
]
);
}
|
php
|
{
"resource": ""
}
|
q239515
|
RESTLyte.put
|
train
|
public function put($path, $postData, $accept="")
{
return $this->request(
'PUT',
$path,
$accept,
[
CURLOPT_POSTFIELDS => $postData
]
);
}
|
php
|
{
"resource": ""
}
|
q239516
|
RESTLyte.patch
|
train
|
public function patch($path, $postData, $accept="")
{
return $this->request(
'PATCH',
$path,
$accept,
[
CURLOPT_POSTFIELDS => $postData
]
);
}
|
php
|
{
"resource": ""
}
|
q239517
|
RESTLyte.delete
|
train
|
public function delete($path, $postData, $accept="")
{
return $this->request(
'DELETE',
$path,
$accept,
[
CURLOPT_POSTFIELDS => $postData
]
);
}
|
php
|
{
"resource": ""
}
|
q239518
|
DecodedRawOutput.isWellFormed
|
train
|
public function isWellFormed()
{
if (!is_array($this->decodedRawOutput)) {
return false;
}
if (!isset($this->decodedRawOutput[0]) || !is_string($this->decodedRawOutput[0])) {
return false;
}
if (!isset($this->decodedRawOutput[1]) || !is_array($this->decodedRawOutput[1])) {
return false;
}
return true;
}
|
php
|
{
"resource": ""
}
|
q239519
|
Result.setStatus
|
train
|
public function setStatus(Result\ResultStatus $status)
{
if (Result\ResultStatus::UNPROCESSED !== $status->getValue()) {
$this->transacted = true;
$this->dateTransacted = new DateTime();
}
if (!$this->transaction->isParent()
&& Result\ResultStatus::ERROR !== $status->getValue()
&& Result\ResultStatus::UNPROCESSED !== $status->getValue()) {
$this->transaction->getParent()->setStatus($status);
}
$this->transaction->setStatus($status);
$this->status = $status;
}
|
php
|
{
"resource": ""
}
|
q239520
|
GroupTableMap.doInsert
|
train
|
public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(GroupTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from Group object
}
if ($criteria->containsKey(GroupTableMap::COL_ID) && $criteria->keyContainsValue(GroupTableMap::COL_ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.GroupTableMap::COL_ID.')');
}
// Set the correct dbName
$query = GroupQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
}
|
php
|
{
"resource": ""
}
|
q239521
|
EmailService.queueEmail
|
train
|
public function queueEmail(
$type,
$to,
$fromEmail,
$fromName,
$subject,
$body = null,
$contentType = 'text/html',
$template = null,
$parameters = [],
$cc = [],
$bcc = [],
$delaySeconds = 0
) {
$payload = [
'to' => $to,
'fromName' => $fromName,
'fromEmail' => $fromEmail,
'subject' => $subject,
'cc' => $cc,
'bcc' => $bcc,
];
if ($type === self::SEND_TEMPLATE) {
$method = 'performSendTemplate';
$payload['template'] = $template;
$payload['parameters'] = $parameters;
} else {
$method = 'performSend';
$payload['body'] = $body;
$payload['contentType'] = $contentType;
}
return $this->addJob('email', $payload, self::class, $delaySeconds, $method);
}
|
php
|
{
"resource": ""
}
|
q239522
|
BackupCommandController.restoreCommand
|
train
|
public function restoreCommand($selectedBackup = null)
{
$this->initialize();
if (is_null($selectedBackup)) {
$availableVersions = $this->backupService->getAvailableVersions();
if ( count($availableVersions)<=0 ) {
$this->output->outputLine();
$this->output->outputLine('<b>You have no Backups!</b>');
$this->output->outputLine();
$this->output->outputLine('Call \'./flow backup:now\' and create one.');
$this->output->outputLine();
return;
}
$selectedBackup = $this->askWithSelectForVersion($availableVersions);
}
$this->backupService->restoreBackup($selectedBackup);
}
|
php
|
{
"resource": ""
}
|
q239523
|
BackupCommandController.listCommand
|
train
|
public function listCommand()
{
$this->output->outputLine();
$this->output->outputLine('<b>Available Backups</b>');
$this->output->outputLine();
$this->output->outputLine('<b>Identifier Date Time</b>');
$this->initialize();
$availableVersions = $this->backupService->getAvailableVersions();
foreach ($availableVersions as $version) {
if ( is_numeric($version) ) {
$this->output->outputLine($version . ': ' . date('d.m.Y H:i', $version * 1));
}
}
$this->output->outputLine();
}
|
php
|
{
"resource": ""
}
|
q239524
|
BackupCommandController.clearCommand
|
train
|
public function clearCommand($force = null)
{
$this->initialize();
$this->backupService->removeAllBackups();
if ( $force===true ) {
$this->backupService->removeKeyfile();
}
}
|
php
|
{
"resource": ""
}
|
q239525
|
RouteService.attach
|
train
|
public function attach($methods, $match, $callable)
{
if (is_string($methods)) {
$methods = [$methods];
}
$route = new Route($methods, $callable);
$this->storage[$match] = $route;
return $route;
}
|
php
|
{
"resource": ""
}
|
q239526
|
Services.registerCoreClass
|
train
|
public static function registerCoreClass(string $class): bool
{
if (class_exists($class) === false) {
return false;
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Core") === true) {
self::$core_class = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239527
|
Services.registerModulesClass
|
train
|
public static function registerModulesClass(string $class): bool
{
if (class_exists($class) === false) {
return false;
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Modules") === true) {
self::$modules_class = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239528
|
Services.registerThemeClass
|
train
|
public static function registerThemeClass(string $class): bool
{
if (class_exists($class) === false) {
return false;
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Theme") === true) {
self::$theme_class = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239529
|
Services.registerPluginClass
|
train
|
public static function registerPluginClass(string $name, string $class): bool
{
if (class_exists($class) === false) {
return false;
}
if (self::$plugin_classes === null) {
self::$plugin_classes = [];
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Plugin") === true) {
self::$plugin_classes[$name] = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239530
|
Services.getPluginClass
|
train
|
public static function getPluginClass(string $name): string
{
$class = "";
if (empty($name) === false && empty(self::$plugin_classes[$name]) === false) {
$class = self::$plugin_classes[$name];
}
return $class;
}
|
php
|
{
"resource": ""
}
|
q239531
|
Services.registerExtensionClass
|
train
|
public static function registerExtensionClass(string $name, string $class): bool
{
if (class_exists($class) === false) {
return false;
}
if (self::$extension_classes === null) {
self::$extension_classes = [];
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Extension") === true) {
self::$extension_classes[$name] = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239532
|
Services.getExtensionClass
|
train
|
public static function getExtensionClass(string $name): string
{
$class = "";
if (empty($name) === false && empty(self::$extension_classes[$name]) === false) {
$class = self::$extension_classes[$name];
}
return $class;
}
|
php
|
{
"resource": ""
}
|
q239533
|
Services.registerAdminClass
|
train
|
public static function registerAdminClass(string $name, string $class): bool
{
if (class_exists($class) === false) {
return false;
}
if (self::$admin_classes === null) {
self::$admin_classes = [];
}
$check = new ReflectionClass($class);
if ($check->implementsInterface("TheCMSThread\\Classes\\Admin") === true) {
self::$admin_classes[$name] = $class;
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239534
|
Services.getAdminClass
|
train
|
public static function getAdminClass(string $name): string
{
$class = "";
if (empty($name) === false && empty(self::$admin_classes[$name]) === false) {
$class = self::$admin_classes[$name];
}
return $class;
}
|
php
|
{
"resource": ""
}
|
q239535
|
Event.register
|
train
|
public static function register()
{
$namespace = "Vinala\App\Events";
foreach (get_declared_classes() as $value) {
if (Strings::contains($value, $namespace)) {
$name = self::getName($value);
$events = $value::getEvents();
if (!is_null($events)) {
foreach ($events as $key => $value) {
$data[$name.'.'.$key] = $value;
}
}
self::$listners = array_collapse([$data, self::$listners]);
}
}
}
|
php
|
{
"resource": ""
}
|
q239536
|
Event.trigger
|
train
|
public static function trigger()
{
$args = func_get_args();
//Check if trigger have parrams
$haveParams = count($args) > 1 ? true : false;
//Get events
$events = self::splite($args[0]);
if ($haveParams && count($events) > 1) {
throw new ManyListenersArgumentsException();
}
if (count($events) > 1) {
self::runMany($events);
} elseif (count($events) == 1) {
self::runOne($events, array_except($args, 0));
}
return true;
}
|
php
|
{
"resource": ""
}
|
q239537
|
Event.splite
|
train
|
protected static function splite($pattern)
{
if (is_array($pattern)) {
$events = [];
foreach ($pattern as $value) {
$events = array_collapse([$events, self::extract($value)]);
}
return $events;
} elseif (is_string($pattern)) {
return self::extract($pattern);
}
}
|
php
|
{
"resource": ""
}
|
q239538
|
Event.extract
|
train
|
protected static function extract($pattern)
{
if (str_contains($pattern, '|')) {
$segements = explode('|', $pattern);
$events[$segements[0]] = explode('.', $segements[1]);
} else {
$segements = explode('.', $pattern);
$events[$segements[0]] = $segements[1];
}
return $events;
}
|
php
|
{
"resource": ""
}
|
q239539
|
Event.runMany
|
train
|
public static function runMany($events)
{
foreach ($events as $key => $value) {
$name = '\Vinala\App\Events\\'.$key;
$object = new $name();
if (is_array($value)) {
foreach ($value as $function) {
$function = self::$listners[$key.'.'.$function];
$object->$function();
}
} elseif (is_string($value)) {
$function = self::$listners[$key.'.'.$value];
$object->$function();
}
}
return true;
}
|
php
|
{
"resource": ""
}
|
q239540
|
Event.runOne
|
train
|
public static function runOne($events, $args)
{
foreach ($events as $key => $value) {
$name = '\Vinala\App\Events\\'.$key;
$object = new $name();
$function = self::$listners[$key.'.'.$value];
call_user_func_array([$object, $function], $args);
}
return true;
}
|
php
|
{
"resource": ""
}
|
q239541
|
Filesystem.rawLog
|
train
|
public function rawLog(string $type = '', string $message = '', ?string $source = null, ?string $excp = null): bool
{
$src = $source !== null
? \sprintf('[%s] ', \is_object($source) ? '\\'.\get_class($source) : (string)$source)
: '';
$exc = $excp !== null && ($excp instanceof \Exception) ? \sprintf('[Ex: %s] ', $excp->getMessage()) : '';
$exc = \str_replace(["\r", "\n", "\t"], '', $exc);
$msg = \sprintf('%s %s %s%s%s%s', \date('d-m-Y H:i:s'), $type, $src, $exc, $message, Tags::CRLF);
return File::append($this->logFile, $msg);
}
|
php
|
{
"resource": ""
}
|
q239542
|
Filesystem.logDebug
|
train
|
public function logDebug(string $message = '', ?string $source = null, ?string $exception = null): bool
{
$ret = false;
if ($this->logLevel & Log::LOG_DEBUG) {
$ret = $this->rawLog('[ DEBUG]', $message, $source, $exception);
}
return $ret;
}
|
php
|
{
"resource": ""
}
|
q239543
|
InfoAugment.methods
|
train
|
public function methods() {
return $this->cache(__METHOD__, function() {
return array_unique(array_merge(
$this->publicMethods(),
$this->protectedMethods(),
$this->privateMethods(),
$this->staticMethods()
));
});
}
|
php
|
{
"resource": ""
}
|
q239544
|
InfoAugment.properties
|
train
|
public function properties() {
return $this->cache(__METHOD__, function() {
return array_unique(array_merge(
$this->publicProperties(),
$this->protectedProperties(),
$this->privateProperties(),
$this->staticProperties()
));
});
}
|
php
|
{
"resource": ""
}
|
q239545
|
InfoAugment.traits
|
train
|
public function traits() {
$traits = $this->reflection()->getTraitNames();
$parent = get_parent_class($this->_class);
while ($parent) {
$traits = array_merge($traits, class_uses($parent));
$parent = get_parent_class($parent);
}
return array_values($traits);
}
|
php
|
{
"resource": ""
}
|
q239546
|
InfoAugment._methods
|
train
|
protected function _methods($key, $scope) {
return $this->cache($key, function() use ($scope) {
$methods = [];
foreach ($this->reflection()->getMethods($scope) as $method) {
$methods[] = $method->getName();
}
return $methods;
});
}
|
php
|
{
"resource": ""
}
|
q239547
|
InfoAugment._properties
|
train
|
protected function _properties($key, $scope) {
return $this->cache($key, function() use ($scope) {
$props = [];
foreach ($this->reflection()->getProperties($scope) as $prop) {
$props[] = $prop->getName();
}
return $props;
});
}
|
php
|
{
"resource": ""
}
|
q239548
|
Controller.check_access
|
train
|
protected function check_access($action = null)
{
is_null($action) and $action = $this->request->action;
if ($this->has_access($action) === false)
{
$context = array(
'form' => array(
'%action%' => $action,
'%items%' => $this->get_name(999),
)
);
\Logger::instance('alert')->error(gettext('You are not authorized to %action% %items%.'), $context);
return \Response::redirect_back(\Uri::admin(false));
}
}
|
php
|
{
"resource": ""
}
|
q239549
|
Controller.find
|
train
|
protected function find($id = null)
{
$query = $this->query();
$query->where('id', $id);
if (is_null($id) or is_null($model = $query->get_one()))
{
throw new \HttpNotFoundException();
}
return $model;
}
|
php
|
{
"resource": ""
}
|
q239550
|
Controller.forge
|
train
|
protected function forge($data = [], $new = true, $view = null, $cache = true)
{
return call_user_func([$this->get_model(), 'forge'], $data, $new, $view, $cache);
}
|
php
|
{
"resource": ""
}
|
q239551
|
Exception.create
|
train
|
public static function create($name, $message, $view)
{
$root = Process::root;
$name = ucfirst($name);
$path = $root."app/exceptions/$name.php";
//
if (!File::exists($path)) {
File::put($path, self::set($name, $message, $view));
return true;
} else {
return false;
}
}
|
php
|
{
"resource": ""
}
|
q239552
|
TransformerTrait.includeDefaultIncludes
|
train
|
protected function includeDefaultIncludes($model, $data)
{
// Create an return array
$returnData = [];
// If we have default includes
if ( ! empty( $this->defaultIncludes ) ) {
// Loop through all includes
foreach ($this->defaultIncludes as $include) {
// Add the new data
$returnData[ $include ] = $this->includeByName( $include, $model );
}
}
// Return data
return array_merge( $data, $returnData );
}
|
php
|
{
"resource": ""
}
|
q239553
|
TransformerTrait.includeAvailableIncludes
|
train
|
protected function includeAvailableIncludes($model, $data )
{
// Get available includes from url parameters
$includes = $this->getAvailableIncludesFromUrlParameters();
// Create an return array
$returnData = [];
// Check if we have includes and include parameter values
if ( ! empty( $includes ) && ! empty( $this->availableIncludes ) ) {
// Loop through all includes
foreach ($this->availableIncludes as $include) {
// If the words exists in both includes
if ( in_array( $include, $includes ) ) {
// Add the new data
$returnData[ $include ] = $this->includeByName( $include, $model );
}
}
}
// Return data
return array_merge( $data, $returnData );
}
|
php
|
{
"resource": ""
}
|
q239554
|
TransformerTrait.includeByName
|
train
|
protected function includeByName( $name, $model )
{
$functionName = sprintf( 'include%s', ucfirst( $name ) );
if ( ! method_exists( static::class, $functionName ) ) {
throw new \Exception(sprintf( 'The function name "%s" does not exists on %s', $functionName, static::class ));
}
return $this->{$functionName}( $model );
}
|
php
|
{
"resource": ""
}
|
q239555
|
IconFileRepository.findByHashes
|
train
|
public function findByHashes(array $hashes): array
{
$result = [];
if (count($hashes) > 0) {
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select('if')
->from(IconFile::class, 'if')
->andWhere('if.hash IN (:hashes)')
->setParameter('hashes', array_values(array_map('hex2bin', $hashes)));
$result = $queryBuilder->getQuery()->getResult();
}
return $result;
}
|
php
|
{
"resource": ""
}
|
q239556
|
IconFileRepository.removeOrphans
|
train
|
public function removeOrphans(): void
{
$hashes = $this->findOrphanedHashes();
if (count($hashes) > 0) {
$this->removeHashes($hashes);
}
}
|
php
|
{
"resource": ""
}
|
q239557
|
IconFileRepository.findOrphanedHashes
|
train
|
protected function findOrphanedHashes(): array
{
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select('if.hash AS hash')
->from(IconFile::class, 'if')
->leftJoin('if.icons', 'i')
->andWhere('i.id IS NULL');
$result = [];
foreach ($queryBuilder->getQuery()->getResult() as $data) {
$result[] = $data['hash'];
}
return $result;
}
|
php
|
{
"resource": ""
}
|
q239558
|
IconFileRepository.removeHashes
|
train
|
protected function removeHashes(array $hashes): void
{
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->delete(IconFile::class, 'if')
->andWhere('if.hash IN (:hashes)')
->setParameter('hashes', array_values($hashes));
$queryBuilder->getQuery()->execute();
}
|
php
|
{
"resource": ""
}
|
q239559
|
LoopsAdmin.exec
|
train
|
public function exec($arguments) {
//parse
$options = $this->parse();
// check if help was requested
if(is_integer($options)) {
return $options;
}
// extract and remove special vars
$instance = $options["__instance"];
$method = $options["__method"];
unset($options["__instance"]);
unset($options["__method"]);
// execute action - print error on failure
try {
return (int)Misc::reflectionFunction([ $instance, $method ], self::adjustOptions($options));
}
catch(Exception $e) {
return $this->printError($e->getMessage());
}
}
|
php
|
{
"resource": ""
}
|
q239560
|
LoopsAdmin.adjustOptions
|
train
|
private static function adjustOptions(array $options) {
$result = [];
foreach($options as $key => $value) {
$result[str_replace("-", "_", $key)] = $value;
}
return $result;
}
|
php
|
{
"resource": ""
}
|
q239561
|
LoopsAdmin.ident
|
train
|
private function ident($text, $length = 4, $chunk = 76, $break = "\n") {
$lines = [];
foreach(explode($break, $text) as $line) {
$text = trim(wordwrap($line, $chunk - $length, $break));
foreach(explode($break, $text) as $part) {
$lines[] = str_repeat(" ", $length).$part;
}
}
return implode($break, $lines);
}
|
php
|
{
"resource": ""
}
|
q239562
|
TranslateMethods.translatePlural
|
train
|
public function translatePlural($singular, $plural, $number)
{
$this->checkTranslator();
return $this->translator->translatePlural($singular, $plural, $number);
}
|
php
|
{
"resource": ""
}
|
q239563
|
AdminMeasureUnitController.showAction
|
train
|
public function showAction(MeasureUnit $measureunit)
{
$editForm = $this->createForm(MeasureUnitType::class, $measureunit, array(
'action' => $this->generateUrl('admin_shop_measure_unit_update', array('id' => $measureunit->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($measureunit->getId(), 'admin_shop_measure_unit_delete');
return array(
'measureunit' => $measureunit,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q239564
|
AdminMeasureUnitController.newAction
|
train
|
public function newAction()
{
$measureunit = new MeasureUnit();
$form = $this->createForm(MeasureUnitType::class, $measureunit);
return array(
'measureunit' => $measureunit,
'form' => $form->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q239565
|
AdminMeasureUnitController.createAction
|
train
|
public function createAction(Request $request)
{
$measureunit = new MeasureUnit();
$form = $this->createForm(new MeasureUnitType(), $measureunit);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($measureunit);
$em->flush();
return $this->redirect($this->generateUrl('admin_shop_measure_unit_show', array('id' => $measureunit->getId())));
}
return array(
'measureunit' => $measureunit,
'form' => $form->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q239566
|
AdminMeasureUnitController.updateAction
|
train
|
public function updateAction(MeasureUnit $measureunit, Request $request)
{
$editForm = $this->createForm(new MeasureUnitType(), $measureunit, array(
'action' => $this->generateUrl('admin_shop_measure_unit_update', array('id' => $measureunit->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('admin_shop_measure_unit_show', array('id' => $measureunit->getId())));
}
$deleteForm = $this->createDeleteForm($measureunit->getId(), 'admin_shop_measure_unit_delete');
return array(
'measureunit' => $measureunit,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q239567
|
AdminMeasureUnitController.sortAction
|
train
|
public function sortAction($field, $type)
{
$this->setOrder('measureunit', $field, $type);
return $this->redirect($this->generateUrl('admin_shop_measure_unit'));
}
|
php
|
{
"resource": ""
}
|
q239568
|
AdminMeasureUnitController.deleteAction
|
train
|
public function deleteAction(MeasureUnit $measureunit, Request $request)
{
$form = $this->createDeleteForm($measureunit->getId(), 'admin_shop_measure_unit_delete');
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($measureunit);
$em->flush();
}
return $this->redirect($this->generateUrl('admin_shop_measure_unit'));
}
|
php
|
{
"resource": ""
}
|
q239569
|
Html.getScript
|
train
|
protected function getScript()
{
if (null === $this->getScriptName()) {
$request = $this->frontController->getRequest();
$this->setScriptName($request->getControllerName() . DIRECTORY_SEPARATOR . $request->getActionName());
}
return $this->getScriptName() . '.' . $this->getViewSuffix();
}
|
php
|
{
"resource": ""
}
|
q239570
|
Html.setData
|
train
|
public function setData(array $data)
{
foreach ($data as $name => $value) {
if (is_string($name)) {
$this->__set($name, $value);
}
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239571
|
Configuration.getSenderClass
|
train
|
public function getSenderClass($options)
{
if (empty($options['sender'])) {
if (function_exists('extension_loaded') && extension_loaded('curl') && PHP_VERSION_ID >= 50300) {
return /**/
'Consumerr\Sender\CurlSender' /**/ /*5.2*'Consumerr_CurlSender'*/
;
} else {
return /**/
'Consumerr\Sender\PhpSender' /**/ /*5.2*'Consumerr_PhpSender'*/
;
}
} else {
if (isset($this->senderAlias[$options['sender']])) {
return $this->senderAlias[$options['sender']];
} else {
if (!class_exists($options['sender'])) {
throw new AssertionException("Sender class {$options['sender']} was not found.");
}
return $options['sender'];
}
}
}
|
php
|
{
"resource": ""
}
|
q239572
|
Router.add
|
train
|
public function add(string $path, $callable): Route{
$route = new Route($path, $callable);
$this->routes[] = $route;
return $route;
}
|
php
|
{
"resource": ""
}
|
q239573
|
PathNormalizer.configureSlashPrefix
|
train
|
private function configureSlashPrefix(array $pieces): self
{
$first = array_shift($pieces);
$pattern = sprintf('#^%s#', DIRECTORY_SEPARATOR);
if (preg_match($pattern, $first)) {
$this->prefix .= DIRECTORY_SEPARATOR;
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239574
|
PathNormalizer.getPartsFromSegment
|
train
|
private function getPartsFromSegment(string $segment): array
{
$parts = explode(DIRECTORY_SEPARATOR, $segment);
return array_filter($parts, function ($part) {
return $this->isNotEmpty($part);
});
}
|
php
|
{
"resource": ""
}
|
q239575
|
PathNormalizer.toString
|
train
|
protected function toString(): string
{
$normalized = sprintf('%s%s', $this->prefix, implode(DIRECTORY_SEPARATOR, $this->stack));
return trim($normalized);
}
|
php
|
{
"resource": ""
}
|
q239576
|
ServiceFunctions.isValidEmail
|
train
|
public function isValidEmail(string $email): bool
{
return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL) !== false;
}
|
php
|
{
"resource": ""
}
|
q239577
|
Command.repl
|
train
|
public function repl()
{
$input = $this->prompt();
$buffer = null;
while ($input != 'exit;') {
try {
$buffer .= $input;
if ((new ShallowParser)->statements($buffer)) {
ob_start();
$app = $this->container;
eval($buffer);
$response = ob_get_clean();
if ( ! empty($response)) $this->output->writeln(trim($response));
$buffer = null;
}
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$input = $this->prompt($buffer !== null);
}
if ($input == 'exit;') exit;
}
|
php
|
{
"resource": ""
}
|
q239578
|
Command.prompt
|
train
|
protected function prompt($indent = false)
{
$dialog = $this->getHelperSet()->get('dialog');
$indent = $indent ? '*' : null;
return $dialog->ask($this->output, "<info>encore{$indent}></info>", null);
}
|
php
|
{
"resource": ""
}
|
q239579
|
Filesystem.getActualFileDir
|
train
|
public function getActualFileDir($filename, $subDir = self::UPLOADER_SUB_DIR)
{
return $this->getPath(array($this->getMediaRootDir(), $subDir, $this->getFileDirPrefix($filename)));
}
|
php
|
{
"resource": ""
}
|
q239580
|
Filesystem.getFileDirPrefix
|
train
|
public function getFileDirPrefix($filename)
{
if (empty($filename)) {
throw new InvalidArgumentException('Invalid filename argument');
}
$path = array();
$parts = explode('.', $filename);
for ($i = 0; $i < min(strlen($parts[0]), $this->prefixSize); $i++) {
$path[] = $filename[$i];
}
$path = $this->getPath($path);
return $path;
}
|
php
|
{
"resource": ""
}
|
q239581
|
Filesystem.getAbsoluteFilePath
|
train
|
public function getAbsoluteFilePath($filename, $subDir = self::UPLOADER_SUB_DIR)
{
return $this->getRootDir() . $this->getRelativeFilePath($filename, $subDir);
}
|
php
|
{
"resource": ""
}
|
q239582
|
Filesystem.getRelativeFilePath
|
train
|
public function getRelativeFilePath($filename, $subDir = self::UPLOADER_SUB_DIR)
{
$pathParts = array(Media::NAME, $subDir, $this->getFileDirPrefix($filename), $filename);
return DIRECTORY_SEPARATOR . $this->getPath($pathParts);
}
|
php
|
{
"resource": ""
}
|
q239583
|
User.verifyPassword
|
train
|
public function verifyPassword($email, $password)
{
$this->find("email", $email);
return password_verify($password, $this->password);
}
|
php
|
{
"resource": ""
}
|
q239584
|
User.isEmailUnique
|
train
|
public function isEmailUnique($email)
{
$this->find("email", $email);
if (isset($this->id)) {
return false;
}
return true;
}
|
php
|
{
"resource": ""
}
|
q239585
|
Values.finalize
|
train
|
public function finalize() : Values
{
/* @var input\Parameter $parameter */
foreach ($this->definitions as $name => $parameter) {
if (isset($this->items[$name])) {
continue;
}
// In the case of Parameters which do not accept values (ie. optional flags), we explicitly default them
// to a boolean false, opposed to a boolean true when they are actually set in input.
$this->items[$name] = ($value = $parameter->getValue()) ? $value->getDefault() : false;
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239586
|
Values.assertIsDefined
|
train
|
protected function assertIsDefined(string $name) : input\Parameter
{
/* @var input\Parameter $parameter */
if (!$parameter = $this->definitions->get($name)) {
throw new \OutOfBoundsException("The parameter [$name] is not defined.");
}
return $parameter;
}
|
php
|
{
"resource": ""
}
|
q239587
|
NormalizeKeyCapableTrait._normalizeKey
|
train
|
protected function _normalizeKey($key)
{
try {
return $this->_normalizeString($key);
} catch (InvalidArgumentException $e) {
throw $this->_createOutOfRangeException($this->__('Invalid key'), null, $e, $key);
}
}
|
php
|
{
"resource": ""
}
|
q239588
|
Doctrine._getLifetime
|
train
|
public function _getLifetime(\Doctrine_Record $record)
{
$return = $this->_lifetime;
if (!$this->_overrideLifetime) {
$return = (int) $record->{$this->_lifetimeColumn};
}
return $return;
}
|
php
|
{
"resource": ""
}
|
q239589
|
Operator.get
|
train
|
public static function get()
{
return [
self::$equals,
self::$lessThan,
self::$lessThanEqualTo,
self::$greaterThan,
self::$greaterThanEqualTo,
self::$doesNotEqual,
self::$doesNotEqualAlt,
self::$is,
self::$isA,
self::$isNot,
self::$like,
];
}
|
php
|
{
"resource": ""
}
|
q239590
|
Assume.that
|
train
|
public static function that($condition, $message = null)
{
if ($condition === true) {
return;
}
if (isset($message)) {
throw new InvalidArgumentException($message);
}
$bt = debug_backtrace();
$call = $bt[0];
$lines = file($call['file']);
preg_match('/' . $call['function'] . '\((.+)\)/', $lines[$call['line'] - 1], $matches);
throw new InvalidArgumentException('Assumption failed: ' . $matches[1]);
}
|
php
|
{
"resource": ""
}
|
q239591
|
Net_Notifier_Listener.run
|
train
|
public function run()
{
$this->connect();
// tell server we want to listen
$this->connection->writeText('{ "action" : "listen" }');
while (!$this->moribund) {
$read = array($this->connection->getSocket()->getRawSocket());
// Suppressing warnings for stream_select() because it will raise
// a warning if interrupted by a signal.
$result = @stream_select(
$read,
$write = null,
$except = null,
null
);
if ($result === false || $result < 1) {
continue;
}
$moribund = false;
// check if server closed connection
$bytes = $this->connection->getSocket()->peek(1);
if (mb_strlen($bytes, '8bit') === 0) {
$this->log(
'server closed connection.' . PHP_EOL,
Net_Notifier_Logger::VERBOSITY_CLIENT
);
$moribund = true;
}
try {
if ($this->connection->read(Net_Notifier_Client::READ_BUFFER_LENGTH)) {
if ($this->connection->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSING) {
$messages = $this->connection->getTextMessages();
foreach ($messages as $message) {
if (mb_strlen($message, '8bit') > 0) {
$this->log(
sprintf(
'received message: "%s"' . PHP_EOL,
$message
),
Net_Notifier_Logger::VERBOSITY_MESSAGES
);
$this->handleMessage($message);
}
}
}
} else {
$this->log(
'got a message chunk from server' . PHP_EOL,
Net_Notifier_Logger::VERBOSITY_CLIENT
);
}
} catch (Net_Notifier_WebSocket_HandshakeFailureException $e) {
$this->log(
sprintf(
'failed server handshake: %s' . PHP_EOL,
$e->getMessage()
),
Net_Notifier_Logger::VERBOSITY_CLIENT
);
}
if ($moribund) {
$this->connection->close();
break;
}
}
if ($this->connection->getState() < Net_Notifier_WebSocket_Connection::STATE_CLOSING) {
$this->disconnect();
}
}
|
php
|
{
"resource": ""
}
|
q239592
|
Locale.parse
|
train
|
public static function parse($value)
{
if (is_array($value)) {
return static::fromArray((array)$value);
} elseif (is_string($value)) {
return static::fromString((string)$value);
} else {
return null;
}
}
|
php
|
{
"resource": ""
}
|
q239593
|
Locale.fromArray
|
train
|
public static function fromArray(array $value)
{
$language = null;
$culture = null;
if (!empty($value['language'])) {
$language = $value['language'];
} elseif ($value[0]) {
$language = $value[0];
}
if (!empty($value['culture'])) {
$culture = $value['culture'];
} elseif ($value[1]) {
$culture = $value[1];
}
return new static($language, $culture);
}
|
php
|
{
"resource": ""
}
|
q239594
|
Locale.fromString
|
train
|
public static function fromString(string $value)
{
$locale = preg_split('/-|_/', $value, 2);
$language = null;
$culture = null;
if (isset($locale[0])) {
$language = $locale[0];
}
if (isset($locale[1])) {
$culture = $locale[1];
}
return new static($language, $culture);
}
|
php
|
{
"resource": ""
}
|
q239595
|
Locale.toString
|
train
|
public function toString()
{
if ($this->_language && $this->_culture) {
return (string)$this->_language . '_' . (string)$this->_culture;
} else {
return (string)$this->_language;
}
}
|
php
|
{
"resource": ""
}
|
q239596
|
Imageable.image
|
train
|
public function image()
{
if ($this->relationLoaded('mediables')) {
return $this->mediables->where('type', 'image')->first();
}
return $this->mediables()
->where('media.type', 'image')
->whereNull('mediables.type')
->first();
}
|
php
|
{
"resource": ""
}
|
q239597
|
Imageable.setImageAttribute
|
train
|
public function setImageAttribute($value)
{
$value = $this->resolveMediableValue($value);
// Dont store or make lazy store
// if current model doesn't exists in database.
if (!$this->exists && $value) {
return $this->attributes['image'] = $value;
} elseif (!$this->exists) {
return;
}
$this->mediables()->sync($value);
$this->touch();
}
|
php
|
{
"resource": ""
}
|
q239598
|
Imageable.getImageAttribute
|
train
|
public function getImageAttribute()
{
// It should have image
if ($this->exists) {
return $this->image();
}
return isset($this->attributes['image']) ? $this->attributes['image'] : null;
}
|
php
|
{
"resource": ""
}
|
q239599
|
Imageable.getImageUrlAttribute
|
train
|
public function getImageUrlAttribute()
{
if ($this->exists) {
$image = $this->image();
if ($image) {
return $image->url;
}
return config('media.image.default');
}
return config('media.image.default');
}
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.