_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q267000
Kernel.shutdown
test
public function shutdown(&$arg = null, $callback = null) { if ($this->getDebug() && false===$this->is_shutdown) { return \DevDebug\Debugger::shutdown(true, $callback); } }
php
{ "resource": "" }
q267001
Kernel.handles
test
public function handles(Request $request) { if (!$this->is_booted) { $this->boot(); } $this->getContainer()->set('request', $request); $this->getContainer()->get('router')->setUrl($request->buildUrl()); $mode_data = $this->getMode(true); if (isset($mode_data['log_requests']) && $mode_data['log_requests']) { \CarteBlanche\CarteBlanche::log( get_class($request).' :: '.$this->getContainer()->get('request')->getUrl(), \Library\Logger::INFO ); } return $this; }
php
{ "resource": "" }
q267002
Kernel.distribute
test
public function distribute() { if (!$this->is_booted) { $this->boot(); } $req = $this->getContainer()->get('request'); if (empty($req)) { $this->handles(new Request); } return $this->getContainer()->get('front_controller') ->distribute(); }
php
{ "resource": "" }
q267003
Kernel.initBundle
test
public function initBundle($space, $dir) { $bundle = new \CarteBlanche\App\Bundle($space, $dir); return $this->getContainer()->setBundle($space, $bundle); }
php
{ "resource": "" }
q267004
Kernel.addBootError
test
public function addBootError($string) { $this->boot_errors[] = $string; if ($this->getMode()==='dev') { die( sprintf("[boot error] : %s", $string) ); } return $this; }
php
{ "resource": "" }
q267005
Kernel.initConstantPath
test
public function initConstantPath($cst, $path_ref, $must_exists = false, $must_be_writable = false) { if (defined($cst)) { $this->addPath($path_ref, constant($cst), $must_exists, $must_be_writable); } else { throw new ErrorException( sprintf('Missing constant path "%s"!', $cst) ); } return $this; }
php
{ "resource": "" }
q267006
Kernel.addPath
test
public function addPath($name, $value, $must_exists = false, $must_be_writable = false) { $config = $this->getContainer()->get('config'); if ($must_exists) { $realpath = $this->getAbsolutePath($value); if (!empty($realpath)) { $value = $realpath; } else { DirectoryHelper::ensureExists($value); if (!file_exists($value)) { $this->addBootError( sprintf('Directory "%s" defined as an application path doesn\'t exist and can\'t be created!', $value) ); /* throw new RuntimeException( sprintf('Directory "%s" defined as an application path doesn\'t exist and can\'t be created!', $value) ); */ } } } if ($must_be_writable && !is_writable($value)) { $this->addBootError( sprintf('Directory "%s" must be writable! (%s)', $value, $name) ); /* throw new RuntimeException( sprintf('Directory "%s" must be writable!', $value) ); */ } $config->getRegistry() ->loadStack('paths') ->setEntry($name, $value) ->saveStack('paths', true); return $this; }
php
{ "resource": "" }
q267007
Kernel.getPath
test
public function getPath($name, $full_path = false) { $config = $this->getContainer()->get('config'); $path = $config->getRegistry()->getStackEntry($name, null, 'paths'); if (file_exists($path) && is_dir($path)) { $path = DirectoryHelper::slashDirname($path); } if (true===$full_path) { return $this->getAbsolutePath($path); } return $path; }
php
{ "resource": "" }
q267008
Kernel.getAbsolutePath
test
public function getAbsolutePath($path) { $root = $this->getPath('root_path'); if (empty($root)) { return null; } if (empty($path)) { return $root; } if (0===substr_count($path, $root)) { $path = DirectoryHelper::slashDirname($root).$path; } return file_exists($path) ? DirectoryHelper::slashDirname(realpath($path)) : null; }
php
{ "resource": "" }
q267009
Kernel.whoAmI
test
public function whoAmI() { $cmd = new \Library\Command; $whoami = $cmd->run('whoami'); return !empty($whoami[0]) ? $whoami[0] : null; }
php
{ "resource": "" }
q267010
Kernel.__setMode
test
private function __setMode($mode = 'dev') { $config = $this->getContainer()->get('config'); $mode_data = $config->get('carte_blanche.modes', array(), 'app'); if (array_key_exists($mode, $mode_data)) { $this->mode = strtolower($mode); } else { $this->mode = isset($mode_data['default']) ? strtolower($mode_data['default']) : 'dev'; } if (isset($mode_data[$this->mode])) { $this->mode_data = $mode_data[$this->mode]; if (isset($this->mode_data['display_errors'])) { @ini_set('display_errors',$this->mode_data['display_errors']); } if (isset($this->mode_data['error_reporting'])) { @error_reporting($this->mode_data['error_reporting']); } if (isset($this->mode_data['debug']) && $this->mode_data['debug']) { $this->setDebug(true); } else { $this->setDebug(false); } } return $this; }
php
{ "resource": "" }
q267011
Kernel.__loadDefaultConfig
test
private function __loadDefaultConfig() { $app_cfgfile = __DIR__.'/../../../config/'.self::CARTE_BLANCHE_CONFIG_FILE; if (!file_exists($app_cfgfile)) { throw new ErrorException( sprintf('Default application configuration file not found in "%s" [%s]!', $this->getPath('config_dir'), $app_cfgfile) ); } $this->getContainer()->get('config')->load($app_cfgfile); }
php
{ "resource": "" }
q267012
AssetManager.init
test
public function init() { parent::init(); $this->basePath = Reaction::$app->getAlias($this->basePath); if (!is_dir($this->basePath)) { throw new InvalidConfigException("The directory does not exist: {$this->basePath}"); } elseif (!is_writable($this->basePath)) { throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}"); } $this->basePath = realpath($this->basePath); $this->baseUrl = rtrim(Reaction::$app->getAlias($this->baseUrl), '/'); }
php
{ "resource": "" }
q267013
AssetManager.loadBundle
test
protected function loadBundle($name, $config = [], $publish = true) { if (!isset($config['class'])) { $config['class'] = $name; } /* @var $bundle AssetBundle */ $bundle = Reaction::create($config); if ($publish) { $bundle->publish($this); } return $bundle; }
php
{ "resource": "" }
q267014
AssetManager.getConverter
test
public function getConverter() { if ($this->_converter === null) { $this->_converter = Reaction::create(AssetConverter::class); } elseif (is_array($this->_converter) || is_string($this->_converter)) { if (is_array($this->_converter) && !isset($this->_converter['class'])) { $this->_converter['class'] = AssetConverter::class; } $this->_converter = Reaction::create($this->_converter); } return $this->_converter; }
php
{ "resource": "" }
q267015
AssetManager.hash
test
protected function hash($path) { if (is_callable($this->hashCallback)) { return call_user_func($this->hashCallback, $path); } $path = (is_file($path) ? dirname($path) : $path) . filemtime($path); return sprintf('%x', crc32($path . Reaction::getVersion() . '|' . $this->linkAssets)); }
php
{ "resource": "" }
q267016
AbstractMail.addReplytos
test
public function addReplytos(array $reply_tos) { foreach ($reply_tos as $key => $val) { if (is_numeric($key)) { $this->addReplyto($val); } else { $this->addReplyto($key, $val); } } }
php
{ "resource": "" }
q267017
liteAuth.newUser
test
public function newUser($user, $pass, $email = '', $fname = '', $sname = '' , $admin = False){ $hash = password_hash($pass, PASSWORD_BCRYPT); return $this->db->insert($this->prefix.'users', ['user' => $user, 'pass' => $hash, 'admin' => $admin, 'email' => $email, 'first_name' => $fname, 'surname' => $sname]) ? $this->db->id() : False; }
php
{ "resource": "" }
q267018
liteAuth.resumeSession
test
public function resumeSession($authtoken) { if( $id = $this->db->get($this->prefix.'authtokens', 'user_id', ['token'=>$authtoken]) ) $this->user = new User($this, $id); else return False; }
php
{ "resource": "" }
q267019
PokeCalculator.calculate
test
public function calculate($expression) { $translatedExpression = $this->translate($expression); $result = eval('return '.$translatedExpression.';'); $decimalResult = new Number($result); // this is bad and needs some work return $decimalResult->convert($this->numberSystem); }
php
{ "resource": "" }
q267020
Ifsta.urlUserDetails
test
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) { return $this->domain . '/api/userinfo?access_token=' . $token; }
php
{ "resource": "" }
q267021
Mapper.raw
test
public function raw($sql, array $values = [], $class = null) { return $this->execute($sql, $values, function(\PDOStatement $statement) use($class) { if($statement->columnCount() > 0) { return $class ? $statement->fetchAll(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, $class) : $statement->fetchAll(\PDO::FETCH_OBJ); } return $statement->rowCount(); }); }
php
{ "resource": "" }
q267022
Html.csrfMetaTags
test
public static function csrfMetaTags(RequestApplicationInterface $app) { $encoding = $app->charset; if ($app->reqHelper->enableCsrfValidation) { return static::tag('meta', '', ['name' => 'csrf-param', 'content' => $app->reqHelper->csrfParam], $encoding) . "\n " . static::tag('meta', '', ['name' => 'csrf-token', 'content' => $app->reqHelper->getCsrfToken()], $encoding) . "\n"; } return ''; }
php
{ "resource": "" }
q267023
Html.label
test
public static function label($content, $for = null, $options = [], $encoding = null) { $options['for'] = $for; return static::tag('label', $content, $options, $encoding); }
php
{ "resource": "" }
q267024
Html.button
test
public static function button($content = 'Button', $options = [], $encoding = null) { if (!isset($options['type'])) { $options['type'] = 'button'; } return static::tag('button', $content, $options, $encoding); }
php
{ "resource": "" }
q267025
Html.submitButton
test
public static function submitButton($content = 'Submit', $options = [], $encoding = null) { $options['type'] = 'submit'; return static::button($content, $options, $encoding); }
php
{ "resource": "" }
q267026
Html.submitInput
test
public static function submitInput($label = 'Submit', $options = [], $encoding = null) { $options['type'] = 'submit'; $options['value'] = $label; return static::tag('input', '', $options, $encoding); }
php
{ "resource": "" }
q267027
Html.resetInput
test
public static function resetInput($label = 'Reset', $options = [], $encoding = null) { $options['type'] = 'reset'; $options['value'] = $label; return static::tag('input', '', $options, $encoding); }
php
{ "resource": "" }
q267028
Html.hiddenInput
test
public static function hiddenInput($name, $value = null, $options = [], $encoding = null) { return static::input('hidden', $name, $value, $options, $encoding); }
php
{ "resource": "" }
q267029
Html.passwordInput
test
public static function passwordInput($name, $value = null, $options = [], $encoding = null) { return static::input('password', $name, $value, $options, $encoding); }
php
{ "resource": "" }
q267030
Html.processBooleanInputOptions
test
protected static function processBooleanInputOptions($name, &$options) { if(isset($options['label'])) { $options['labelOptions'] = isset($options['labelOptions']) ? $options['labelOptions'] : []; Html::addCssClass($options['labelOptions'], ['widget' => 'form-check-label']); } Html::addCssClass($options, ['widget' => 'form-check-input']); if(!isset($options['id'])) { $idMain = strtolower(str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name)); $options['id'] = $idMain . '-opt-' . $options['value']; } }
php
{ "resource": "" }
q267031
Time.setHours
test
public function setHours(int $hours): void { $this->timeElementsAreValid($hours, $this->minutes, $this->seconds); $this->hours = $hours; }
php
{ "resource": "" }
q267032
Time.setMinutes
test
public function setMinutes(int $minutes): void { $this->timeElementsAreValid($this->hours, $minutes, $this->seconds); $this->minutes = $minutes; }
php
{ "resource": "" }
q267033
Time.setSeconds
test
public function setSeconds(int $seconds): void { $this->timeElementsAreValid($this->hours, $this->minutes, $seconds); $this->seconds = $seconds; }
php
{ "resource": "" }
q267034
Time.timeElementsAreValid
test
private function timeElementsAreValid($hours, $minutes, $seconds): bool { $exception = new \InvalidArgumentException( \sprintf('Invalid time "%02d:%02d:%02d".', $hours, $minutes, $seconds) ); if ((int)\sprintf('%d%02d%02d', $hours, $minutes, $seconds) > 240000) { throw $exception; } if ($hours < 0 || $minutes < 0 || $seconds < 0) { throw $exception; } if ($hours <= 24 && $minutes <= 59 && $seconds <= 59) { return true; } throw $exception; }
php
{ "resource": "" }
q267035
FlyFilesystem.write
test
public function write(string $path, string $contents): bool { return $this->flySystem->write($path, $contents); }
php
{ "resource": "" }
q267036
FlyFilesystem.writeStream
test
public function writeStream(string $path, $resource): bool { return $this->flySystem->writeStream($path, $resource); }
php
{ "resource": "" }
q267037
FlyFilesystem.update
test
public function update(string $path, string $contents): bool { return $this->flySystem->update($path, $contents); }
php
{ "resource": "" }
q267038
FlyFilesystem.updateStream
test
public function updateStream(string $path, $resource): bool { return $this->flySystem->updateStream($path, $resource); }
php
{ "resource": "" }
q267039
FlyFilesystem.put
test
public function put(string $path, string $contents): bool { return $this->flySystem->put($path, $contents); }
php
{ "resource": "" }
q267040
FlyFilesystem.putStream
test
public function putStream(string $path, $resource): bool { return $this->flySystem->putStream($path, $resource); }
php
{ "resource": "" }
q267041
FlyFilesystem.rename
test
public function rename(string $path, string $newPath): bool { return $this->flySystem->rename($path, $newPath); }
php
{ "resource": "" }
q267042
FlyFilesystem.copy
test
public function copy(string $path, string $newPath): bool { return $this->flySystem->copy($path, $newPath); }
php
{ "resource": "" }
q267043
FlyFilesystem.metadata
test
public function metadata(string $path): ? array { $metadata = $this->flySystem->getMetadata($path); return false !== $metadata ? $metadata : null; }
php
{ "resource": "" }
q267044
FlyFilesystem.mimetype
test
public function mimetype(string $path): ? string { $mimetype = $this->flySystem->getMimetype($path); return false !== $mimetype ? $mimetype : null; }
php
{ "resource": "" }
q267045
FlyFilesystem.size
test
public function size(string $path): ? int { $size = $this->flySystem->getSize($path); return false !== $size ? $size : null; }
php
{ "resource": "" }
q267046
FlyFilesystem.timestamp
test
public function timestamp(string $path): ? int { $timestamp = $this->flySystem->getTimestamp($path); return false !== $timestamp ? $timestamp : null; }
php
{ "resource": "" }
q267047
FlyFilesystem.visibility
test
public function visibility(string $path): ? string { $visibility = $this->flySystem->getVisibility($path); return false !== $visibility ? $visibility : null; }
php
{ "resource": "" }
q267048
FlyFilesystem.setVisibility
test
public function setVisibility(string $path, Visibility $visibility): bool { return $this->flySystem->setVisibility($path, $visibility->getValue()); }
php
{ "resource": "" }
q267049
FlyFilesystem.setVisibilityPublic
test
public function setVisibilityPublic(string $path): bool { return $this->flySystem->setVisibility($path, Visibility::PUBLIC); }
php
{ "resource": "" }
q267050
FlyFilesystem.setVisibilityPrivate
test
public function setVisibilityPrivate(string $path): bool { return $this->flySystem->setVisibility($path, Visibility::PRIVATE); }
php
{ "resource": "" }
q267051
FlyFilesystem.listContents
test
public function listContents(string $directory = null, bool $recursive = false): array { return $this->flySystem->listContents($directory ?? '', $recursive); }
php
{ "resource": "" }
q267052
FlyFilesystem.localAdapter
test
protected function localAdapter(): Local { return self::$adapters['local'] ?? self::$adapters['local'] = new Local( $this->app->config()['filesystem']['adapters']['s3']['dir'] ); }
php
{ "resource": "" }
q267053
FlyFilesystem.s3Adapter
test
protected function s3Adapter(): AwsS3Adapter { if (isset(self::$adapters['s3'])) { return self::$adapters['s3']; } $config = $this->app->config()['filesystem']['adapters']['s3']; $clientConfig = [ 'credentials' => [ 'key' => $config['key'], 'secret' => $config['secret'], ], 'region' => $config['region'], 'version' => $config['version'], ]; self::$adapters['s3'] = new AwsS3Adapter( new S3Client($clientConfig), $config['bucket'], $config['dir'] ); return self::$adapters['s3']; }
php
{ "resource": "" }
q267054
UrlManager.processRequest
test
protected function processRequest() { if (!Reaction::$app->getI18n()->detectLanguageByUrl) { return; } $langPrefixes = Reaction::$app->getI18n()->languagePrefixes; $rawUrl = trim($this->app->reqHelper->getPathInfo(), '/'); $requestPrefix = ''; $rawUrlParts = explode('/', $rawUrl); if (!empty($rawUrlParts) && isset($langPrefixes[$rawUrlParts[0]])) { $requestPrefix = $rawUrlParts[0]; $this->baseUrl = $requestPrefix; array_shift($rawUrlParts); } $rawUrl = '/' . trim(implode('/', $rawUrlParts), '/'); $requestLanguage = $langPrefixes[$requestPrefix]; $this->app->reqHelper->setPathInfo($rawUrl); $this->app->language = $requestLanguage; }
php
{ "resource": "" }
q267055
JmsSerializerContentNegotiation.deserializeRequest
test
public function deserializeRequest($className) { $request = $this->app["request_stack"]->getCurrentRequest(); return $this->app["serializer"]->deserialize( $request->getContent(), $className, $request->getContentType(), $this->app["conneg.deserializationContext"] ); }
php
{ "resource": "" }
q267056
Model.checkAccess
test
private static function checkAccess($object,$errorMessage){ if(is_string($object)){ $className = $object; $object = null; }else{ $className = get_class($object); } if(TransactionManager::isSuperUser()){ return true; } $hasAccess = false; $hasAccessChecks = false; try{ TransactionManager::startTransaction(null,true); $debugBacktraces = debug_backtrace(false); $args = null; $function = null; foreach($debugBacktraces as $debugBacktrace){ if($debugBacktrace["class"] == $className){ $args = $debugBacktrace["args"]; $function = $debugBacktrace["function"]; break; } } $accessAnnotations = self::getAccessAnnotation($className, $function); if(is_array($accessAnnotations) && count($accessAnnotations) > 0){ $hasAccessChecks = true; // // access annotations will be of the form // array( // "key1|value1", // "key2|value2", // ... // "function|functionName" // ) // // Access is granted if session contains value for the specified key // "function" is the special reserved key for which a function mentioned as value is called instead of checking for the value in session // group access annotations by key $accessMasks = array(); foreach ($accessAnnotations as $accessMask){ $accessMaskArr = preg_split('/\|/', $accessMask); $accessMaskKey = $accessMaskArr[0]; $accessMaskValue = $accessMaskArr[1]; if(!array_key_exists($accessMaskKey, $accessMasks)){ $accessMaskValues = array(); }else{ $accessMaskValues = $accessMasks[$accessMaskKey]; } $accessMaskValues[] = $accessMaskValue; $accessMasks[$accessMaskKey] = $accessMaskValues; } $session = Factory::getSession(); foreach ($accessMasks as $accessKey=>$accessValues){ if($accessKey == "function"){ continue; } $sessionValues = $session->get($accessKey); if(count(array_intersect($sessionValues, $accessValues)) > 0){ $hasAccess = true; break; } } if(!$hasAccess && array_key_exists("function", $accessMasks)){ foreach ($accessMasks["function"] as $function){ $result = Reflection::invokeArgs($className, $function, $object, $args); if($result instanceof Expression){ $hasAccess = $result; break; }else if(isset($result) && $result){ $hasAccess = true; break; } } } } TransactionManager::commitTransaction(); }catch (\Exception $e){ TransactionManager::abortTransaction(); throw $e; } if($hasAccessChecks){ if($hasAccess === false){ throw new NoAccessException($errorMessage); } return $hasAccess; } return true; }
php
{ "resource": "" }
q267057
DocBlock.parseBlock
test
protected function parseBlock($block) { $lines = array_filter(array_map(function($line) { $line = trim($line); if (strpos($line, "/**") !== false or strpos($line, "*/") !== false) { return null; } return trim(substr($line, 1)); }, explode(PHP_EOL, $block))); return array_values($lines); }
php
{ "resource": "" }
q267058
Directory.path
test
public static function path(string $path = null): ? string { return $path && $path[0] !== static::DIRECTORY_SEPARATOR ? static::DIRECTORY_SEPARATOR . $path : $path; }
php
{ "resource": "" }
q267059
AbstractApi.getAuthenticationObject
test
protected function getAuthenticationObject() { if ($this->authObject == null) { if (strlen($this->login) <= 0 || strlen($this->password) <= 0) { throw new NullPointerException("Login or Password is not set."); } $auth = new Authentication(); if (! $auth->authenticate()) { throw new AuthException("Authentication Problem. Please check Login and Password."); } $this->authObject = $auth; } return $this->authObject; }
php
{ "resource": "" }
q267060
AbstractApi.getDataFromUrl
test
protected function getDataFromUrl($url) { $auth = $this->getAuthenticationObject(); $process = curl_init($url); curl_setopt($process, CURLOPT_HEADER, 0); // setting the authentication header curl_setopt($process, CURLOPT_HTTPHEADER, array( "Authorization: " . $auth->getTokenType() . " " . $auth->getAccessToken() )); curl_setopt($process, CURLOPT_TIMEOUT, 30); curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); $returnData = curl_exec($process); curl_close($process); return $returnData; }
php
{ "resource": "" }
q267061
AbstractApi.parseJsonData
test
protected function parseJsonData($data) { if ($data != FALSE) { // check, if raw answer is requestedd if ($this->getRawAnswer()) { return $data; } $json_data = json_decode($data, TRUE); if (isset($json_data["errors"])) { $err_msg = array(); foreach ($json_data["errors"] as $error) { $err_msg[] = $error["Message"]; } throw new JsonException(implode(";", $err_msg)); } else { return $json_data; } } else { throw new ServerException("Get No Data from Server."); } }
php
{ "resource": "" }
q267062
AbstractApi.getAll
test
public function getAll() { // build url $url = $this->base_url . $this->url; // get data from server $data = $this->getDataFromUrl($url); // parse result set and get data as array $result = $this->parseJsonData($data); return $result; }
php
{ "resource": "" }
q267063
EntityRepositoryTrait.getEntityAlias
test
public function getEntityAlias() { if (!$this->entityAlias) { $className = $this->getClassName(); $reflectionCLass = new ReflectionClass($className); if (is_string($reflectionCLass->getConstant('ALIAS_NAME'))) { $entityAlias = $reflectionCLass->getConstant('ALIAS_NAME'); } else { $entityAlias = array_slice(explode('\\', $className), -1, 1)[0]; } $this->entityAlias = preg_replace('/[^a-z]/i', '', $entityAlias); } return $this->entityAlias; }
php
{ "resource": "" }
q267064
EntityRepositoryTrait.createQueryBuilder
test
public function createQueryBuilder($alias = null, $indexBy = null) { return $this->createNewQueryBuilderInstance()->selectFromRepositoryEntity($alias, $indexBy); }
php
{ "resource": "" }
q267065
EntityRepositoryTrait.createResultSetMappingBuilder
test
public function createResultSetMappingBuilder($alias = null) { if (!$alias) { $alias = $this->getEntityAlias(); } $resultSet = new ResultSetMappingBuilder( $this->getEntityManager(), ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT ); $resultSet->addRootEntityFromClassMetadata($this->getClassName(), $alias); return $resultSet; }
php
{ "resource": "" }
q267066
EntityRepositoryTrait.findAllIdentifiers
test
public function findAllIdentifiers() { $metadata = $this->getClassMetadata(); $identifiers = $metadata->getIdentifier(); $qb = $this->createQueryBuilder(); foreach ($identifiers as $field) { $qb->select($qb->alias($field)); } return $qb->fetchAllScalar(); }
php
{ "resource": "" }
q267067
EntityRepositoryTrait.min
test
public function min($column) { $qb = $this->createQueryBuilder(); $qb->select(sprintf('MIN(%s) AS min_%s', $qb->alias($column), $column)); return $qb->fetchSingleScalar(); }
php
{ "resource": "" }
q267068
EntityRepositoryTrait.paginate
test
public function paginate($page = 1, $perPage = null) { $perPage = $perPage ?: $this->getMaxResults(); $qb = $this->createQueryBuilder(); $qb->paginate($page, $perPage); return $this->getPaginator($qb); }
php
{ "resource": "" }
q267069
EntityRepositoryTrait.isEntity
test
public function isEntity($entity) { return is_object($entity) && !$this->getEntityManager()->getMetadataFactory()->isTransient(ClassUtils::getClass($entity)); }
php
{ "resource": "" }
q267070
EntityRepositoryTrait.getIdentifier
test
protected function getIdentifier($entity, $single = false) { $this->validateEntity($entity, __METHOD__); $entityClass = ClassUtils::getClass($entity); $entityManager = $this->getEntityManager(); $metadata = $entityManager->getClassMetadata($entityClass); $metadata->validateIdentifier(); $id = $metadata->getIdentifierValues($entity); /** @noinspection IsEmptyFunctionUsageInspection */ if (empty($id)) { return $single ? reset($id) : $id; } foreach ($id as $field => &$idValue) { if (is_object($idValue) && $entityManager->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($idValue)) ) { $singleId = $entityManager->getUnitOfWork()->getSingleIdentifierValue($idValue); if ($singleId === null) { throw ORMInvalidArgumentException::invalidIdentifierBindingEntity(); } $idValue = $singleId; } if (!in_array($field, $metadata->identifier, true)) { throw ORMException::missingIdentifierField($metadata->name, $field); } } unset($idValue); if (count($metadata->identifier) !== count($id)) { throw ORMException::unrecognizedIdentifierFields( $metadata->name, array_diff($metadata->identifier, $id) ); } return $single ? reset($id) : $id; }
php
{ "resource": "" }
q267071
EntityRepositoryTrait.validateEntity
test
protected function validateEntity($entity, $method) { if (!$this->isEntity($entity)) { throw new Exception\InvalidArgumentException( sprintf( '%s expects parameter 1 to be a valid entity instance, %s provided instead', $method, is_object($entity) ? get_class($entity) : gettype($entity) ) ); } }
php
{ "resource": "" }
q267072
EntityRepositoryTrait.toArray
test
public function toArray($entity) { $entityManager = $this->getEntityManager(); $unitOfWork = $entityManager->getUnitOfWork(); $classMetadata = $this->getClassMetadata(); $result = []; foreach ($unitOfWork->getOriginalEntityData($entity) as $field => $value) { if ($classMetadata->hasAssociation($field)) { $associationMapping = $classMetadata->getAssociationMapping($field); // Only owning side of x-1 associations can have a FK column. if (!$associationMapping['isOwningSide'] || !($associationMapping['type'] & ClassMetadata::TO_ONE)) { continue; } if ($value !== null) { $newValId = $unitOfWork->getEntityIdentifier($value); $targetClass = $entityManager->getClassMetadata($associationMapping['targetEntity']); /** @noinspection ForeachSourceInspection */ foreach ($associationMapping['joinColumns'] as $joinColumn) { $sourceColumn = $joinColumn['name']; $targetColumn = $joinColumn['referencedColumnName']; if ($value === null) { $result[$sourceColumn] = null; } elseif ($targetClass->containsForeignIdentifier) { $result[$sourceColumn] = $newValId[$targetClass->getFieldForColumn($targetColumn)]; } else { $result[$sourceColumn] = $newValId[$targetClass->fieldNames[$targetColumn]]; } } } } elseif ($classMetadata->hasField($field)) { $columnName = $classMetadata->getFieldName($field); $result[$columnName] = $value; } } return $result; }
php
{ "resource": "" }
q267073
FileValidator.filterFiles
test
private function filterFiles(array $files) { $result = []; //\React\Http\Io\UploadedFile::class; foreach ($files as $fileName => $file) { if ($file instanceof UploadedFile && $file->error !== UPLOAD_ERR_NO_FILE) { $result[$fileName] = $file; } } return $result; }
php
{ "resource": "" }
q267074
FileValidator.getSizeLimit
test
public function getSizeLimit() { // Get the lowest between post_max_size and upload_max_filesize, log a warning if the first is < than the latter $limit = $this->sizeToBytes(ini_get('upload_max_filesize')); $postLimit = $this->sizeToBytes(ini_get('post_max_size')); if ($postLimit > 0 && $postLimit < $limit) { Reaction::$app->logger->warning('PHP.ini\'s \'post_max_size\' is less than \'upload_max_filesize\'.', __METHOD__); $limit = $postLimit; } if ($this->maxSize !== null && $limit > 0 && $this->maxSize < $limit) { $limit = $this->maxSize; } if (isset($_POST['MAX_FILE_SIZE']) && $_POST['MAX_FILE_SIZE'] > 0 && $_POST['MAX_FILE_SIZE'] < $limit) { $limit = (int)$_POST['MAX_FILE_SIZE']; } return $limit; }
php
{ "resource": "" }
q267075
BagTrait.has
test
public function has($key) { return (isset($this->bag[$key]) || array_key_exists($key, $this->bag)); }
php
{ "resource": "" }
q267076
NativeKernel.handle
test
public function handle(Input $input, Output $output): int { $exitCode = 1; try { $exitCode = $this->console->dispatch($input, $output); } catch (Throwable $exception) { // Show the exception // TODO: Implement dd($exception); } $this->app->events()->trigger( ConsoleKernelHandled::class, [new ConsoleKernelHandled($input, $exitCode)] ); return $exitCode; }
php
{ "resource": "" }
q267077
NativeKernel.terminate
test
public function terminate(Input $input, int $exitCode): void { $this->app->events()->trigger( ConsoleKernelTerminate::class, [new ConsoleKernelTerminate($input, $exitCode)] ); }
php
{ "resource": "" }
q267078
CategoryComponent.accountCategories
test
public function accountCategories(Account $account) { $this->dataCollection->add('account', $account); $categoryMapper = new CategoryMapper(Database::get('money')); $categories = $categoryMapper->findAllByAccountId($account->getId()); $this->dataCollection->add('categories', $categories); return $this->render('Categories'); }
php
{ "resource": "" }
q267079
WebApp.run
test
public function run() { try { $this->init(); $this->executeController(); } catch (\Exception $e) { $this->logger->addCritical('Exception caught', array('exception' => $e)); $this->response->setHttpResponseCode(500); } }
php
{ "resource": "" }
q267080
WebApp.init
test
private function init() { $timeZone = $this->appConfig->getTimeZone(); if (!empty($timeZone)) { $this->timeZone->setDefaultTimeZone($timeZone); } }
php
{ "resource": "" }
q267081
ThrowPromise.execute
test
public function execute(array $args, FunctionProphecy $function) { if (is_string($this->exception)) { $classname = $this->exception; $reflection = new ReflectionClass($classname); $constructor = $reflection->getConstructor(); if ($constructor->isPublic() && 0 == $constructor->getNumberOfRequiredParameters()) { throw $reflection->newInstance(); } if (!$this->instantiator) { $this->instantiator = new Instantiator(); } throw $this->instantiator->instantiate($classname); } throw $this->exception; }
php
{ "resource": "" }
q267082
Field.toArray
test
public function toArray() { return [ 'name' => $this->name, 'title' => $this->title, 'type' => $this->type, 'value' => $this->value, 'attributes' => $this->getAttributesData(), ]; }
php
{ "resource": "" }
q267083
DbManager.init
test
public function init() { parent::init(); $this->db = Instance::ensure($this->db, DatabaseInterface::class); if ($this->cache !== null) { $this->cache = Instance::ensure($this->cache, CacheInterface::class); } }
php
{ "resource": "" }
q267084
DbManager.getChildrenList
test
protected function getChildrenList() { return (new Query())->from($this->itemChildTable) ->all($this->db) ->then( function($rows) { $parents = []; foreach ($rows as $row) { $parents[$row['parent']][] = $row['child']; } return $parents; } ); }
php
{ "resource": "" }
q267085
DbManager.detectLoop
test
protected function detectLoop($parent, $child) { if ($child->name === $parent->name) { return reject(true); } return $this->getChildren($child->name) ->then(function($children) use ($parent) { $promises = []; foreach ($children as $grandchild) { $promises[] = $this->detectLoop($parent, $grandchild); } return !empty($promises) ? all($promises)->then(function() { return false; }) : false; }, function() { return false; }); }
php
{ "resource": "" }
q267086
DbManager.invalidateCache
test
public function invalidateCache() { $this->_checkAccessAssignments = []; if ($this->cache !== null) { $this->items = null; $this->rules = null; $this->parents = null; return $this->cache->delete($this->cacheKey) ->then(function() { return true; }, function() { return true; }); } return resolve(true); }
php
{ "resource": "" }
q267087
DoctrineMigrationRepository.getLastBatchNumber
test
public function getLastBatchNumber() { $result = $this->getEntities()->createQueryBuilder() ->select('o, MAX(o.batch) as max_batch') ->from('Mitch\LaravelDoctrine\Migrations\Migration', 'o') ->getQuery()->getResult()[0]['max_batch']; return $result ?: 0; }
php
{ "resource": "" }
q267088
Response.html
test
public static function html($content = null, $code = 200, array $headers = []) { return new Response\Html($content, $code , $headers); }
php
{ "resource": "" }
q267089
Response.json
test
public static function json($content = null, $code = 200, array $headers = []) { return new Response\Json($content, $code , $headers); }
php
{ "resource": "" }
q267090
Response.template
test
public static function template($template, array $vars = [], $code = 200, array $headers = []) { return new Response\Template($template, $vars, $code , $headers); }
php
{ "resource": "" }
q267091
ControllerService.others
test
protected static function others(FileManager $fileManager, array &$parameters) { if (in_array( static::explain($parameters, 'Do you want to create Model layer?', '[y/n]'), static::POSITIVES) ) { $fileManager->execute('model'); } if (in_array( static::explain($parameters, 'Do you want to create Repository layer?', '[y/n]'), self::POSITIVES )) { $fileManager->execute('repository'); } }
php
{ "resource": "" }
q267092
Zend_Filter_Compress.getAdapter
test
public function getAdapter() { if ($this->_adapter instanceof Zend_Filter_Compress_CompressInterface) { return $this->_adapter; } $adapter = $this->_adapter; $options = $this->getAdapterOptions(); if (!class_exists($adapter)) { if (Zend_Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend_Filter_Compress_' . ucfirst($adapter); } Zend_Loader::loadClass($adapter); } $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof Zend_Filter_Compress_CompressInterface) { throw new Zend_Filter_Exception("Compression adapter '" . $adapter . "' does not implement Zend_Filter_Compress_CompressInterface"); } return $this->_adapter; }
php
{ "resource": "" }
q267093
Zend_Filter_Compress.setAdapter
test
public function setAdapter($adapter) { if ($adapter instanceof Zend_Filter_Compress_CompressInterface) { $this->_adapter = $adapter; return $this; } if (!is_string($adapter)) { throw new Zend_Filter_Exception('Invalid adapter provided; must be string or instance of Zend_Filter_Compress_CompressInterface'); } $this->_adapter = $adapter; return $this; }
php
{ "resource": "" }
q267094
AbstractRoutes.setPrefix
test
private static function setPrefix(array $config) { if(array_key_exists('prefix', $config)) { static::$prefix = $config['prefix']; } // Route group prefix must be set or defined. if(is_null(static::$prefix)) { throw new Exception(__CLASS__ . ': $prefix can not be null.'); } }
php
{ "resource": "" }
q267095
Request.getValue
test
private function getValue($name) { if (!$this->serverAccessor->contains($name)) { return null; } return $this->serverAccessor->getValue($name); }
php
{ "resource": "" }
q267096
DefaultController.indexAction
test
public function indexAction($offset = 0, $limit = 5, $table = null, $show = null) { return array(self::$views_dir.'hello', array( 'altdb'=>$this->getContainer()->get('request')->getUrlArg('altdb'), 'title' => $this->trans("Hello"), )); }
php
{ "resource": "" }
q267097
DefaultController.installAction
test
public function installAction() { $_altdb = $this->getContainer()->get('request')->getUrlArg('altdb'); $SQLITE = $this->getContainer()->get('database'); $tables = \CarteBlanche\Library\AutoObject\AutoObjectMapper::getObjectsStructure( $_altdb ); if (!empty($tables)) { $installed = array(); foreach ($tables as $table) { $err = $SQLITE->add_table( $table['table'], $table['structure'] ); if (!$err) { trigger_error( "An error occurred while creating table '{$table['table']}'!", E_USER_ERROR); } $installed[] = $table['table']; } } $this->getContainer()->get('session') ->setFlash("ok:".$this->trans('OK - Tables "%list%" created', array('list'=>join("', '", $installed)))); $this->getContainer()->get('session')->commit(); $this->getContainer()->get('router')->redirect( $this->getContainer()->get('router')->buildUrl('altdb',$_altdb) ); }
php
{ "resource": "" }
q267098
DefaultController.bootErrorAction
test
public function bootErrorAction(array $errors = null) { $session = $this->getContainer()->get('session'); $original_errors = $session->has('boot_errors') ? $session->get('boot_errors') : $errors; $running_user = $this->getKernel()->whoAmI(); return array(self::$views_dir.'errors', array( 'title'=>$this->trans('System errors'), 'original_errors'=>$original_errors, 'running_user' => $running_user, 'errors'=>$errors )); }
php
{ "resource": "" }
q267099
VarDumper.getSerializer
test
private static function getSerializer() { if (!isset(static::$_serializer)) { $superClosure = new \SuperClosure\Serializer(); static::$_serializer = new \Zumba\JsonSerializer\JsonSerializer($superClosure); } return static::$_serializer; }
php
{ "resource": "" }