_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q266100
Repository.all
test
public function all(QueryParameters $queryParameters = null) { return $this->getQuery( $this->createSelectQuery(), $queryParameters )->getResult(); }
php
{ "resource": "" }
q266101
Repository.columns
test
public function columns(array $fields, QueryParameters $queryParameters = null) { $select = ''; foreach($fields as $field) { $select .= 'o.' . $field; if($field !== last($fields)) { $select .= ', '; } } $qb = $this->entities->createQueryBuilder() ->select($select) ->from($this->entityName, 'o'); return $this->getQuery($qb, $queryParameters)->getResult(); }
php
{ "resource": "" }
q266102
Repository.paginate
test
public function paginate($perPage = 25, QueryParameters $queryParameters = null, $currentPage = null, $searchQuery = null) { $currentPage = $currentPage === null ? $this->paginator->getCurrentPage() : $currentPage; $qb = $this->addSearchConditions($this->createSelectQuery(), $searchQuery); $qb = $qb->setFirstResult($perPage * ($currentPage - 1)) ->setMaxResults($perPage); $items = $this->getQuery($qb, $queryParameters)->getResult(); $count = $this->addSearchConditions($this->createCountQuery(), $searchQuery); $count = (int) $this->getQuery($count, $queryParameters)->getSingleScalarResult(); return $this->paginator->make($items, $count, $perPage); }
php
{ "resource": "" }
q266103
Repository.find
test
public function find($id, QueryParameters $queryParameters = null) { $q = $this->getQuery( $this->createSelectQuery() ->andWhere('o.id = :id') ->setParameter('id', $id), $queryParameters ); try { return $q->getSingleResult(); } catch(DoctrineNoResultException $e) { throw $this->makeNoResultException($e, $q); } }
php
{ "resource": "" }
q266104
Repository.persist
test
public function persist($entity, $flush = true) { $this->entities->persist($entity); if($flush) { $this->entities->flush(); } }
php
{ "resource": "" }
q266105
Repository.delete
test
public function delete($entity, $flush = true) { $this->entities->remove($entity); if($flush) { $this->entities->flush(); } }
php
{ "resource": "" }
q266106
Repository.count
test
public function count(QueryParameters $queryParameters = null) { return (int) $this->getQuery( $this->entities->createCountQuery(), $queryParameters )->getSingleScalarResult(); }
php
{ "resource": "" }
q266107
Repository.createSelectQuery
test
protected function createSelectQuery($alias = 'o', $indexBy = null) { return $this->entities ->createQueryBuilder() ->select($alias) ->from($this->entityName, $alias, $indexBy); }
php
{ "resource": "" }
q266108
Repository.applyScopesToQueryBuilder
test
protected function applyScopesToQueryBuilder(QueryBuilder $qb, array $scopes) { foreach((array) $scopes as $scope) { $method = 'scope' . ucfirst($scope); if(method_exists($this, $method)) { $qb = $this->{$method}($qb); } else { throw new InvalidArgumentException('Scope \'' . $scope . '\' not found'); } } return $qb; }
php
{ "resource": "" }
q266109
Repository.applyOrderByToQueryBuilder
test
private function applyOrderByToQueryBuilder(QueryBuilder $queryBuilder, array $orderBy, $alias) { $queryBuilder->orderBy($alias . '.' . $orderBy[0], $orderBy[1]); return $queryBuilder; }
php
{ "resource": "" }
q266110
Repository.makeNoResultException
test
protected function makeNoResultException(\Exception $e, Query $q) { return new NoResultException($e, $this->replaceQueryParameters($q->getDQL(), $q->getParameters())); }
php
{ "resource": "" }
q266111
Repository.replaceQueryParameters
test
private function replaceQueryParameters($query, $parameters) { foreach($parameters as $parameter) { $value = $parameter->getValue(); $value = $value instanceof DateTime ? $value->format('Y-m-d H:i:s') : $value; $query = str_replace(':' . $parameter->getName(), $value, $query); } return $query; }
php
{ "resource": "" }
q266112
Client.addMethod
test
public function addMethod(RPC\Method $method) { $tmp = explode('\\', get_class($method)); $this->methods[end($tmp)] = $method; }
php
{ "resource": "" }
q266113
Client.getMethod
test
public function getMethod($name) { var_dump(array_keys($this->methods)); if (!isset($this->methods[$name])) { throw new RuntimeException(sprintf( 'Unable to find RPC method %s', $name )); } return $this->methods[$name]; }
php
{ "resource": "" }
q266114
Client.shutdown
test
public function shutdown($message = null) { if (!$this->loop) { return false; } if ($message) { $this->log('notice', sprintf('Loop stopped: %s', $message)); } $this->loop = false; return true; }
php
{ "resource": "" }
q266115
Header.add
test
public function add(array $headers) { foreach ($headers as $key => $values) { $this->set($key, $values); } return $this; }
php
{ "resource": "" }
q266116
Header.setLink
test
public function setLink($url, $as, $type = null, $crossorigin = false, $nopush = false) { $args = [ sprintf('<%s>', $url), 'rel=preload', 'as='.$as ]; if (!empty($type)) { $args[] = 'type='.$type; } if ($crossorigin) { $args[] = 'crossorigin'; } if ($nopush) { $args[] = 'nopush'; } return $this->set('Link', implode('; ', $args)); }
php
{ "resource": "" }
q266117
ApiGallery.newRequest
test
public function newRequest(RequestAdapter $request = null) { if (empty($request)) { $request = new GuzzleRequest; } $request = $request::init($this->endPoint); if (! empty($this->plugins)) { array_walk($this->plugins, [$request, 'addPlugin']); } return $request; }
php
{ "resource": "" }
q266118
ApiGallery.newPhoto
test
public function newPhoto(PhotoAdapter $photo = null) { if (empty($photo)) { $class = $this->getChildClassNamespace() . '\\Photo'; $photo = new $class; } if (! empty($this->plugins)) { array_walk($this->plugins, [$photo, 'addPlugin']); } return $photo; }
php
{ "resource": "" }
q266119
Expr.range
test
public function range($val, $x, $y) { return $this->andX($this->gt($val, $x), $this->lt($val, $y)); }
php
{ "resource": "" }
q266120
Session.session_start
test
final public static function session_start() { if ( self::$started ) trigger_error('Session already started', E_USER_WARNING); self::$started = true; if ( isset($_COOKIE[session_name()]) ) { self::$id = $_COOKIE[session_name()]; } else { self::$id = uniqid(); $config = self::session_get_cookie_params(); Cookie::setcookie( session_name(), self::$id, $config['lifetime'], $config['path'], $config['domain'], $config['secure'], $config['httponly'] ); } if ( !$savePath = session_save_path() ) $savePath = sys_get_temp_dir(); if ( !is_dir($savePath) ) mkdir($savePath, 0777); self::$file = sprintf('%s/sess_%s', $savePath, self::$id); if (self::$handler) { self::$handler->open($savePath, session_name()); self::$handler->read(self::$id); } if ( file_exists(self::$file) ) { $data = file_get_contents(self::$file); session_decode($data); } return true; }
php
{ "resource": "" }
q266121
Session.session_regenerate_id
test
final public static function session_regenerate_id($delete_old_session = false) { if ( !self::$started ) return false; if ( $delete_old_session ) self::session_destroy(); else { self::$started = null; self::$file = null; self::$id = null; } if ( isset($_COOKIE[session_name()]) ) unset($_COOKIE[session_name()]); return self::session_start(); }
php
{ "resource": "" }
q266122
Session.session_write_close
test
final public static function session_write_close() { if ( !self::$started ) return; if (self::$handler) { self::$handler->write(self::$id, self::session_encode()); self::$handler->close(); } self::$started = false; file_put_contents(self::$file, self::session_encode()); }
php
{ "resource": "" }
q266123
Session.session_unset
test
final public static function session_unset() { if ( !isset($_SESSION) ) return false; foreach ($_SESSION as $key => $value) { unset($_SESSION[$key]); } }
php
{ "resource": "" }
q266124
Session.session_destroy
test
final public static function session_destroy() { if ( !self::$started ) return false; self::reset(); if ( file_exists(self::$file) ) unlink(self::$file); return true; }
php
{ "resource": "" }
q266125
Session.session_decode
test
final public static function session_decode($data) { if ( !$values = unserialize($data) ) return false; foreach ($values as $key => $value) { $_SESSION[$key] = $value; } return true; }
php
{ "resource": "" }
q266126
Session.session_cache_expire
test
final public static function session_cache_expire($new_cache_expire = null) { if( !$new_cache_expire ) return (int) ini_get('session.cache_expire'); ini_set('session.cache_expire', (int) $new_cache_expire); return (int) $new_cache_expire; }
php
{ "resource": "" }
q266127
StaticInstanceTrait.instance
test
public static function instance($refresh = false) { $className = get_called_class(); if ($refresh || !isset(self::$_instances[$className])) { self::$_instances[$className] = \Reaction::create($className); } return self::$_instances[$className]; }
php
{ "resource": "" }
q266128
Form.getModuleOptions
test
protected function getModuleOptions() { $entitys = $this->moduleService->getAll(array( 'pagination' => 'off' )); $options = array(); foreach ($entitys as $entity) { $options[$entity->getModuleId()] = $entity->getModuleName(); } return $options; }
php
{ "resource": "" }
q266129
Matrix.getSize
test
public function getSize($which = null) { if (!empty($which)) { return (isset($this->_size[$which]) ? $this->_size[$which] : null); } else { return $this->_size; } }
php
{ "resource": "" }
q266130
Matrix.setWalkFlag
test
public function setWalkFlag($flag, $auto_rewind = true) { $this->_walk_flag = $flag; if (true==$auto_rewind) { $this->rewindXY(); } return $this; }
php
{ "resource": "" }
q266131
Matrix.setArrayFlag
test
public function setArrayFlag($flag, $auto_rewind = true) { $this->_array_flag = $flag; if (true==$auto_rewind) { $this->rewindXY(); } return $this; }
php
{ "resource": "" }
q266132
Matrix.setData
test
public function setData(array $data = null) { $line_length = $column_length = 0; foreach ($data as $x=>$items) { if (!is_array($items)) { throw new InvalidArgumentException( "Data parameter of matrix must be a 2 dimensional array (array of arrays)!" ); } if (count($items)>$line_length) { $line_length = count($items) - 1; } foreach ($items as $subitems) { if (count($subitems)>$column_length) { $column_length = count($subitems) - 1; } } } $this->_size = array( 'x' => $line_length, 'y' => $column_length, 'c' => ($line_length * $column_length) ); foreach ($data as $x=>$items) { $this->data[$x] = $this->_padLine($items); } $this->_cache = $this->data; }
php
{ "resource": "" }
q266133
Matrix.get
test
public function get($index) { try { if (is_string($index)) { if ($this->getWalkFlag() & self::WALK_X) { $ret = $this->getX($index); } elseif ($this->getWalkFlag() & self::WALK_Y) { $ret = $this->getY($index); } else { $ret = $this->getXY($index); } } else { $ret = $this->getInt($index); } } catch (InvalidArgumentException $e) { throw $e; } catch (OutOfRangeException $e) { throw $e; } return $ret; }
php
{ "resource": "" }
q266134
Matrix.set
test
public function set($index, $value) { try { if (is_string($index)) { if ($this->getWalkFlag() & self::WALK_X) { $this->setX($index, $value); } elseif ($this->getWalkFlag() & self::WALK_Y) { $this->setY($index, $value); } else { $this->setXY($index, $value); } } else { $this->setInt($index, $value); } } catch (InvalidArgumentException $e) { throw $e; } catch (OutOfRangeException $e) { throw $e; } return $this; }
php
{ "resource": "" }
q266135
Matrix.rewind
test
public function rewind() { if ($this->getWalkFlag() & self::WALK_X) { return $this->rewindX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->rewindY(); } else { return $this->rewindXY(); } }
php
{ "resource": "" }
q266136
Matrix.previous
test
public function previous() { if ($this->getWalkFlag() & self::WALK_X) { return $this->previousX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->previousY(); } else { return $this->previousXY(); } }
php
{ "resource": "" }
q266137
Matrix.previousX
test
public function previousX() { if ($this->previousXExists()) { $this->seekX($this->keyX()-1); } else { $this->x = null; } return $this; }
php
{ "resource": "" }
q266138
Matrix.previousY
test
public function previousY() { if ($this->previousYExists()) { $this->seekY($this->keyY()-1); } else { $this->y = null; } return $this; }
php
{ "resource": "" }
q266139
Matrix.previousXY
test
public function previousXY() { if (($this->keyY()-1)>0) { $this->seekY($this->keyY()-1); } else { if (($this->keyX()-1)>0) { $this->rewindY(); $this->seekX($this->keyX()-1); } else { $this->x = null; $this->y = null; } } return $this; }
php
{ "resource": "" }
q266140
Matrix.next
test
public function next() { if ($this->getWalkFlag() & self::WALK_X) { return $this->nextX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->nextY(); } else { return $this->nextXY(); } }
php
{ "resource": "" }
q266141
Matrix.nextX
test
public function nextX() { if ($this->nextXExists()) { $this->seekX($this->keyX()+1); } else { $this->x = null; } return $this; }
php
{ "resource": "" }
q266142
Matrix.nextY
test
public function nextY() { if ($this->nextYExists()) { $this->seekY($this->keyY()+1); } else { $this->y = null; } return $this; }
php
{ "resource": "" }
q266143
Matrix.nextXY
test
public function nextXY() { if (($this->keyY()+1)<=$this->countY()) { $this->seekY($this->keyY()+1); } else { if (($this->keyX()+1)<=$this->countX()) { $this->rewindY(); $this->seekX($this->keyX()+1); } else { $this->x = null; $this->y = null; } } return $this; }
php
{ "resource": "" }
q266144
Matrix.seek
test
public function seek($index) { try { if ($this->getWalkFlag() & self::WALK_X) { return $this->seekX($index); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->seekY($index); } else { return $this->seekXY($index); } } catch (InvalidArgumentException $e) { throw $e; } catch (OutOfRangeException $e) { throw $e; } }
php
{ "resource": "" }
q266145
Matrix.current
test
public function current() { if ($this->getWalkFlag() & self::WALK_X) { return $this->currentX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->currentY(); } else { return $this->currentXY(); } }
php
{ "resource": "" }
q266146
Matrix.key
test
public function key() { if ($this->getWalkFlag() & self::WALK_X) { return $this->keyX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->keyY(); } else { return $this->keyXY(); } }
php
{ "resource": "" }
q266147
Matrix.valid
test
public function valid() { if ($this->getWalkFlag() & self::WALK_X) { return $this->validX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->validY(); } else { return $this->validXY(); } }
php
{ "resource": "" }
q266148
Matrix.validX
test
public function validX() { return (bool) (!is_null($this->keyX()) && isset($this->data[$this->keyX(true)])); }
php
{ "resource": "" }
q266149
Matrix.validY
test
public function validY() { return (bool) ($this->validX() && !is_null($this->keyY()) && isset($this->data[$this->keyX(true)][$this->keyY(true)])); }
php
{ "resource": "" }
q266150
Matrix.count
test
public function count() { if ($this->getWalkFlag() & self::WALK_X) { return $this->countX(); } elseif ($this->getWalkFlag() & self::WALK_Y) { return $this->countY(); } else { return $this->countXY(); } }
php
{ "resource": "" }
q266151
Matrix.seekToOffset
test
public function seekToOffset($offset) { try { if (($this->getArrayFlag() & self::ARRAY_INT) && !is_string($offset)) { return $this->seekToOffsetInteger($offset); } else { return $this->seekToOffsetPositional($offset); } } catch (OutOfRangeException $e) { throw $e; } }
php
{ "resource": "" }
q266152
Matrix.seekToOffsetInteger
test
public function seekToOffsetInteger($offset) { $indexes = explode(self::XY_SEPARATOR, $offset); try { if (count($indexes)==2) { if ($indexes[0]=='') { $this->seekY($indexes[1]); } else { $this->seekXY($offset); } } else { $this->seekX($offset); } } catch (OutOfRangeException $e) { throw $e; } return $this; }
php
{ "resource": "" }
q266153
Matrix.offsetExists
test
public function offsetExists($offset) { try { $res = $this ->seekToOffset($offset) ->valid(); } catch (OutOfRangeException $e) { $res = false; } return (bool) $res; }
php
{ "resource": "" }
q266154
Matrix.offsetGet
test
public function offsetGet($offset) { try { $res = $this ->seekToOffset($offset) ->current(); } catch (OutOfRangeException $e) { $res = null; trigger_error("Undefined offset: '$offset'", E_USER_NOTICE); } return $res; }
php
{ "resource": "" }
q266155
Matrix.offsetSet
test
public function offsetSet($offset, $value) { try { $this ->seekToOffset($offset) ->setInt($this->keyInt(), $value); } catch (OutOfRangeException $e) { trigger_error("Undefined offset: '$offset'", E_USER_NOTICE); } return $this; }
php
{ "resource": "" }
q266156
Boolean.IsValid
test
public function IsValid() { if (!is_bool($this->value)) { $errorMsg = 'The $value property of the instance of ' . __CLASS__ . ' is not a boolean.'; throw new InvalidArgumentException($errorMsg, Codes\GeneralErrors::VALUE_IS_NOT_OF_EXPECTED_TYPE, null); } return true; }
php
{ "resource": "" }
q266157
Router.allowViewMethods
test
public function allowViewMethods(string $object, ...$allowedMethods) { if (isset($this->viewMethods[$object]) === false) { $this->viewMethods[$object] = []; } foreach ($allowedMethods as $allowedMethod) { $this->viewMethods[$object][$allowedMethod] = true; } }
php
{ "resource": "" }
q266158
Router.allowControllerMethods
test
public function allowControllerMethods(string $object, ...$allowedMethods) { if (isset($this->controllerMethods[$object]) === false) { $this->controllerMethods[$object] = []; } foreach ($allowedMethods as $allowedMethod) { $this->controllerMethods[$object][$allowedMethod] = true; } }
php
{ "resource": "" }
q266159
Query.table
test
public function table(string $table) { $this->changed = true; $this->table = $table; return $this; }
php
{ "resource": "" }
q266160
Query.from
test
public function from(string ...$table) { $this->changed = true; $this->from = $table; return $this; }
php
{ "resource": "" }
q266161
Query.andWhere
test
public function andWhere(array $conditions) { $this->changed = true; if ($this->conditions) { $this->conditions = [ 'AND', $this->conditions, $conditions, ]; } else { $this->conditions = $conditions; } return $this; }
php
{ "resource": "" }
q266162
Query.orWhere
test
public function orWhere(array $conditions) { $this->changed = true; if ($this->conditions) { $this->conditions = [ 'OR', $this->conditions, $conditions, ]; } else { $this->conditions = $conditions; } return $this; }
php
{ "resource": "" }
q266163
Zend_Filter_Inflector.setStaticRule
test
public function setStaticRule($name, $value) { $name = $this->_normalizeSpec($name); $this->_rules[$name] = (string) $value; return $this; }
php
{ "resource": "" }
q266164
Zend_Filter_Inflector.setStaticRuleReference
test
public function setStaticRuleReference($name, &$reference) { $name = $this->_normalizeSpec($name); $this->_rules[$name] =& $reference; return $this; }
php
{ "resource": "" }
q266165
Zend_Filter_Inflector._getRule
test
protected function _getRule($rule) { if ($rule instanceof Zend_Filter_Interface) { return $rule; } $rule = (string) $rule; $className = $this->getPluginLoader()->load($rule); $ruleObject = new $className(); if (!$ruleObject instanceof Zend_Filter_Interface) { throw new Zend_Filter_Exception('No class named ' . $rule . ' implementing Zend_Filter_Interface could be found'); } return $ruleObject; }
php
{ "resource": "" }
q266166
View.endBody
test
public function endBody() { $this->emit(self::EVENT_END_BODY, [$this]); echo self::PH_BODY_END; foreach (array_keys($this->assetBundles) as $bundle) { $this->registerAssetFiles($bundle); } }
php
{ "resource": "" }
q266167
View.registerJsFile
test
public function registerJsFile($url, $options = [], $key = null) { $url = \Reaction::$app->getAlias($url); $key = $key ?: $url; $helpers = $this->app->helpers; $depends = ArrayHelper::remove($options, 'depends', []); if (empty($depends)) { $position = ArrayHelper::remove($options, 'position', self::POS_END); $this->jsFiles[$position][$key] = $helpers->html->jsFile($url, $options); } else { $this->getAssetManager()->bundles[$key] = Reaction::create([ 'class' => AssetBundle::class, 'baseUrl' => '', 'js' => [strncmp($url, '//', 2) === 0 ? $url : ltrim($url, '/')], 'jsOptions' => $options, 'depends' => (array)$depends, ]); $this->registerAssetBundle($key); } }
php
{ "resource": "" }
q266168
View.registerJsVar
test
public function registerJsVar($name, $value, $position = self::POS_HEAD) { $js = sprintf('var %s = %s;', $name, Json::htmlEncode($value)); $this->registerJs($js, $position, $name); }
php
{ "resource": "" }
q266169
PEAR_Config.getDefaultConfigFiles
test
function getDefaultConfigFiles() { $sl = DIRECTORY_SEPARATOR; if (OS_WINDOWS) { return array( 'user' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.ini', 'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pearsys.ini' ); } return array( 'user' => getenv('HOME') . $sl . '.pearrc', 'system' => PEAR_CONFIG_SYSCONFDIR . $sl . 'pear.conf' ); }
php
{ "resource": "" }
q266170
PEAR_Config.&
test
function &singleton($user_file = '', $system_file = '', $strict = true) { if (is_object($GLOBALS['_PEAR_Config_instance'])) { return $GLOBALS['_PEAR_Config_instance']; } $t_conf = &new PEAR_Config($user_file, $system_file, false, $strict); if ($t_conf->_errorsFound > 0) { return $t_conf->lastError; } $GLOBALS['_PEAR_Config_instance'] = &$t_conf; return $GLOBALS['_PEAR_Config_instance']; }
php
{ "resource": "" }
q266171
PEAR_Config._setupChannels
test
function _setupChannels() { $set = array_flip(array_values($this->_channels)); foreach ($this->configuration as $layer => $data) { $i = 1000; if (isset($data['__channels']) && is_array($data['__channels'])) { foreach ($data['__channels'] as $channel => $info) { $set[$channel] = $i++; } } } $this->_channels = array_values(array_flip($set)); $this->setChannels($this->_channels); }
php
{ "resource": "" }
q266172
PEAR_Config.mergeConfigFile
test
function mergeConfigFile($file, $override = true, $layer = 'user', $strict = true) { if (empty($this->files[$layer])) { return $this->raiseError("unknown config layer `$layer'"); } if ($file === null) { $file = $this->files[$layer]; } $data = $this->_readConfigDataFrom($file); if (PEAR::isError($data)) { if (!$strict) { return true; } $this->_errorsFound++; $this->lastError = $data; return $data; } $this->_decodeInput($data); if ($override) { $this->configuration[$layer] = PEAR_Config::arrayMergeRecursive($this->configuration[$layer], $data); } else { $this->configuration[$layer] = PEAR_Config::arrayMergeRecursive($data, $this->configuration[$layer]); } $this->_setupChannels(); if (!$this->_noRegistry && ($phpdir = $this->get('php_dir', $layer, 'pear.php.net'))) { $this->_registry[$layer] = &new PEAR_Registry($phpdir); $this->_registry[$layer]->setConfig($this, false); $this->_regInitialized[$layer] = false; } else { unset($this->_registry[$layer]); } return true; }
php
{ "resource": "" }
q266173
PEAR_Config.writeConfigFile
test
function writeConfigFile($file = null, $layer = 'user', $data = null) { $this->_lazyChannelSetup($layer); if ($layer == 'both' || $layer == 'all') { foreach ($this->files as $type => $file) { $err = $this->writeConfigFile($file, $type, $data); if (PEAR::isError($err)) { return $err; } } return true; } if (empty($this->files[$layer])) { return $this->raiseError("unknown config file type `$layer'"); } if ($file === null) { $file = $this->files[$layer]; } $data = ($data === null) ? $this->configuration[$layer] : $data; $this->_encodeOutput($data); $opt = array('-p', dirname($file)); if (!@System::mkDir($opt)) { return $this->raiseError("could not create directory: " . dirname($file)); } if (file_exists($file) && is_file($file) && !is_writeable($file)) { return $this->raiseError("no write access to $file!"); } $fp = @fopen($file, "w"); if (!$fp) { return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed ($php_errormsg)"); } $contents = "#PEAR_Config 0.9\n" . serialize($data); if (!@fwrite($fp, $contents)) { return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ($php_errormsg)"); } return true; }
php
{ "resource": "" }
q266174
PEAR_Config._readConfigDataFrom
test
function _readConfigDataFrom($file) { $fp = false; if (file_exists($file)) { $fp = @fopen($file, "r"); } if (!$fp) { return $this->raiseError("PEAR_Config::readConfigFile fopen('$file','r') failed"); } $size = filesize($file); $rt = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); fclose($fp); $contents = file_get_contents($file); if (empty($contents)) { return $this->raiseError('Configuration file "' . $file . '" is empty'); } set_magic_quotes_runtime($rt); $version = false; if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) { $version = $matches[1]; $contents = substr($contents, strlen($matches[0])); } else { // Museum config file if (substr($contents,0,2) == 'a:') { $version = '0.1'; } } if ($version && version_compare("$version", '1', '<')) { // no '@', it is possible that unserialize // raises a notice but it seems to block IO to // STDOUT if a '@' is used and a notice is raise $data = unserialize($contents); if (!is_array($data) && !$data) { if ($contents == serialize(false)) { $data = array(); } else { $err = $this->raiseError("PEAR_Config: bad data in $file"); return $err; } } if (!is_array($data)) { if (strlen(trim($contents)) > 0) { $error = "PEAR_Config: bad data in $file"; $err = $this->raiseError($error); return $err; } $data = array(); } // add parsing of newer formats here... } else { $err = $this->raiseError("$file: unknown version `$version'"); return $err; } return $data; }
php
{ "resource": "" }
q266175
PEAR_Config.getDefaultChannel
test
function getDefaultChannel($layer = null) { $ret = false; if ($layer === null) { foreach ($this->layers as $layer) { if (isset($this->configuration[$layer]['default_channel'])) { $ret = $this->configuration[$layer]['default_channel']; break; } } } elseif (isset($this->configuration[$layer]['default_channel'])) { $ret = $this->configuration[$layer]['default_channel']; } if ($ret == 'pear.php.net' && defined('PEAR_RUNTYPE') && PEAR_RUNTYPE == 'pecl') { $ret = 'pecl.php.net'; } if ($ret) { if ($ret != 'pear.php.net') { $this->_lazyChannelSetup(); } return $ret; } return PEAR_CONFIG_DEFAULT_CHANNEL; }
php
{ "resource": "" }
q266176
PEAR_Config._getChannelValue
test
function _getChannelValue($key, $layer, $channel) { if ($key == '__channels' || $channel == 'pear.php.net') { return null; } $ret = null; if ($layer === null) { foreach ($this->layers as $ilayer) { if (isset($this->configuration[$ilayer]['__channels'][$channel][$key])) { $ret = $this->configuration[$ilayer]['__channels'][$channel][$key]; break; } } } elseif (isset($this->configuration[$layer]['__channels'][$channel][$key])) { $ret = $this->configuration[$layer]['__channels'][$channel][$key]; } if ($key != 'preferred_mirror') { return $ret; } if ($ret !== null) { $reg = &$this->getRegistry($layer); if (is_object($reg)) { $chan = &$reg->getChannel($channel); if (PEAR::isError($chan)) { return $channel; } if (!$chan->getMirror($ret) && $chan->getName() != $ret) { return $channel; // mirror does not exist } } return $ret; } if ($channel != $this->getDefaultChannel($layer)) { return $channel; // we must use the channel name as the preferred mirror // if the user has not chosen an alternate } return $this->getDefaultChannel($layer); }
php
{ "resource": "" }
q266177
PEAR_Config.setChannels
test
function setChannels($channels, $merge = false) { if (!is_array($channels)) { return false; } if ($merge) { $this->_channels = array_merge($this->_channels, $channels); } else { $this->_channels = $channels; } foreach ($channels as $channel) { $channel = strtolower($channel); if ($channel == 'pear.php.net') { continue; } foreach ($this->layers as $layer) { if (!isset($this->configuration[$layer]['__channels'])) { $this->configuration[$layer]['__channels'] = array(); } if (!isset($this->configuration[$layer]['__channels'][$channel]) || !is_array($this->configuration[$layer]['__channels'][$channel])) { $this->configuration[$layer]['__channels'][$channel] = array(); } } } return true; }
php
{ "resource": "" }
q266178
PEAR_Config.getType
test
function getType($key) { if (isset($this->configuration_info[$key])) { return $this->configuration_info[$key]['type']; } return false; }
php
{ "resource": "" }
q266179
PEAR_Config.getDocs
test
function getDocs($key) { if (isset($this->configuration_info[$key])) { return $this->configuration_info[$key]['doc']; } return false; }
php
{ "resource": "" }
q266180
PEAR_Config.getPrompt
test
function getPrompt($key) { if (isset($this->configuration_info[$key])) { return $this->configuration_info[$key]['prompt']; } return false; }
php
{ "resource": "" }
q266181
PEAR_Config.getGroup
test
function getGroup($key) { if (isset($this->configuration_info[$key])) { return $this->configuration_info[$key]['group']; } return false; }
php
{ "resource": "" }
q266182
PEAR_Config.getGroups
test
function getGroups() { $tmp = array(); foreach ($this->configuration_info as $key => $info) { $tmp[$info['group']] = 1; } return array_keys($tmp); }
php
{ "resource": "" }
q266183
PEAR_Config.getGroupKeys
test
function getGroupKeys($group) { $keys = array(); foreach ($this->configuration_info as $key => $info) { if ($info['group'] == $group) { $keys[] = $key; } } return $keys; }
php
{ "resource": "" }
q266184
PEAR_Config.getSetValues
test
function getSetValues($key) { if (isset($this->configuration_info[$key]) && isset($this->configuration_info[$key]['type']) && $this->configuration_info[$key]['type'] == 'set') { $valid_set = $this->configuration_info[$key]['valid_set']; reset($valid_set); if (key($valid_set) === 0) { return $valid_set; } return array_keys($valid_set); } return null; }
php
{ "resource": "" }
q266185
PEAR_Config.getKeys
test
function getKeys() { $keys = array(); foreach ($this->layers as $layer) { $test = $this->configuration[$layer]; if (isset($test['__channels'])) { foreach ($test['__channels'] as $channel => $configs) { $keys = array_merge($keys, $configs); } } unset($test['__channels']); $keys = array_merge($keys, $test); } return array_keys($keys); }
php
{ "resource": "" }
q266186
PEAR_Config.remove
test
function remove($key, $layer = 'user', $channel = null) { if ($channel === null) { $channel = $this->getDefaultChannel(); } if ($channel !== 'pear.php.net') { if (isset($this->configuration[$layer]['__channels'][$channel][$key])) { unset($this->configuration[$layer]['__channels'][$channel][$key]); return true; } } if (isset($this->configuration[$layer][$key])) { unset($this->configuration[$layer][$key]); return true; } return false; }
php
{ "resource": "" }
q266187
PEAR_Config.removeLayer
test
function removeLayer($layer) { if (isset($this->configuration[$layer])) { $this->configuration[$layer] = array(); return true; } return false; }
php
{ "resource": "" }
q266188
PEAR_Config.definedBy
test
function definedBy($key, $returnchannel = false) { foreach ($this->layers as $layer) { $channel = $this->getDefaultChannel(); if ($channel !== 'pear.php.net') { if (isset($this->configuration[$layer]['__channels'][$channel][$key])) { if ($returnchannel) { return array('layer' => $layer, 'channel' => $channel); } return $layer; } } if (isset($this->configuration[$layer][$key])) { if ($returnchannel) { return array('layer' => $layer, 'channel' => 'pear.php.net'); } return $layer; } } return ''; }
php
{ "resource": "" }
q266189
PEAR_Config.isDefined
test
function isDefined($key) { foreach ($this->layers as $layer) { if (isset($this->configuration[$layer][$key])) { return true; } } return false; }
php
{ "resource": "" }
q266190
PEAR_Config.setRegistry
test
function setRegistry(&$reg, $layer = 'user') { if ($this->_noRegistry) { return false; } if (!in_array($layer, array('user', 'system'))) { return false; } $this->_registry[$layer] = &$reg; if (is_object($reg)) { $this->_registry[$layer]->setConfig($this, false); } return true; }
php
{ "resource": "" }
q266191
Zend_Config_Json._processExtends
test
protected function _processExtends(array $data, $section, array $config = array()) { if (!isset($data[$section])) { throw new Zend_Config_Exception(sprintf('Section "%s" cannot be found', $section)); } $thisSection = $data[$section]; if (is_array($thisSection) && isset($thisSection[self::EXTENDS_NAME])) { if (is_array($thisSection[self::EXTENDS_NAME])) { throw new Zend_Config_Exception('Invalid extends clause: must be a string; array received'); } $this->_assertValidExtend($section, $thisSection[self::EXTENDS_NAME]); if (!$this->_skipExtends) { $config = $this->_processExtends($data, $thisSection[self::EXTENDS_NAME], $config); } unset($thisSection[self::EXTENDS_NAME]); } $config = $this->_arrayMergeRecursive($config, $thisSection); return $config; }
php
{ "resource": "" }
q266192
Zend_Config_Json._replaceConstants
test
protected function _replaceConstants($value) { foreach ($this->_getConstants() as $constant) { if (strstr($value, $constant)) { // handle backslashes that may represent windows path names for instance $replacement = str_replace('\\', '\\\\', constant($constant)); $value = str_replace($constant, $replacement, $value); } } return $value; }
php
{ "resource": "" }
q266193
PdoWriter.getCallback
test
protected function getCallback(): callable { if ($this->callback === null) { $this->callback = function (LogInterface $log): array { $metaData = $log->getMetaData() ?: null; if (is_array($metaData) === true) { $metaData = json_encode($metaData, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES); } $priority = $log->getPriority(); return [ 'value' => $priority->getValue(), 'keyword' => strtoupper($priority->getKeyword()), 'date_time' => $log->getDateTime()->format('Y-m-d H:i:s'), 'message' => $log->getMessage(), 'meta_data' => $metaData, ]; }; } return $this->callback; }
php
{ "resource": "" }
q266194
Enum.isValid
test
public static function isValid($value): bool { if (\is_array($value) || \is_object($value)) { return false; } // Get the valid values to compare with $validValues = static::validValues(); // If the value isset in the valid values array and the value matches // the value to check // ?? Why is this here ?? // As is known by all isset is faster than in_array. We want to // capitalize on that with some enums by making the const VALUES // array a key value pair of the value itself so that we've // essentially got value => value for each item in the const VALUES // array. This way we can take advantage of the quickness of isset over // in_array. However, because not all enums may do this we need to // ensure if the value isset as the key in the array that it also // matches as the value of that item in the array, otherwise we'll // get false positives where its a normal array of 0 => value, 1 => // value and we check for 0 being a valid value where it may very // well not be valid at all. if (isset($validValues[$value]) && $validValues[$value] === $value) { return true; } return \in_array($value, $validValues, true); }
php
{ "resource": "" }
q266195
Enum.validValues
test
public static function validValues(): array { // If the const VALUES array has been populated if (null !== static::VALUES) { // Use it as the developer took the time to define it return static::VALUES; } // Get the class name that was called $className = static::class; // If the called enum isn't yet cached // and the values aren't already set (to avoid a reflection class) if (! array_key_exists($className, self::$cache)) { // Set the cache to avoid a reflection class creation on each new // instance of the enum self::$cache[$className] = static::reflectionValidValues(); } return self::$cache[$className] ?? []; }
php
{ "resource": "" }
q266196
Enum.reflectionValidValues
test
protected static function reflectionValidValues(): array { try { // Get a reflection class of the enum $reflectionClass = new ReflectionClass(static::class); $values = $reflectionClass->getConstants(); } // Catch any exceptions catch (\Exception $exception) { $values = []; } $validValues = []; // Iterate through the values foreach ($values as $key => $value) { // If this value is defined in this abstract Enum (self) if (\defined(self::class . '::' . $key)) { // Unset it from the list as its not a valid Enum value, but // rather a value the Enum class needs (like self::VALUES) unset($values[$key]); continue; } $validValues[$value] = $value; } return $validValues; }
php
{ "resource": "" }
q266197
Enum.setValue
test
public function setValue($value): void { // If the value is not valid if (! static::isValid($value)) { // Throw an exception throw new InvalidArgumentException( sprintf( 'Invalid enumeration %s for Enum %s', $value, \get_class($this) ) ); } $this->value = $value; }
php
{ "resource": "" }
q266198
PEAR_Task_Postinstallscript.init
test
function init($xml, $fileattribs, $lastversion) { $this->_class = str_replace('/', '_', $fileattribs['name']); $this->_filename = $fileattribs['name']; $this->_class = str_replace ('.php', '', $this->_class) . '_postinstall'; $this->_params = $xml; $this->_lastversion = $lastversion; }
php
{ "resource": "" }
q266199
PEAR_Task_Postinstallscript.startSession
test
function startSession($pkg, $contents) { if ($this->installphase != PEAR_TASK_INSTALL) { return false; } // remove the tasks: namespace if present $this->_pkg = $pkg; $this->_stripNamespace(); $this->logger->log(0, 'Including external post-installation script "' . $contents . '" - any errors are in this script'); include_once $contents; if (class_exists($this->_class)) { $this->logger->log(0, 'Inclusion succeeded'); } else { return $this->throwError('init of post-install script class "' . $this->_class . '" failed'); } $this->_obj = new $this->_class; $this->logger->log(1, 'running post-install script "' . $this->_class . '->init()"'); PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $res = $this->_obj->init($this->config, $pkg, $this->_lastversion); PEAR::popErrorHandling(); if ($res) { $this->logger->log(0, 'init succeeded'); } else { return $this->throwError('init of post-install script "' . $this->_class . '->init()" failed'); } $this->_contents = $contents; return true; }
php
{ "resource": "" }