_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q239400
|
PhpMd.ignorePatterns
|
train
|
public function ignorePatterns($ignorePatterns)
{
if (!is_array($ignorePatterns)) {
$ignorePatterns = [$ignorePatterns];
}
$this->ignorePatterns = array_unique(array_merge($this->ignorePatterns, $ignorePatterns));
return $this;
}
|
php
|
{
"resource": ""
}
|
q239401
|
ResourceServer.isValidRequest
|
train
|
public function isValidRequest($headerOnly = true, $accessToken = null)
{
$accessTokenString = ($accessToken !== null)
? $accessToken
: $this->determineAccessToken($headerOnly);
// Set the access token
$this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString);
// Ensure the access token exists
if (!$this->accessToken instanceof AccessTokenEntity) {
throw new AccessDeniedException();
}
// Check the access token hasn't expired
// Ensure the auth code hasn't expired
if ($this->accessToken->isExpired() === true) {
throw new AccessDeniedException();
}
\Illuminate\Support\Facades\DB::table('oauth_access_tokens')->where('id', $accessTokenString)->update(['expire_time' => time() + 30]);
return true;
}
|
php
|
{
"resource": ""
}
|
q239402
|
ResourceServer.determineAccessToken
|
train
|
public function determineAccessToken($headerOnly = false)
{
if (!empty($this->getRequest()->headers->get('Authorization'))) {
$accessToken = $this->getTokenType()->determineAccessTokenInHeader($this->getRequest());
} elseif ($headerOnly === false && (! $this->getTokenType() instanceof MAC)) {
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET')
? $this->getRequest()->query->get($this->tokenKey)
: $this->getRequest()->request->get($this->tokenKey);
}
if (empty($accessToken)) {
throw new InvalidRequestException('access token');
}
return $accessToken;
}
|
php
|
{
"resource": ""
}
|
q239403
|
SynchronizeController.indexAction
|
train
|
public function indexAction()
{
$models = $this->getAllModels();
foreach($models as $model) {
$this->checkTable(new $model['namespace']);
}
}
|
php
|
{
"resource": ""
}
|
q239404
|
SynchronizeController.checkTable
|
train
|
private function checkTable($modelObj)
{
if (!method_exists($modelObj, 'table')) {
return false;
}
// get table name
$tableName = $modelObj->table();
// check table, add if not exist
$existTable = PdoDriver::getInstance()->tableExists($tableName);
if (!$existTable) {
$this->createTable($tableName, $modelObj->getFields());
CliManager::getMessage('Created table ' . $tableName);
}
// get database table data and check
PdoDriver::getInstance()->query('SHOW COLUMNS FROM ' . $tableName);
$dbFields = PdoDriver::getInstance()->selectAll();
$modelFieldNames = [];
foreach ($modelObj->getFields() as $modelField) {
$modelFieldNames[] = $modelField->identifier();
}
// check db fields on model fields
$dbFieldNames = [];
foreach ($dbFields as $dbField) {
if (!in_array($dbField->Field, $modelFieldNames)) {
echo " --- Old field " . CliManager::setTextColor($dbField->Field, 'yellow') . " in table " . CliManager::setTextColor($modelObj->table(), 'green') . " --- \n\r";
}
$dbFieldNames[] = $dbField->Field;
}
// check model fields on db fields
foreach ($modelObj->getFields() as $key => $modelField) {
if (!in_array($modelField->identifier(), $dbFieldNames)) {
// Add new fields to db table
$previousField = false;
if (isset($modelObj->getFields()[$key-1])) {
$previousField = $modelObj->getFields()[$key-1];
}
$this->createField($tableName, $modelField, $previousField);
echo CliManager::setTextColor(" --- Add New field " . $modelField->identifier() . " in table " . $modelObj->table(), 'green') . " --- \n\r";
}
}
}
|
php
|
{
"resource": ""
}
|
q239405
|
SynchronizeController.getAllModels
|
train
|
private function getAllModels()
{
$modules = Safan::handler()->getModules();
$modelClasses = [];
foreach ($modules as $moduleName => $modulePath) {
$modelsPath = APP_BASE_PATH . DS . $modulePath . DS . 'Models';
$modelFiles = [];
if (is_dir($modelsPath)) {
$modelFiles = scandir($modelsPath);
}
foreach ($modelFiles as $modelFile) {
if ($modelFile != '.' && $modelFile != '..' && is_dir($modelsPath . DS . $modelFile)) {
$subModelFiles = scandir($modelsPath . DS . $modelFile);
foreach ($subModelFiles as $subModelFile) {
if ($subModelFile != '.' && $subModelFile != '..' && is_file($modelsPath . DS . $modelFile . DS . $subModelFile)) {
$subModelName = substr($subModelFile, 0, -4);
$modelClasses[] = [
'name' => $subModelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelFile . '\\' . $subModelName,
'file' => $modelsPath . DS . $modelFile . DS . $subModelFile
];
}
}
} elseif ($modelFile != '.' && $modelFile != '..' && is_file($modelsPath . DS . $modelFile)) {
$modelName = substr($modelFile, 0, -4);
$modelClasses[] = [
'name' => $modelName,
'namespace' => '\\' . $moduleName . '\\Models\\' . $modelName,
'file' => $modelsPath . DS . $modelFile
];
}
}
}
return $modelClasses;
}
|
php
|
{
"resource": ""
}
|
q239406
|
ClauseTrait.quoteAlias
|
train
|
protected function quoteAlias($alias, array $settings)/*# : string */
{
if (is_int($alias)) {
return '';
} else {
$prefix = $settings['quotePrefix'];
$suffix = $settings['quoteSuffix'];
return ' AS ' . $this->quoteSpace($alias, $prefix, $suffix);
}
}
|
php
|
{
"resource": ""
}
|
q239407
|
ClauseTrait.&
|
train
|
protected function &getClause(/*# string */ $clauseName)/*# : array */
{
if (empty($clauseName)) {
return $this->clause;
} else {
if (!isset($this->clause[$clauseName])) {
$this->clause[$clauseName] = [];
}
return $this->clause[$clauseName];
}
}
|
php
|
{
"resource": ""
}
|
q239408
|
ClauseTrait.processValue
|
train
|
protected function processValue(
$value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if (is_object($value)) {
return $this->quoteObject($value, $settings);
} elseif (is_array($value)) {
return $this->processArrayValue($value, $settings, $between);
} else {
return $this->processScalarValue($value);
}
}
|
php
|
{
"resource": ""
}
|
q239409
|
ClauseTrait.processArrayValue
|
train
|
protected function processArrayValue(
array $value,
array $settings,
/*# bool */ $between = false
)/*# : string */ {
if ($between) {
$v1 = $this->processValue($value[0], $settings);
$v2 = $this->processValue($value[1], $settings);
return $v1 . ' AND ' . $v2;
} else {
$result = [];
foreach ($value as $val) {
$result[] = $this->processValue($val, $settings);
}
return '(' . join(', ', $result) . ')';
}
}
|
php
|
{
"resource": ""
}
|
q239410
|
ClauseTrait.processScalarValue
|
train
|
protected function processScalarValue($value)/*# : string */
{
if (ClauseInterface::NO_VALUE == $value) {
return '?';
} elseif (is_null($value) || is_bool($value)) {
return strtoupper(var_export($value, true));
} else {
return $this->getBuilder()->getParameter()->getPlaceholder($value);
}
}
|
php
|
{
"resource": ""
}
|
q239411
|
ClauseTrait.joinClause
|
train
|
protected function joinClause(
/*# : string */ $prefix,
/*# : string */ $seperator,
array $clause,
array $settings
)/*# : string */ {
if (empty($clause)) {
return '';
} else {
$sepr = $settings['seperator'];
$join = $settings['join'];
$pref = empty($prefix) ? $join : ($sepr . $prefix . $join);
return $pref . join($seperator . $join, $clause);
}
}
|
php
|
{
"resource": ""
}
|
q239412
|
ClauseTrait.buildClause
|
train
|
protected function buildClause(
/*# string */ $clauseName,
/*# string */ $clausePrefix,
array $settings,
array $clauseParts = []
)/*# string */ {
$clause = &$this->getClause($clauseName);
foreach ($clause as $alias => $field) {
$part =
$this->quoteItem($field[0], $settings, $field[1]) .
$this->quoteAlias($alias, $settings) .
(isset($field[2]) ? (' ' . $field[2]) : '');
$clauseParts[] = $part;
}
return $this->joinClause($clausePrefix, ',', $clauseParts, $settings);
}
|
php
|
{
"resource": ""
}
|
q239413
|
Deque.typed
|
train
|
public static function typed(string $type, iterable $input = []): Deque
{
$resolver = Resolver::typed($type);
return new static($input, $resolver);
}
|
php
|
{
"resource": ""
}
|
q239414
|
Html.link
|
train
|
public function link($target, $caption = null, $attributes = array())
{
// Check if target needs to be resolved
if (is_object($target)) {
// Try to get a link
$target = Url::instance()->show($target);
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
}
|
php
|
{
"resource": ""
}
|
q239415
|
Html.deleteLink
|
train
|
public function deleteLink($target, $caption = null, $confirmMessage = 'Are you sure?', $attributes = array())
{
// Check if target needs to be resolved
if (is_array($target) || is_object($target)) {
// Try to get a link
$target = Url::instance()->delete($target);
}
// Set method to delete
$attributes = array_merge(array(
"data-method" => "delete",
"rel" => "nofollow"
), $attributes);
// Confirm?
if (is_null($confirmMessage)) {
$attributes['data-confirm'] = 'Are you sure?';
} elseif ($confirmMessage !== false) {
$attributes['data-confirm'] = $confirmMessage;
}
// Create element
$link = new \HtmlObject\Link($target, $caption, $attributes);
return $link;
}
|
php
|
{
"resource": ""
}
|
q239416
|
Html.listingFor
|
train
|
public function listingFor($items, \Closure $callback, $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create the element
$list = \HtmlObject\Element::$element('', $attributes);
// Get closure info
$closureMethod = Reflection::getClosureMethod($callback);
$closureArgs = Reflection::getClosureParams($closureMethod);
// Loop through items
$index = 0;
foreach ($items as $item) {
// Invoke the closure
$li = Reflection::invokeClosure($callback,
array($index, $item),
array($item));
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("The ulFor callback needs to return a HTMLObject\\Element, or a string containing HTML.", 1);
}
$index++;
}
return $list;
}
|
php
|
{
"resource": ""
}
|
q239417
|
Html.listing
|
train
|
public function listing($contents = array(), $attributes = array(), $element = 'ul', $childElement = 'li')
{
// Create list
$list = \HtmlObject\Element::$element('', $attributes);
// Array?
if (!is_null($contents) && !is_array($contents)) {
$contents = array($contents);
}
// Loop contents
foreach ($contents as $li) {
// Is it an element?
if (is_string($li)) {
// Create li containing that...
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} elseif (is_subclass_of($li, "\\HtmlObject\\Traits\\Tag")) {
// An li tag?
if ($li->getTag() !== $childElement) {
// Wrap it!
$realLi = \HtmlObject\Element::$childElement($li);
$list->addChild($realLi);
} else {
// Add it as it is
$list->addChild($li);
}
} else {
// Not good.
throw new \Exception("Invalid contents for listing. ", 1);
}
}
return $list;
}
|
php
|
{
"resource": ""
}
|
q239418
|
Html.li
|
train
|
public function li($contents = '', $attributes = array())
{
$li = \HtmlObject\Element::li($contents, $attributes);
return $li;
}
|
php
|
{
"resource": ""
}
|
q239419
|
Session.start
|
train
|
public function start($name = null, $id = null)
{
if (!session_id()) {
if ($name) {
session_name($name);
}
if ($id) {
session_id($this->id);
}
session_start();
return true;
}
return false;
}
|
php
|
{
"resource": ""
}
|
q239420
|
Session.destroy
|
train
|
public function destroy()
{
$_SESSION = [];
if ($this->cookieJar) {
$this->cookieJar->remove($this->name());
} else {
$params = session_get_cookie_params();
setcookie($this->name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
}
|
php
|
{
"resource": ""
}
|
q239421
|
Group.getHtmlId
|
train
|
public function getHtmlId()
{
$form = $this->getParentOfType('\\Zepi\\Web\\UserInterface\\Form\\Form');
// If the group isn't assigned to a data form we can not generate
// the id of the group.
if (!$form) {
return $this->key;
}
return $form->getHtmlId() . '-' . $this->key;
}
|
php
|
{
"resource": ""
}
|
q239422
|
AnnotationBuilderTrait.getFormFactory
|
train
|
public function getFormFactory()
{
if ($this->formFactory) {
return $this->formFactory;
}
$this->formFactory = new Factory();
return $this->formFactory;
}
|
php
|
{
"resource": ""
}
|
q239423
|
AnnotationBuilderTrait.createForm
|
train
|
public function createForm($entity)
{
$formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
if (!isset($formSpec['options']['merge_input_filter'])) {
$formSpec['options']['merge_input_filter'] = true;
}
return $this->getFormFactory()->createForm($formSpec);
}
|
php
|
{
"resource": ""
}
|
q239424
|
AnnotationBuilderTrait.configureElement
|
train
|
protected function configureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return early
if ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = new ArrayObject([
'flags' => [],
'spec' => [
'name' => $name
],
]);
$inputSpec = new ArrayObject([
'name' => $name,
]);
$event = new Event();
$event->setParams([
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
]);
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
}
// Since "filters", "type", "validators" is a reserved names in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1 || $annotations->hasAnnotation(Input::class)) {
if ($name === 'type' || $name === 'filters' || $name === 'validators') {
$filterSpec[] = $event->getParam('inputSpec');
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
}
}
$elementSpec = $event->getParam('elementSpec');
$type = isset($elementSpec['spec']['type'])
? $elementSpec['spec']['type']
: Element::class;
// Compose as a fieldset or an element, based on specification type.
// If preserve defined order is true, all elements are composed as elements to keep their ordering
if (!$this->preserveDefinedOrder() && is_subclass_of($type, FieldsetInterface::class)) {
if (!isset($formSpec['fieldsets'])) {
$formSpec['fieldsets'] = [];
}
if (isset($formSpec['fieldsets'][$name])) {
$formSpec['fieldsets'][] = $elementSpec;
} else {
$formSpec['fieldsets'][$name] = $elementSpec;
}
} else {
if (!isset($formSpec['elements'])) {
$formSpec['elements'] = [];
}
if (isset($formSpec['elements'][$name])) {
$formSpec['elements'][] = $elementSpec;
} else {
$formSpec['elements'][$name] = $elementSpec;
}
}
}
|
php
|
{
"resource": ""
}
|
q239425
|
Htsl.compile
|
train
|
public function compile( string$fromFile, string$toFile='' )
{
$fromFile= $this->getFilePath($fromFile);
$result= $this->execute(new FileBuffer($this,$fromFile));
if( $toFile ){
return file_put_contents($toFile,$result);
}else{
return $result;
}
}
|
php
|
{
"resource": ""
}
|
q239426
|
Htsl.setBasePath
|
train
|
public function setBasePath( string$basePath ):self
{
$this->basePath= '/'===substr($basePath,-1) ? substr($basePath,0,-1) : $basePath;
return $this;
}
|
php
|
{
"resource": ""
}
|
q239427
|
Htsl.getConfig
|
train
|
public function getConfig( string...$keys )
{
$result= $this->config;
foreach( $keys as $key ){
if( !isset($result[$key]) )
{ return null; }
$result= $result[$key];
}
return $result;
}
|
php
|
{
"resource": ""
}
|
q239428
|
Htsl.getFilePath
|
train
|
public function getFilePath( string$filePath, string$path=null ):string
{
if( !isset($this->basePath) )
{ throw new \Exception('BasePath musbe set.'); }
if( !strlen($filePath) )
{ throw new \Exception('FilePath cannot be empty.'); }
if( '/'===$filePath{0} ){
if( is_null($path) )
{ return $filePath; }
else
{ return $this->basePath.$filePath; }
}else{
if( !strlen($path) )
{ return $this->basePath.'/'.$filePath; }
elseif( '/'===substr($path,-1) )
{ return $path.$filePath; }
else
{ return $path.'/'.$filePath; }
}
}
|
php
|
{
"resource": ""
}
|
q239429
|
Htsl.getFileContent
|
train
|
public function getFileContent( string$filePath ):string
{
return isset($this->fileGetter) ? $this->fileGetter($filePath) : file_get_contents($filePath);
}
|
php
|
{
"resource": ""
}
|
q239430
|
InputTypeResolverTrait.getInputFor
|
train
|
public static function getInputFor(\stdClass $fieldData)
{
$formData = explode(':', $fieldData->type->ui);
$type = $formData[0];
$options = isset($formData[1]) ? $formData[1] : '[]';
if ($type == 'text' ||
$type == 'number' ||
$type == 'textarea' ||
$type == 'date'
)
{
return '{!! Form::' . $type . '(\'' . $fieldData->name . '\', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'select')
{
$list = isset($formData[1]) ? $formData[1] : '[]';
$options = isset($formData[2]) ? $formData[2] : '[]';
return '{!! Form::select(\'' . $fieldData->name . '\', ' . $list . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'selectRange')
{
$begin = isset($formData[1]) ? $formData[1] : '0';
$end = isset($formData[2]) ? $formData[2] : '0';
$options = isset($formData[3]) ? $formData[3] : '[]';
return '{!! Form::selectRange(\'' . $fieldData->name . '\', ' . $begin . ', ' . $end . ', (isset($model)) ? $model->' . $fieldData->name . ' : null, ' . $options . ') !!}';
}
elseif ($type == 'checkbox')
{
$options = isset($formData[1]) ? $formData[1] : 'false';
return '{!! Form::checkbox(\'' . $fieldData->name . '\', 1, (isset($model) && $model->' . $fieldData->name . ' == 1) ? true : false, ' . $options . ') !!}';
}
elseif ($type == 'radio')
{
array_shift($formData);
$radioGroup = '';
$radioId = 0;
foreach ($formData as $value)
{
$radioGroup .= '{!! Form::radio(\'' . $fieldData->name . '\', \'' . $value . '\', (isset($model) && $model->' . $fieldData->name . ' == \'' . $value . '\') ? true : false, [\'id\' => ' . $radioId . ']) !!}';
$radioId++;
if (end($formData) != $value) $radioGroup .= PHP_EOL . "\t";
}
return $radioGroup;
}
else
{
throw new \Exception('Input type not implemented');
}
}
|
php
|
{
"resource": ""
}
|
q239431
|
Router.processMap
|
train
|
protected function processMap($arr, $prefix='') {
foreach ($arr as $uri => $options) {
$uri = $prefix . $this->preProcessURI($uri);
foreach ($options as $method => $target) {
if (!is_array($target)) continue;
if (array_key_exists('name', $target)) {
$this->map($method, $uri, $target, $target['name']);
} else {
$this->map($method, $uri, $target);
}
}
}
}
|
php
|
{
"resource": ""
}
|
q239432
|
Router.preProcessURI
|
train
|
public function preProcessURI($uri) {
$s = preg_replace("/\{([\w]+)\}/", "[*:$1]", $uri);
if (!empty($s)) {
$uri = $s;
}
return $uri;
}
|
php
|
{
"resource": ""
}
|
q239433
|
Router.evaluate
|
train
|
public function evaluate($target) {
switch (Utils::get('type', $target)) {
case 'class' :
$return = $this->processClass(Utils::get('target',$target), Utils::get('match', $target));
break;
case 'controller' :
$return = $this->processController(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'view':
$return = $this->processView(Utils::get('target', $target), Utils::get('match', $target));
break;
case 'eval':
$return = eval($target['target']['eval']);
break;
default:
throw new \Exception("Undefined target",404);
}
return $return;
}
|
php
|
{
"resource": ""
}
|
q239434
|
Router.resolve
|
train
|
public function resolve() {
$return = false;
$match = $this->match();
if (!$match) {
$target = $this->getDefaultRoute();
if ($target) {
$match = ['target' => $target];
}
}
if (substr(Utils::get('name', $match, ''),0,7) =='plugin:') {
Application::getInstance()->preparePlugin($match['name']);
}
if (is_array($match) && array_key_exists('target', $match)) {
$target = $match['target'];
$return = ['target'=>$target, 'match'=>$match, 'application' => $this->getApplicationName()];
if (array_key_exists('class', $target)) {
$return['type'] = 'class';
} elseif (array_key_exists('controller', $target)) {
$return['type'] = 'controller';
} elseif (array_key_exists('view', $target)) {
$return['type'] = 'view';
} elseif (array_key_exists('eval', $target)) {
$return['type'] = 'eval';
} else {
$return = ['success'=>false, 'msg' => "Target undefined",'code'=>404, 'info'=> $match];
}
} else {
$return = ['success'=>false, 'msg' => "Target not found",'code'=>404, 'info'=> $match];
}
return $return;
}
|
php
|
{
"resource": ""
}
|
q239435
|
AdminController.assets
|
train
|
public function assets(Response $response, $asset)
{
$filesystem = new Filesystem(new Adapter(FS2ADMIN));
$expires = 8640000;
try {
// generate cache data
$timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
$etag = md5($filesystem->read($asset));
$mime_type = $filesystem->getMimetype($asset);
if (0 !== strpos($mime_type, 'image')) {
$mime_type = 'text/css';
}
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if ((($if_none_match && $if_none_match == "\"{$etag}\"") || (!$if_none_match)) &&
($if_modified_since && $if_modified_since == $timestamp_string)
) {
return $response->withStatus('304');
} else {
$response = $response
->withHeader('Last-Modified', $timestamp_string)
->withHeader('ETag', "\"{$etag}\"");
}
// send out content type, expire time and the file
$response->getBody()->write($filesystem->read($asset));
return $response
->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')
->withHeader('Content-Type', $mime_type)
->withHeader('Pragma', 'cache')
->withHeader('Cache-Control', 'cache');
} catch (FileNotFoundException $e) {
throw $e;
}
}
|
php
|
{
"resource": ""
}
|
q239436
|
QueueController.index
|
train
|
public function index()
{
try {
$jobs = FailedJob::orderBy('id', 'DESC')->paginate();
} catch (QueryException $e) {
return $this->setup();
}
return view('laravie/quemon::index', compact('jobs'));
}
|
php
|
{
"resource": ""
}
|
q239437
|
ArrayList.add
|
train
|
public function add($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
}
|
php
|
{
"resource": ""
}
|
q239438
|
ArrayList.average
|
train
|
public function average(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
return Number::divide($this->sum(), \strval($this->count()));
}
|
php
|
{
"resource": ""
}
|
q239439
|
ArrayList.chunk
|
train
|
public function chunk($size){
$outer = new static();
$chunks = \array_chunk($this->_Arr, $size);
foreach($chunks as $chunk){
$outer->pushBack(new static($chunk));
}
return $outer;
}
|
php
|
{
"resource": ""
}
|
q239440
|
ArrayList.concat
|
train
|
public function concat(ICollection $coll){
$arr = array();
$coll->copyTo($arr);
return new static(\array_merge($this->_Arr, \array_values($arr)));
}
|
php
|
{
"resource": ""
}
|
q239441
|
ArrayList.copy
|
train
|
public function copy($deep = true){
$arr = array();
foreach($this->_Arr as $key => $item){
$arr[$key] = $deep
? Functions\Object::copy($item)
: $item;
}
return new static($arr);
}
|
php
|
{
"resource": ""
}
|
q239442
|
ArrayList.copyTo
|
train
|
public function copyTo(array &$arr, $index = 0) {
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index);
return $this;
}
|
php
|
{
"resource": ""
}
|
q239443
|
ArrayList.intersect
|
train
|
public function intersect(ICollection $coll){
//array_intersect does not work on \Closure objects
$arr = array();
$coll->copyTo($arr);
$ret = array();
foreach($this->_Arr as $outerItem){
foreach($arr as $innerItem){
if($innerItem === $outerItem){
$ret[] = $outerItem;
break;
}
}
}
return new static($ret);
}
|
php
|
{
"resource": ""
}
|
q239444
|
ArrayList.insert
|
train
|
public function insert($index, $value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
//Permit 0-index insertion
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 0, array($value));
return $this;
}
|
php
|
{
"resource": ""
}
|
q239445
|
ArrayList.insertRange
|
train
|
public function insertRange($index, ICollection $coll){
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = array();
$coll->copyTo($arr);
\array_splice($this->_Arr, $index, 0, $arr);
return $this;
}
|
php
|
{
"resource": ""
}
|
q239446
|
ArrayList.lastIndexOf
|
train
|
public function lastIndexOf($value){
$i = $this->count() - 1;
while($i >= 0 && $this->_Arr[$i] !== $value){
--$i;
}
return $i;
}
|
php
|
{
"resource": ""
}
|
q239447
|
ArrayList.max
|
train
|
public function max(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$max = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::greaterThan($this->_Arr[$i], $max)){
$max = $this->_Arr[$i];
}
}
return $max;
}
|
php
|
{
"resource": ""
}
|
q239448
|
ArrayList.min
|
train
|
public function min(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
$min = $this->front();
for($i = 1, $l = $this->count(); $i < $l; ++$i){
if(Number::lessThan($this->_Arr[$i], $min)){
$min = $this->_Arr[$i];
}
}
return $min;
}
|
php
|
{
"resource": ""
}
|
q239449
|
ArrayList.popBack
|
train
|
public function popBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_pop($this->_Arr);
}
|
php
|
{
"resource": ""
}
|
q239450
|
ArrayList.popFront
|
train
|
public function popFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return \array_shift($this->_Arr);
}
|
php
|
{
"resource": ""
}
|
q239451
|
ArrayList.product
|
train
|
public function product(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = \strval($this->front());
for($i = 1, $l = $this->count(); $i < $l; ++$i){
$total = Number::multiply($total, \strval($this->_Arr[$i]));
}
return $total;
}
|
php
|
{
"resource": ""
}
|
q239452
|
ArrayList.pushBack
|
train
|
public function pushBack(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge($this->_Arr, \func_get_args());
return $this;
}
|
php
|
{
"resource": ""
}
|
q239453
|
ArrayList.pushFront
|
train
|
public function pushFront(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_merge(\func_get_args(), $this->_Arr);
return $this;
}
|
php
|
{
"resource": ""
}
|
q239454
|
ArrayList.&
|
train
|
public function &random(){
if($this->isEmpty()){
throw new \UnderflowException(\get_called_class() . ' is empty');
}
return $this->_Arr[\array_rand($this->_Arr, 1)];
}
|
php
|
{
"resource": ""
}
|
q239455
|
ArrayList.readOnly
|
train
|
public function readOnly($bool = true){
$list = $this->copy(false);
$list->setReadOnly();
return $list;
}
|
php
|
{
"resource": ""
}
|
q239456
|
ArrayList.remove
|
train
|
public function remove($value) {
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(($key = \array_search($value, $this->_Arr)) !== false){
\array_splice($this->_Arr, $key, 1);
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239457
|
ArrayList.removeAt
|
train
|
public function removeAt($index) {
if($this->_ReadOnly){
throw new \RuntimeException(\get_called_class() . ' is read only');
}
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
\array_splice($this->_Arr, $index, 1);
return $this;
}
|
php
|
{
"resource": ""
}
|
q239458
|
ArrayList.resize
|
train
|
public function resize($size, $value = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(!\is_int($size)){
throw new \InvalidArgumentException('$size is not an int');
}
if($size < 0){
throw new \OutOfBoundsException('$size cannot be less than 0');
}
$len = $this->count();
if($size > $len){
$this->_Arr = \array_pad($this->_Arr, $size, $value);
}
else if($size < $len){
$this->_Arr = \array_slice($this->_Arr, 0, $size, false);
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239459
|
ArrayList.reverse
|
train
|
public function reverse(){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
$this->_Arr = \array_reverse($this->_Arr);
return $this;
}
|
php
|
{
"resource": ""
}
|
q239460
|
ArrayList.sentinelSearch
|
train
|
public function sentinelSearch($value){
$l = $this->count();
$arr = $this->_Arr;
$arr[$l] = $value;
$i = 0;
while($arr[$i] !== $value){
++$i;
}
return $i !== $l ? $i : static::NO_INDEX;
}
|
php
|
{
"resource": ""
}
|
q239461
|
ArrayList.slice
|
train
|
public function slice($index, $count = null){
if(!$this->offsetExists($index)){
throw new \OutOfRangeException('$index is invalid');
}
$arr = \array_slice($this->_Arr, $index, $count);
return new static($arr);
}
|
php
|
{
"resource": ""
}
|
q239462
|
ArrayList.sort
|
train
|
public function sort(\Closure $compare = null){
if($this->_ReadOnly){
throw new ReadOnlyException(\get_called_class() . ' is read only');
}
if(\is_callable($compare)){
\usort($this->_Arr, $compare);
}
else{
\sort($this->_Arr);
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q239463
|
ArrayList.sum
|
train
|
public function sum(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$total = '0';
foreach($this->_Arr as $item){
$total = Number::add($total, \strval($item));
}
return $total;
}
|
php
|
{
"resource": ""
}
|
q239464
|
ArrayList.stdDev
|
train
|
public function stdDev(){
Number::setScale(static::NUMERIC_FUNCTIONS_SCALE);
$mean = $this->average();
$squares = new static();
foreach($this->_Arr as $num){
$squares->add(Number::pow(Number::sub(\strval($num), $mean), '2'));
}
return Number::sqrt($squares->average());
}
|
php
|
{
"resource": ""
}
|
q239465
|
ArrayList.unique
|
train
|
public function unique(\Closure $compare = null){
if(\is_callable($compare)){
$arr = new static();
$this->each(function($outerItem) use (&$arr, $compare){
if(!$arr->some(function($cmpItem) use ($outerItem, $compare){
return $compare($outerItem, $cmpItem);
})){
$arr->_Arr[] = $outerItem;
}
});
return $arr;
}
else{
return new static(\array_values(\array_unique(
$this->_Arr, \SORT_REGULAR)));
}
}
|
php
|
{
"resource": ""
}
|
q239466
|
MethodService.call
|
train
|
public function call(MethodArgumentDocument $methodArgument)
{
$serviceName = $methodArgument->getMethod()->getService()->getServiceName();
$service = $this->container->get($serviceName);
if (null === $service) {
throw new UndefinedServiceException(sprintf('"%s" is not a service', $serviceName));
}
$methodName = $methodArgument->getMethod()->getName();
try {
$r = new \ReflectionMethod($service, $methodName);
} catch (\ReflectionException $e) {
throw new BadMethodCallException(sprintf('"%s" is not a method in %s', $methodName, $serviceName));
}
$methodArguments = $methodArgument->getArguments();
$numberOfArgs = $methodArguments->count();
$minArgs = $r->getNumberOfRequiredParameters();
$maxArgs = $r->getNumberOfParameters();
if ($numberOfArgs < $minArgs || $numberOfArgs > $maxArgs) {
$range = $minArgs === $maxArgs ? $minArgs : "$minArgs-$maxArgs";
throw new WrongNumberOfArgumentsException(
sprintf('Method "%s" in %s expects %s arguments, got %d', $methodName, $serviceName, $range, $numberOfArgs)
);
}
return $service->$methodName(...$this->buildArgumentArray($r->getParameters(), $methodArguments));
}
|
php
|
{
"resource": ""
}
|
q239467
|
SentryAuthenticationHelper.checkProfileEditPermission
|
train
|
public function checkProfileEditPermission($user_id) {
$current_user_id = App::make('sentry')->getUser()->id;
// edit his profile
if ($user_id == $current_user_id) {
return true;
}
// has special permission to edit other user profiles
$edit_perm = Config::get('authentication::permissions.edit_profile');
if ($this->hasPermission($edit_perm)) {
return true;
}
return false;
}
|
php
|
{
"resource": ""
}
|
q239468
|
SentryAuthenticationHelper.getNotificationRegistrationUsersEmail
|
train
|
public function getNotificationRegistrationUsersEmail() {
$group_name = Config::get('authentication::permissions.profile_notification_group');
$user_r = App::make('user_repository');
$users = $user_r->findFromGroupName($group_name)->lists('email');
return $users;
}
|
php
|
{
"resource": ""
}
|
q239469
|
TemplatingModule.addTemplatingEngineClass
|
train
|
public function addTemplatingEngineClass(array &$globalConfig, string $templateEngineClass) {
$globalConfig[$this->getModuleKey()][self::CONFIG_ENGINES][] = $templateEngineClass;
}
|
php
|
{
"resource": ""
}
|
q239470
|
TemplatingModule.configureDependencyInjection
|
train
|
public function configureDependencyInjection(DependencyInjectionContainer $dic,
array $moduleConfig,
array $globalConfig) {
/**
* @var TemplateEngine[] $engines
*/
$engines = [];
if (empty($moduleConfig[self::CONFIG_ENGINES])) {
throw new ConfigurationException('The templating module itself was loaded, but there is no module ' .
' for the actual template engine present. Did you forget to load your templating module?');
}
//Create the instances of the template engine to be used with the TemplateRenderingChain
foreach ($moduleConfig[self::CONFIG_ENGINES] as $engineClass) {
$engines[] = $dic->make($engineClass);
}
if (isset($moduleConfig[self::CONFIG_FILTERS])) {
foreach ($moduleConfig[self::CONFIG_FILTERS] as $filterClass) {
$filterInstance = $dic->make($filterClass);
if ($filterInstance instanceof TemplateFilter) {
foreach ($engines as $engine) {
$engine->registerFilter($filterInstance);
}
} else {
throw new ConfigurationException($filterClass . ' does not implement ' . TemplateFilter::class);
}
}
}
if (isset($moduleConfig[self::CONFIG_FUNCTIONS])) {
foreach ($moduleConfig[self::CONFIG_FUNCTIONS] as $functionClass) {
$functionInstance = $dic->make($functionClass);
if ($functionInstance instanceof TemplateFunction) {
foreach ($engines as $engine) {
$engine->registerFunction($functionInstance);
}
} else {
throw new ConfigurationException($functionClass . ' does not implement ' . TemplateFunction::class);
}
}
}
$dic->setClassParameters(TemplateRenderingChain::class, ['templateEngines' => $engines]);
}
|
php
|
{
"resource": ""
}
|
q239471
|
Serializer.serializeObject
|
train
|
private function serializeObject($object, string $className = null)
{
if (is_null($className)) {
$index = array_search($object, $this->references, true);
if ($index !== false) {
$this->referencesUsed[] = $index;
return ['@ref' => $index];
}
$this->references[] = $object;
}
$data = ['@type' => get_class($object)];
$reflectionClass = new \ReflectionClass($className ? $className : $object);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$parentData = $this->serializeObject($object, $parent->getName());
if (count($parentData) > 0) {
$data = array_merge($data, $parentData);
}
}
// current $object
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
$value = $property->getValue($object);
$name = $property->getName();
// for parent class, don't reserialize public & protected properties
if (isset($data[$name])) {
continue;
}
// optimization: only save value if not the default value
$defaults = $reflectionClass->getDefaultProperties();
if (array_key_exists($name, $defaults) && $defaults[$name] === $value) {
continue;
}
$this->serializeValue($name, $value, $data);
}
// ugly hack for public undeclared properties and
// for internal object like datetime that can't be accessed by reflection
// @see http://news.php.net/php.internals/93826%20view%20original
if (!$className) {
foreach (get_object_vars($object) as $key => $value) {
if (!isset($data[$key])) {
$this->serializeValue($key, $value, $data);
}
}
}
return $data;
}
|
php
|
{
"resource": ""
}
|
q239472
|
Serializer.unserializeObject
|
train
|
private function unserializeObject($object, &$data, string $className = null) : array
{
$reflectionClass = new \ReflectionClass($className ? $className : $object);
unset($data['@type']);
// parent class
$parent = $reflectionClass->getParentClass();
if ($parent) {
$this->unserializeObject($object, $data, $parent->getName());
}
foreach ($reflectionClass->getProperties() as $property) {
$name = $property->getName();
if (array_key_exists($name, $data)) {
$currentValue = $data[$name];
if (isset($data[$name]['@ref'])) {
$currentValue = $this->references[$data[$name]['@ref']];
} elseif (isset($data[$name]['@type'])) {
$reflection = new \ReflectionClass($data[$name]['@type']);
$parent = $reflection;
$internal = false;
while ($parent !== false) {
$internal = $parent->isInternal() ? true : $internal;
$parent = $parent->getParentClass();
}
if ($internal) {
$currentData = $data[$name];
$currentType = $data[$name]['@type'];
unset($currentData['@type']);
$serialize = preg_replace(
'`^a:`',
'O:' . strlen($currentType) . ':"' . $currentType . '":',
serialize($currentData)
);
$currentValue = unserialize($serialize);
} else {
$currentValue = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue, $data[$name]);
}
} elseif (is_array($currentValue)) {
$currentValue = [];
foreach ($data[$name] as $key => $value) {
if (isset($value['@type'])) {
$reflection = new \ReflectionClass($value['@type']);
$currentValue[$key] = $reflection->newInstanceWithoutConstructor();
$this->unserializeObject($currentValue[$key], $value);
} else {
$currentValue[$key] = $value;
}
}
}
$property->setAccessible(true);
$property->setValue($object, $currentValue);
unset($data[$name]);
}
}
return $data;
}
|
php
|
{
"resource": ""
}
|
q239473
|
EarthIT_CMIPREST_ResultAssembler_JAOResultAssembler._q45
|
train
|
protected function _q45( EarthIT_Schema_ResourceClass $rc, array $items ) {
$restObjects = array();
foreach( $items as $item ) {
$restObjects[] = $this->internalObjectToJao($rc, $item);
}
return $restObjects;
}
|
php
|
{
"resource": ""
}
|
q239474
|
ResourceFactory.newSimpleOutput
|
train
|
public function newSimpleOutput()
{
$config = $this->config->getCurrentResourceConfiguration();
return new SimpleOutput(
$this->newSerializer($config),
$this->newResource($config)
);
}
|
php
|
{
"resource": ""
}
|
q239475
|
ResourceFactory.newSlimOutput
|
train
|
public function newSlimOutput(Request $request, Response $response)
{
$config = $this->config->getCurrentResourceConfiguration();
return new SlimOutput(
$request,
$response,
$this->newSerializer($config),
$this->newResource($config)
);
}
|
php
|
{
"resource": ""
}
|
q239476
|
ResourceFactory.generateSlimRoutes
|
train
|
public function generateSlimRoutes(Slim $slim)
{
// if we are not on a resources's route, then dont generate any routes
if (!$this->config->getCurrentResourceConfiguration()) {
return;
}
$output = $this->newSlimOutput($slim->request, $slim->response);
$generator = new SlimRouteGenerator($slim, $output, $this->config);
$generator->generateRoutes();
}
|
php
|
{
"resource": ""
}
|
q239477
|
ResourceFactory.resourceFor
|
train
|
public function resourceFor($resourceName)
{
$resourceConfig = $this->config->resourceConfigurationFor($resourceName);
return $this->newResource($resourceConfig);
}
|
php
|
{
"resource": ""
}
|
q239478
|
ResourceFactory.newRepository
|
train
|
protected function newRepository(ResourceConfiguration $config)
{
if ($this->database instanceof EntityManager) {
return $this->newDoctrineRepository($this->database, $config->getEntityClass(), $config->getParent());
} elseif ($this->database instanceof PDO) {
return $this->newPdoRepository($this->database, $config->getResource(), $config->getParent());
}
throw new \Exception("Couldn't determine database connection type.");
}
|
php
|
{
"resource": ""
}
|
q239479
|
ResourceFactory.newSerializer
|
train
|
protected function newSerializer(ResourceConfiguration $config)
{
return new JMSSerializer(
SerializerBuilder::create()->build(),
new SerializationContext,
new JMSPropertyExcluder($config->getExcludedProperties())
);
}
|
php
|
{
"resource": ""
}
|
q239480
|
ResourceFactory.newResource
|
train
|
protected function newResource(ResourceConfiguration $config)
{
return new Resource(
$this->newRepository($config),
$this->newValidator($config),
$this->newSecurity(),
$this,
$config
);
}
|
php
|
{
"resource": ""
}
|
q239481
|
ResourceFactory.newValidator
|
train
|
protected function newValidator(ResourceConfiguration $config)
{
$class = $config->getValidatorClass();
return $config->isUsingYamlValidation() ?
new YamlResourceValidator($config->getYamlValidation()) : new $class();
}
|
php
|
{
"resource": ""
}
|
q239482
|
ResourceFactory.newSecurity
|
train
|
protected function newSecurity()
{
$config = $this->config->getCurrentResourceConfiguration();
return new Security(
new SimpleAuthenticationBouncer($config),
new SimpleRoleBouncer($config),
new ParentBouncer($config)
);
}
|
php
|
{
"resource": ""
}
|
q239483
|
HttpClient.callApi
|
train
|
public function callApi(Message $req, $method, $uri, $handler)
{
// check handler, php before 5.4 doesn't support Type Hinting of callable
if (!is_callable($handler)) {
throw new GeneralException("Can not find response handler.");
}
$data = [
'json' => (object) $req->to_array(),
'http_errors' => false,
];
$response = $this->request($method, $uri, $data);
$rawContent = $response->getBody()->getContents();
$content = json_decode($rawContent, true);
if (!$content) {
throw new GeneralException("Response is not json data: " . $rawContent);
}
$statusCode = $response->getStatusCode();
switch ($statusCode) {
case 200:
// happy path
if (isset($content)) {
return $handler($content, "", "");
} else {
throw new GeneralException("Cannot find response body: " . $rawContent);
}
break;
case 400:
// biz error
if (isset($content)) {
return $handler("", $content, "");
}
throw new GeneralException("Cannot find Biz Error body: " . $rawContent);
break;
case 420:
// common error
if (isset($content)) {
return $handler("", "", $content);
}
throw new GeneralException("Cannot find Common Error body: " . $rawContent);
break;
case 500:
// internal error
throw new InternalServerErrorException("Internal server error: " . $rawContent);
break;
}
}
|
php
|
{
"resource": ""
}
|
q239484
|
AbstractRepository.diff
|
train
|
public function diff(Repository $otherRepository)
{
$diffRepository = new Memory();
foreach ($this->unitOfWorkStore as $unitOfWork) {
if (!$otherRepository->contains($unitOfWork)) {
$diffRepository->add($unitOfWork);
}
}
$diffRepository->sort();
return $diffRepository;
}
|
php
|
{
"resource": ""
}
|
q239485
|
AbstractRepository.find
|
train
|
public function find(Uid $uniqueId)
{
if (!array_key_exists((string) $uniqueId, $this->unitOfWorkStore)) {
throw new UnitNotFoundException();
}
return $this->unitOfWorkStore[(string) $uniqueId];
}
|
php
|
{
"resource": ""
}
|
q239486
|
AbstractRepository.add
|
train
|
public function add(UnitOfWork $unitOfWork)
{
if ($this->contains($unitOfWork)) {
throw new UnitIsAlreadyPresentException();
}
$this->unitOfWorkStore[$unitOfWork->getUniqueId()] = $unitOfWork;
}
|
php
|
{
"resource": ""
}
|
q239487
|
AbstractRepository.replace
|
train
|
public function replace(UnitOfWork $unitOfWork)
{
if (!$this->contains($unitOfWork)) {
throw new UnitNotPresentException;
}
$this->unitOfWorkStore[$unitOfWork->getUniqueId()] = $unitOfWork;
}
|
php
|
{
"resource": ""
}
|
q239488
|
ProtectedMembersAccessor.getReflectionMethod
|
train
|
protected function getReflectionMethod($class, $method)
{
if (!isset($this->methodReflectors[$class])) {
$this->methodReflectors[$class] = [];
}
if (!isset($this->methodReflectors[$class][$method])) {
$this->methodReflectors[$class][$method] = new \ReflectionMethod($class, $method);
}
return $this->methodReflectors[$class][$method];
}
|
php
|
{
"resource": ""
}
|
q239489
|
ProtectedMembersAccessor.getReflectionProperty
|
train
|
protected function getReflectionProperty($class, $property)
{
if (!isset($this->propertyReflectors[$class])) {
$this->propertyReflectors[$class] = [];
}
if (!isset($this->propertyReflectors[$class][$property])) {
$this->propertyReflectors[$class][$property] = new \ReflectionProperty($class, $property);
}
return $this->propertyReflectors[$class][$property];
}
|
php
|
{
"resource": ""
}
|
q239490
|
ProtectedMembersAccessor.getProtectedMethod
|
train
|
public function getProtectedMethod(...$params)
{
if (is_string($params[0])) {
list($className, $object, $name) = $params;
} elseif (is_object($params[0])) {
list($object, $name) = $params;
$className = get_class($object);
}
/** @var string $className */
/** @var object $object */
/** @var string $name */
$this->checkOnObject($object);
$this->checkOnMemberName($name);
$reflector = $this->getReflectionMethod($className, $name);
return $reflector->getClosure($object);
}
|
php
|
{
"resource": ""
}
|
q239491
|
ProtectedMembersAccessor.getProtectedProperty
|
train
|
public function getProtectedProperty(...$params)
{
if (is_string($params[0])) {
list($className, $object, $name) = $params;
} elseif (is_object($params[0])) {
list($object, $name) = $params;
$className = get_class($object);
}
/** @var string $className */
/** @var object $object */
/** @var string $name */
$this->checkOnObject($object);
$this->checkOnMemberName($name);
$reflector = new \ReflectionProperty($className, $name);
$isProtected = $reflector->isProtected() || $reflector->isPrivate();
if ($isProtected) {
$reflector->setAccessible(true);
}
$value = $reflector->getValue($object);
if ($isProtected) {
$reflector->setAccessible(false);
}
return $value;
}
|
php
|
{
"resource": ""
}
|
q239492
|
ProtectedMembersAccessor.setProtectedProperty
|
train
|
public function setProtectedProperty(...$params)
{
if (is_string($params[0])) {
list($className, $object, $name, $value) = $params;
} elseif (is_object($params[0])) {
list($object, $name, $value) = $params;
$className = get_class($object);
}
/** @var string $className */
/** @var object $object */
/** @var string $name */
/** @var mixed $value */
$this->checkOnObject($object);
$this->checkOnMemberName($name);
$reflector = $this->getReflectionProperty($className, $name);
$isProtected = $reflector->isProtected() || $reflector->isPrivate();
if ($isProtected) {
$reflector->setAccessible(true);
}
$reflector->setValue($object, $value);
if ($isProtected) {
$reflector->setAccessible(false);
}
}
|
php
|
{
"resource": ""
}
|
q239493
|
VerifyCsrfToken.getTokenString
|
train
|
protected function getTokenString()
{
$result = Request::post('_token', '');
if ('' == $result) {
$result = Request::get('_token', '');
}
if ('' == $result) {
$result = isset($_SERVER['X-CSRF-TOKEN']) ? $_SERVER['X-CSRF-TOKEN'] : '';
}
return $result;
}
|
php
|
{
"resource": ""
}
|
q239494
|
ArrayUtils.removeKeysFromMultiArray
|
train
|
public static function removeKeysFromMultiArray(&$array, $keys)
{
foreach ($array as $key => &$value) {
if (is_array($value)) {
self::traverseArray($value, $keys);
} else {
if (in_array($key, $keys) || '' == $value) {
unset($array[$key]);
}
}
}
return $array;
}
|
php
|
{
"resource": ""
}
|
q239495
|
ArrayUtils.listToMultiArray
|
train
|
public static function listToMultiArray($array)
{
$nested = [];
$depths = [];
foreach ($array as $key => $arr) {
if ($arr['depth'] == 0) {
$nested[$key] = $arr;
} else {
$parent =& $nested;
for ($i = 1; $i <= ($arr['depth']); $i++) {
$parent =& $parent[$depths[$i]];
}
$parent['pages'][$key] = $arr;
}
$depths[$arr['depth'] + 1] = $key;
}
return $nested;
}
|
php
|
{
"resource": ""
}
|
q239496
|
UploaderS3.upload
|
train
|
public function upload($filePath, $contentType = 'text/plain')
{
$s3FileName = $this->getFilePathAndUniquePrefix() . basename($filePath);
list($bucket, $prefix) = explode('/', $this->s3path, 2);
$this->s3client->putObject([
'Bucket' => $bucket,
'Key' => (empty($prefix) ? '' : (trim($prefix, '/') . '/')) . $s3FileName,
'ContentType' => $contentType,
'ACL' => 'private',
'ServerSideEncryption' => 'AES256',
'SourceFile' => $filePath,
]);
return $this->withUrlPrefix($s3FileName);
}
|
php
|
{
"resource": ""
}
|
q239497
|
UploaderS3.uploadString
|
train
|
public function uploadString($name, $content, $contentType = 'text/plain')
{
$s3FileName = $this->getFilePathAndUniquePrefix() . $name;
list($bucket, $prefix) = explode('/', $this->s3path, 2);
$this->s3client->putObject([
'Bucket' => $bucket,
'Key' => (empty($prefix) ? '' : (trim($prefix, '/') . '/')) . $s3FileName,
'ContentType' => $contentType,
'ACL' => 'private',
'ServerSideEncryption' => 'AES256',
'Body' => $content,
]);
return $this->withUrlPrefix($s3FileName);
}
|
php
|
{
"resource": ""
}
|
q239498
|
Factory.create
|
train
|
public static function create(ProviderRepository $providerRepository = null)
{
$container = new Container(
$providerRepository
);
if (!$container->isProvided(AnnotationServiceProvider::class)) {
$container->addProvider(AnnotationServiceProvider::class);
}
$container->add(
Container::class,
function () use ($container) {
return $container;
}
)->alias(ContainerInterface::class);
return $container;
}
|
php
|
{
"resource": ""
}
|
q239499
|
TCP.connecting
|
train
|
private function connecting() : void
{
$this->connected = false;
$this->closing
? $this->closed()->resolve()
: $this->client = Socket::connect($this->endpoint, $this->events)
;
}
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.