_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q8700 | ObjectMatcher.throwsException | train | public function throwsException($exceptionClassOrObject): ObjectExceptionMatcher {
$class = is_string($exceptionClassOrObject) ? $exceptionClassOrObject : get_class($exceptionClassOrObject);
$matcher = $this->createInternalMatcherWithDescription(ObjectExceptionMatcher::class, 'I see that exception "' . $class . '"');
$matcher->exceptionClassOrObject = $exceptionClassOrObject;
return $matcher;
} | php | {
"resource": ""
} |
q8701 | EndpointConfiguration.getValue | train | public function getValue($endpoint, $key)
{
if (isset($this->endpoints['endpoints'][$endpoint])
&& isset($this->endpoints['endpoints'][$endpoint][$key])
) {
return $this->endpoints['endpoints'][$endpoint][$key];
}
if (isset($this->endpoints[$key])) {
return $this->endpoints[$key];
}
return null;
} | php | {
"resource": ""
} |
q8702 | Location.addPath | train | public function addPath($value)
{
if ($this->path === null) {
$this->path = new \Protobuf\ScalarCollection();
}
$this->path->add($value);
} | php | {
"resource": ""
} |
q8703 | Location.addSpan | train | public function addSpan($value)
{
if ($this->span === null) {
$this->span = new \Protobuf\ScalarCollection();
}
$this->span->add($value);
} | php | {
"resource": ""
} |
q8704 | Location.addLeadingDetachedComments | train | public function addLeadingDetachedComments($value)
{
if ($this->leading_detached_comments === null) {
$this->leading_detached_comments = new \Protobuf\ScalarCollection();
}
$this->leading_detached_comments->add($value);
} | php | {
"resource": ""
} |
q8705 | Revisionable.getOldAttributes | train | public function getOldAttributes()
{
$attributes = $this->prepareAttributes($this->original);
$attributes = $this->getRevisionableItems($attributes);
return $attributes;
} | php | {
"resource": ""
} |
q8706 | Revisionable.getNewAttributes | train | public function getNewAttributes()
{
$attributes = $this->prepareAttributes($this->attributes);
$attributes = $this->getRevisionableItems($attributes);
return $attributes;
} | php | {
"resource": ""
} |
q8707 | Invoice.generateSecurityCode | train | public function generateSecurityCode()
{
$result = $this->getCertificatePrivateKey();
$result .= $this->getOib();
$result .= $this->getDateTime();
$result .= $this->getInvoiceNumber()->getInvoiceNumber();
$result .= $this->getInvoiceNumber()->getBusinessLocationCode();
$result .= $this->getInvoiceNumber()->getPaymentDeviceCode();
$result .= $this->getTotalValue();
$this->setSecurityCode(md5($result));
return $this;
} | php | {
"resource": ""
} |
q8708 | DoctrineServiceProvider.setUpEntityManagers | train | protected function setUpEntityManagers()
{
$managers = [];
$connections = [];
foreach ($this->config['managers'] as $manager => $settings) {
$managerName = IlluminateRegistry::getManagerNamePrefix() . $manager;
$connectionName = IlluminateRegistry::getConnectionNamePrefix() . $manager;
// Bind manager
$this->app->singleton($managerName, function () use ($settings) {
$manager = EntityManager::create(
ConnectionManager::resolve(array_get($settings, 'connection')),
MetaDataManager::resolve(array_get($settings, 'meta'))
);
$configuration = $manager->getConfiguration();
// Listeners
if (isset($settings['events']['listeners'])) {
foreach ($settings['events']['listeners'] as $event => $listener) {
$manager->getEventManager()->addEventListener($event, $listener);
}
}
// Subscribers
if (isset($settings['events']['subscribers'])) {
foreach ($settings['events']['subscribers'] as $subscriber) {
$manager->getEventManager()->addEventSubscriber($subscriber);
}
}
// Filters
if (isset($settings['filters'])) {
foreach ($settings['filters'] as $name => $filter) {
$configuration->getMetadataDriverImpl()->addFilter($name, $filter);
$manager->getFilters()->enable($name);
}
}
// Paths
$configuration->getMetadataDriverImpl()->addPaths(
array_get($settings, 'paths', [])
);
// Repository
$configuration->setDefaultRepositoryClassName(
array_get($settings, 'repository', \Doctrine\ORM\EntityRepository::class)
);
$configuration->setAutoGenerateProxyClasses(
array_get($settings, 'proxies.auto_generate', false)
);
if ($namespace = array_get($settings, 'proxies.namespace', false)) {
$configuration->setProxyNamespace($namespace);
}
return $manager;
});
// Bind connection
$this->app->singleton($connectionName, function ($app) use ($manager) {
$app->make(IlluminateRegistry::getManagerNamePrefix() . $manager)->getConnection();
});
$managers[$manager] = $manager;
$connections[$manager] = $manager;
}
return [$managers, $connections];
} | php | {
"resource": ""
} |
q8709 | DoctrineServiceProvider.registerEntityManager | train | protected function registerEntityManager()
{
// Bind the default Entity Manager
$this->app->singleton('em', function ($app) {
return $app->make(ManagerRegistry::class)->getManager();
});
$this->app->alias('em', EntityManager::class);
$this->app->alias('em', EntityManagerInterface::class);
} | php | {
"resource": ""
} |
q8710 | DoctrineServiceProvider.setupMetaData | train | protected function setupMetaData()
{
MetaDataManager::registerDrivers(
$this->config['meta']['drivers'],
$this->config['dev']
);
MetaDataManager::resolved(function (Configuration $configuration) {
// Debugbar
if ($this->config['debugbar'] === true) {
$debugStack = new DebugStack();
$configuration->setSQLLogger($debugStack);
$this->app['debugbar']->addCollector(
new DoctrineCollector($debugStack)
);
}
$configuration->getMetadataDriverImpl()->addPaths([
__DIR__ . '/Migrations',
__DIR__ . '/Auth/Passwords'
]);
// Automatically make table, column names, etc. like Laravel
$configuration->setNamingStrategy(
$this->app->make(LaravelNamingStrategy::class)
);
// Custom functions
$configuration->setCustomDatetimeFunctions($this->config['custom_datetime_functions']);
$configuration->setCustomNumericFunctions($this->config['custom_numeric_functions']);
$configuration->setCustomStringFunctions($this->config['custom_string_functions']);
// Second level caching
if ($this->config['cache']['second_level']) {
$configuration->setSecondLevelCacheEnabled(true);
$cacheConfig = $configuration->getSecondLevelCacheConfiguration();
$cacheConfig->setCacheFactory(
new DefaultCacheFactory(
$cacheConfig->getRegionsConfiguration(),
CacheManager::resolve(
$this->config['cache']['default']
)
)
);
}
});
} | php | {
"resource": ""
} |
q8711 | CacheManager.setup | train | public static function setup($caches, Logger $logger = null, $logLevel = null)
{
if (!is_array($caches)) {
$caches = array(self::_DEFAULT => array('backend' => $caches));
}
self::$logger = $logger;
self::$logLevel = $logLevel;
foreach ($caches as $name => $options) {
self::$caches[$name] = self::factory($options);
}
} | php | {
"resource": ""
} |
q8712 | Filters.apply | train | public function apply()
{
$filters = $this->filters;
$inputs = $this->inputs;
$assistant = $this->assistant;
if (count($filters)) {
foreach ($filters as $name => $filter) {
// Allow filter to defined as array or pipe delimited string
$rules = (is_array($filter)) ? $filter : explode('|', $filter);
// At least a rule is set and the input
// field exists.
if (count($rules) and isset($inputs[$name])) {
foreach ($rules as $rule) {
$splitAt = strpos($rule, ':');
$argument = null;
if ($splitAt) {
$argument = substr($rule, $splitAt+1);
$rule = substr($rule, 0, $splitAt);
}
$rule = strtolower($rule);
$rule = str_replace('_', ' ', $rule);
$rule = str_replace(' ', '', ucwords($rule));
$method = 'filter'.$rule;
// Check if rule is defined as a class method.
if (method_exists($this, $method)) {
$inputs[$name] = $this->$method($inputs[$name], $argument);
}
// Check if ValidatorAssistant object has the same/custom filter defined
if ( $assistant && method_exists($assistant, $method)) {
$inputs[$name] = $assistant->$method($inputs[$name], $argument);
}
}
}
}
}
return $inputs;
} | php | {
"resource": ""
} |
q8713 | Filters.filterStripTags | train | private function filterStripTags($value, $argument = null)
{
$allowedTags = array('<p>', '<a>', '<b>', '<i>', '<em>', '<strong>', '<img>', '<br>', '<ul>', '<ol>', '<li>', '<span>', '<blockquote>', '<code>', '<sub>', '<sup>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<dd>', '<dl>', '<label>');
return strip_tags($value, join(null, $allowedTags));
} | php | {
"resource": ""
} |
q8714 | Filters.filterNumberFormat | train | private function filterNumberFormat($value, $argument = null)
{
if ($argument and is_int($argument)) {
$value = number_format($value, $argument);
}
return $value;
} | php | {
"resource": ""
} |
q8715 | ValidatorManager.validate | train | public function validate($endpoint, $value, $configKey = 'upload_validators')
{
$validationConfiguration = $this->configuration->getValue($endpoint, $configKey);
foreach ((array) $validationConfiguration as $validationType => $config) {
$validator = $this->validators->getValidator($validationType);
$validator->applyValidator($value, $config);
}
} | php | {
"resource": ""
} |
q8716 | Client.start | train | public function start($browserName = null)
{
if ($this->started) {
throw new Exception\ConnectionException('Client is already started');
}
if (!$this->con->isProxyStarted()) {
throw new Exception\ConnectionException('Sahi proxy seems not running');
}
// open browser if connection uses custom SID (not defaultly autogenerated)
if (!$this->con->isCustomSidProvided()) {
if (null === $browserName) {
throw new \InvalidArgumentException('Specify browser to run in');
}
$this->con->start($browserName);
$limit = 600;
while (!$this->con->isReady()) {
usleep(100000);
if (--$limit <= 0) {
throw new Exception\ConnectionException(
'Connection time limit reached'
);
}
}
$this->browserAutoruned = true;
} elseif (!$this->con->isReady()) {
throw new Exception\ConnectionException(sprintf(
"Can not connect to Sahi session with id \"%s\".\n".
"Start Sahi session in target browser by opening:\n".
"http://sahi.example.com/_s_/dyn/Driver_start?sahisid=%s&startUrl=http://sahi.example.com/_s_/dyn/Driver_initialized",
$this->con->getSid(),
$this->con->getSid()
));
}
$this->started = true;
} | php | {
"resource": ""
} |
q8717 | Client.stop | train | public function stop()
{
if (!$this->started) {
throw new Exception\ConnectionException('Client is not started');
}
if ($this->browserAutoruned) {
$this->con->stop();
}
$this->started = false;
} | php | {
"resource": ""
} |
q8718 | Client.navigateTo | train | public function navigateTo($url, $reload = null)
{
$arguments = array(json_encode($url));
if (null !== $reload) {
$arguments[] = (bool) $reload ? 'true' : 'false';
}
$this->con->executeStep(sprintf('_sahi._navigateTo(%s)', implode(', ', $arguments)));
} | php | {
"resource": ""
} |
q8719 | Client.wait | train | public function wait($timeout, $condition)
{
$conditionResult = false;
while ($timeout > 0 && true !== $conditionResult) {
usleep(100);
$timeout -= 100;
// don't throw exceptions
try {
$conditionResult = $this->con->evaluateJavascript($condition);
} catch (\Exception $e) {
$conditionResult = false;
}
}
return (boolean) $conditionResult;
} | php | {
"resource": ""
} |
q8720 | Client.findDiv | train | public function findDiv($id = null, array $relations = array())
{
return new Accessor\DivAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8721 | Client.findImage | train | public function findImage($id = null, array $relations = array())
{
return new Accessor\ImageAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8722 | Client.findLabel | train | public function findLabel($id = null, array $relations = array())
{
return new Accessor\LabelAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8723 | Client.findLink | train | public function findLink($id = null, array $relations = array())
{
return new Accessor\LinkAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8724 | Client.findListItem | train | public function findListItem($id = null, array $relations = array())
{
return new Accessor\ListItemAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8725 | Client.findSpan | train | public function findSpan($id = null, array $relations = array())
{
return new Accessor\SpanAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8726 | Client.findButton | train | public function findButton($id = null, array $relations = array())
{
return new Accessor\Form\ButtonAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8727 | Client.findCheckbox | train | public function findCheckbox($id = null, array $relations = array())
{
return new Accessor\Form\CheckboxAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8728 | Client.findFile | train | public function findFile($id = null, array $relations = array())
{
return new Accessor\Form\FileAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8729 | Client.findHidden | train | public function findHidden($id = null, array $relations = array())
{
return new Accessor\Form\HiddenAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8730 | Client.findImageSubmitButton | train | public function findImageSubmitButton($id = null, array $relations = array())
{
return new Accessor\Form\ImageSubmitButtonAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8731 | Client.findOption | train | public function findOption($id = null, array $relations = array())
{
return new Accessor\Form\OptionAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8732 | Client.findPassword | train | public function findPassword($id = null, array $relations = array())
{
return new Accessor\Form\PasswordAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8733 | Client.findRadio | train | public function findRadio($id = null, array $relations = array())
{
return new Accessor\Form\RadioAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8734 | Client.findReset | train | public function findReset($id = null, array $relations = array())
{
return new Accessor\Form\ResetAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8735 | Client.findSelect | train | public function findSelect($id = null, array $relations = array())
{
return new Accessor\Form\SelectAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8736 | Client.findSubmit | train | public function findSubmit($id = null, array $relations = array())
{
return new Accessor\Form\SubmitAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8737 | Client.findTextarea | train | public function findTextarea($id = null, array $relations = array())
{
return new Accessor\Form\TextareaAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8738 | Client.findTextbox | train | public function findTextbox($id = null, array $relations = array())
{
return new Accessor\Form\TextboxAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8739 | Client.findCell | train | public function findCell($id = null, array $relations = array())
{
return new Accessor\Table\CellAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8740 | Client.findRow | train | public function findRow($id = null, array $relations = array())
{
return new Accessor\Table\RowAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8741 | Client.findTableHeader | train | public function findTableHeader($id = null, array $relations = array())
{
return new Accessor\Table\TableHeaderAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8742 | Client.findTable | train | public function findTable($id = null, array $relations = array())
{
return new Accessor\Table\TableAccessor($id, $relations, $this->con);
} | php | {
"resource": ""
} |
q8743 | InstallerController.store | train | public function store(Request $request, Installer $processor)
{
return $processor->store($this, $request->all());
} | php | {
"resource": ""
} |
q8744 | KeyGenerator.fromEndpoint | train | public static function fromEndpoint(Endpoint $endpoint)
{
return static::generateKey(strtolower($endpoint->getRegion()->getDomain()).$endpoint->getUrl());
} | php | {
"resource": ""
} |
q8745 | MelisFrontSearchController.addLuceneIndexAction | train | public function addLuceneIndexAction()
{
$moduleName = $this->params()->fromRoute('moduleName', null);
$pageId = $this->params()->fromRoute('pageid', null);
$excludes = $this->params()->fromRoute('expageid', null);
$status = '';
/** @var \MelisEngine\Service\MelisSearchService $searchIndex */
$searchIndex = $this->getServiceLocator()->get('MelisSearch');
if ($moduleName && $pageId) {
$tmpexPageIds = explode(';', $excludes);
$exPageIds = [];
foreach ($tmpexPageIds as $id) {
if ($id) {
$exPageIds[] = $id;
}
}
/** Checks if the site's folder is that of MelisSite or Vendor */
$moduleDirectory = null;
if (is_dir($_SERVER['DOCUMENT_ROOT'] . self::MELIS_SITES . $moduleName)) {
/** Module is located inside MelisSites folder */
$moduleDirectory = $_SERVER['DOCUMENT_ROOT'] . self::MELIS_SITES;
} elseif (is_dir($_SERVER['DOCUMENT_ROOT'] . self::VENDOR . $moduleName)) {
/** Module is located inside Vendor folder */
$moduleDirectory = $_SERVER['DOCUMENT_ROOT'] . self::VENDOR;
}
$status = $searchIndex->createIndex($moduleName, $pageId, $exPageIds, $moduleDirectory);
}
$view = new ViewModel();
$view->setTerminal(true);
$view->status = $status;
return $view;
} | php | {
"resource": ""
} |
q8746 | QueryFilter.getValue | train | public function getValue($name)
{
return (isset($this->options['params'][$name])) ? $this->options['params'][$name] : null;
} | php | {
"resource": ""
} |
q8747 | QueryFilter.run | train | public function run($query)
{
$options = $this->options;
if ($this->hasActiveFilters()) {
foreach ($options['params'] as $param => $value) {
$query->where(
function ($query) use ($options, $param, $value) {
$options['filters'][$param]($query, $value);
}
);
}
}
//Setting data for filter form
$this->options['params'] = $options['params'];
if ($options['save']) {
$_SESSION[$options['save']] = $options['params'];
}
return $query;
} | php | {
"resource": ""
} |
q8748 | AngelaControl.start | train | public function start() : int
{
$pathToServerScript = $this->config['server_path'];
if (!file_exists($pathToServerScript)) {
throw new ControlException('Server script not found. Check server_path in your config file.');
}
// check if process is already running:
$serverPid = $this->getServerPid();
if ($serverPid !== 0) {
return $serverPid;
}
// startup server:
$phpPath = $this->config['php_path'];
$startupCommand = escapeshellcmd($phpPath . ' ' . $pathToServerScript) . ' > /dev/null 2>&1 &';
exec($startupCommand);
// return process id:
$pid = $this->getServerPid();
if (empty($pid)) {
throw new ControlException('Could not start server. (Empty Pid)');
}
return $pid;
} | php | {
"resource": ""
} |
q8749 | AngelaControl.stop | train | public function stop() : bool
{
$serverPid = $this->getServerPid();
if ($serverPid === 0) {
return true;
}
$response = $this->sendCommand('stop');
if ($response !== 'ok') {
throw new ControlException('Shutdown failed.');
}
return true;
} | php | {
"resource": ""
} |
q8750 | AngelaControl.restart | train | public function restart() : int
{
$pid = $this->getServerPid();
if (empty($pid)) {
return $this->start();
}
$stopped = $this->stop();
if ($stopped !== true) {
throw new ControlException('Error while stopping current Angela process.');
}
return $this->start();
} | php | {
"resource": ""
} |
q8751 | AngelaControl.status | train | public function status() : array
{
$serverPid = $this->getServerPid();
if (empty($serverPid)) {
throw new ControlException('Angela not currently running.');
}
$response = $this->sendCommand('status');
if (empty($response)) {
throw new ControlException('Error fetching status. (Incorrect response)');
}
return json_decode($response, true);
} | php | {
"resource": ""
} |
q8752 | AngelaControl.flushQueue | train | public function flushQueue() : bool
{
$serverPid = $this->getServerPid();
if (empty($serverPid)) {
throw new ControlException('Angela not currently running.');
}
$response = $this->sendCommand('flush_queue');
if ($response !== 'ok') {
throw new ControlException('Error flushing queue. (Incorrect response)');
}
return true;
} | php | {
"resource": ""
} |
q8753 | AngelaControl.kill | train | public function kill() : bool
{
// kill server process:
$serverPid = $this->getServerPid();
if (!empty($serverPid)) {
$this->killProcessById($serverPid);
}
// kill worker processes:
$workerPids = [];
foreach ($this->config['pool'] as $poolName => $poolConfig) {
$pids = $this->getPidsByPath($poolConfig['worker_file']);
if (empty($pids)) {
continue;
}
$workerPids = array_merge($workerPids, $pids);
}
if (empty($workerPids)) {
return true;
}
foreach ($workerPids as $pid) {
$this->killProcessById($pid);
}
return true;
} | php | {
"resource": ""
} |
q8754 | AngelaControl.getPidByPath | train | protected function getPidByPath(string $path) : int
{
$procInfo = [];
$cliOutput = [];
exec('ps x | grep ' . $path, $cliOutput);
foreach ($cliOutput as $line) {
$line = trim($line);
if (empty($line)) {
continue;
}
if (strpos($line, 'grep') !== false) {
continue;
}
$procInfo = preg_split('#\s+#', $line);
break;
}
if (empty($procInfo)) {
return 0;
}
return (int)$procInfo[0];
} | php | {
"resource": ""
} |
q8755 | AngelaControl.getPidsByPath | train | protected function getPidsByPath(string $path) : array
{
$pids = [];
$cliOutput = [];
exec('ps x | grep ' . $path, $cliOutput);
foreach ($cliOutput as $line) {
$line = trim($line);
if (empty($line)) {
continue;
}
if (strpos($line, 'grep') !== false) {
continue;
}
$procInfo = preg_split('#\s+#', $line);
array_push($pids, (int)$procInfo[0]);
}
return $pids;
} | php | {
"resource": ""
} |
q8756 | AngelaControl.sendCommand | train | protected function sendCommand(string $command) : string
{
try {
$client = new Client;
$client->addServer($this->config['sockets']['client']);
$response = $client->sendCommand($command);
$client->close();
return $response;
} catch (ClientException $e) {
return 'error';
}
} | php | {
"resource": ""
} |
q8757 | OperationArguments.checkType | train | protected function checkType($value, $type, $nullable = false)
{
if (gettype($value) === $type) {
return true;
}
return $nullable && null === $value;
} | php | {
"resource": ""
} |
q8758 | OperationArguments.validateArgument | train | public function validateArgument($argname, $value, $type, $nullable = false)
{
if (!$this->checkType($value, $type, $nullable)) {
throw new OperationArgumentException(sprintf(
'Method %s() expects $%s to be %s, %s given.',
$this->operation,
$argname,
$type,
gettype($value)
));
}
} | php | {
"resource": ""
} |
q8759 | OperationArguments.validateArrayArgument | train | public function validateArrayArgument($argname, array $value, $type, $nullable = false)
{
foreach ($value as $element) {
if (!$this->checkType($element, $type, $nullable)) {
throw new OperationArgumentException(sprintf(
'Method %s() expects all of $%s elements to be %s, found %s.',
$this->operation,
$argname,
$type,
gettype($element)
));
}
}
} | php | {
"resource": ""
} |
q8760 | OperationArguments.& | train | public function & get($argname)
{
if ($this->has($argname)) {
return $this->values[$argname];
}
throw new OutOfRangeException(sprintf('Argument %s does not exist.', $argname));
} | php | {
"resource": ""
} |
q8761 | OperationArguments.setValue | train | public function setValue(& $value)
{
if ('append' == $this->operation) {
$this->validateArgument('value', $value, 'string');
}
return $this->set('value', $value);
} | php | {
"resource": ""
} |
q8762 | DoctrineTokenRepository.createNewToken | train | protected function createNewToken(CanResetPassword $user)
{
$email = $user->getEmailForPasswordReset();
$value = str_shuffle(sha1($email . spl_object_hash($this) . microtime(true)));
return hash_hmac('sha1', $value, $this->hashKey);
} | php | {
"resource": ""
} |
q8763 | DoctrineTokenRepository.deleteExpired | train | public function deleteExpired()
{
$expired = Carbon::now()->subSeconds($this->expires);
$this->makeDelete()
->where('o.createdAt < :expired')
->setParameter('expired', $expired)
->getQuery()
->execute();
} | php | {
"resource": ""
} |
q8764 | View.cell | train | public function cell($cell, array $data = [], array $options = [])
{
$parts = explode('::', $cell);
if (count($parts) === 2) {
list($cell, $action) = [$parts[0], $parts[1]];
} else {
list($cell, $action) = [$parts[0], 'display'];
}
$className = Application::className($cell, 'View/' . self::VIEW_TYPE_CELL);
$class = new $className($data);
return $class->{$action}($options);
} | php | {
"resource": ""
} |
q8765 | View.element | train | public function element($name, array $data = [])
{
$view = new View();
$view->type(self::VIEW_TYPE_ELEMENT);
$view->set(array_merge($this->viewVars, $data));
return $view->render($name);
} | php | {
"resource": ""
} |
q8766 | View.viewContent | train | protected function viewContent($type, $view)
{
$ext = pathinfo($view, PATHINFO_EXTENSION);
$view = ($ext === '') ? $view.'.php' : $view;
foreach ($this->paths as $path) {
$path .= $type . DIRECTORY_SEPARATOR;
if ($this->context()
&&
file_exists($path . trim($this->context(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $view)
) {
$viewPath = $path . trim($this->context(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $view;
break;
}
if (file_exists($path . $view)) {
$viewPath = $path . $view;
break;
}
}
if (!isset($viewPath)) {
throw new \RuntimeException('Unable to find the ' . $view);
}
ob_start();
include($viewPath);
$content = ob_get_contents();
ob_end_clean();
return $content;
} | php | {
"resource": ""
} |
q8767 | MediaGalleryUpdateObserver.initializeProductMediaGallery | train | protected function initializeProductMediaGallery(array $attr)
{
// load the value and the attribute ID
$value = $attr[MemberNames::VALUE];
$attributeId = $attr[MemberNames::ATTRIBUTE_ID];
// query whether the product media gallery entity already exists or not
if ($entity = $this->loadProductMediaGallery($attributeId, $value)) {
return $this->mergeEntity($entity, $attr);
}
// simply return the attributes
return $attr;
} | php | {
"resource": ""
} |
q8768 | MediaGalleryUpdateObserver.initializeProductMediaGalleryValueToEntity | train | protected function initializeProductMediaGalleryValueToEntity(array $attr)
{
// load the value/entity ID
$valueId = $attr[MemberNames::VALUE_ID];
$entityId = $attr[MemberNames::ENTITY_ID];
// query whether the product media gallery value to entity entity already exists or not
if ($this->loadProductMediaGalleryValueToEntity($valueId, $entityId)) {
return;
}
// simply return the attributes
return $attr;
} | php | {
"resource": ""
} |
q8769 | Authentication.parseAuthenticationConfiguration | train | protected function parseAuthenticationConfiguration(array $auth): array
{
$driver = $auth['defaults']['guard'] ?? null;
$guard = $auth['guards'][$driver] ?? [
'driver' => 'session',
'provider' => 'users',
];
$provider = $auth['providers'][$guard['provider']] ?? [
'driver' => 'eloquent',
'model' => User::class,
];
return \compact('guard', 'provider');
} | php | {
"resource": ""
} |
q8770 | FileOptions.setOptimizeFor | train | public function setOptimizeFor(\google\protobuf\FileOptions\OptimizeMode $value = null)
{
$this->optimize_for = $value;
} | php | {
"resource": ""
} |
q8771 | TextFilter.doFilter | train | public function doFilter($text, $filters)
{
// Define all valid filters with their callback function.
$callbacks = [
'bbcode' => 'bbcode2html',
'clickable' => 'makeClickable',
'shortcode' => 'shortCode',
'markdown' => 'markdown',
'nl2br' => 'nl2br',
'purify' => 'purify',
];
// Make an array of the comma separated string $filters
if (is_array($filters)) {
$filter = $filters;
} else {
$filters = strtolower($filters);
$filter = preg_replace('/\s/', '', explode(',', $filters));
}
// For each filter, call its function with the $text as parameter.
foreach ($filter as $key) {
if (!isset($callbacks[$key])) {
throw new Exception("The filter '$filters' is not a valid filter string due to '$key'.");
}
$text = call_user_func_array([$this, $callbacks[$key]], [$text]);
}
return $text;
} | php | {
"resource": ""
} |
q8772 | TextFilter.setFilterConfig | train | public function setFilterConfig($filter, $config)
{
if (!$this->hasFilter($filter)) {
throw new Exception("No such filter '$filter' exists.");
}
$this->config[$filter] = $config;
} | php | {
"resource": ""
} |
q8773 | TextFilter.getFilterConfig | train | public function getFilterConfig($filter)
{
if (!$this->hasFilter($filter)) {
throw new Exception("No such filter '$filter' exists.");
}
return isset($this->config[$filter])
? $this->config[$filter]
: [];
} | php | {
"resource": ""
} |
q8774 | TextFilter.addToFrontmatter | train | private function addToFrontmatter($matter)
{
if (empty($matter) || !is_array($matter)) {
return $this;
}
if (is_null($this->current->frontmatter)) {
$this->current->frontmatter = [];
}
$this->current->frontmatter = array_merge($this->current->frontmatter, $matter);
return $this;
} | php | {
"resource": ""
} |
q8775 | TextFilter.parse | train | public function parse($text, $filter)
{
$this->current = new \stdClass();
$this->current->frontmatter = [];
$this->current->text = $text;
foreach ($filter as $key) {
$this->parseFactory($key);
}
$this->current->text = $this->getUntilStop($this->current->text);
return $this->current;
} | php | {
"resource": ""
} |
q8776 | TextFilter.addExcerpt | train | public function addExcerpt($current)
{
list($excerpt, $hasMore) = $this->getUntilMore($current->text);
$current->excerpt = $excerpt;
$current->hasMore = $hasMore;
} | php | {
"resource": ""
} |
q8777 | TextFilter.extractFrontMatter | train | private function extractFrontMatter($text, $startToken, $stopToken)
{
$tokenLength = strlen($startToken);
$start = strpos($text, $startToken);
// Is a valid start?
if ($start !== false && $start !== 0) {
if ($text[$start - 1] !== "\n") {
$start = false;
}
}
$frontmatter = null;
if ($start !== false) {
$stop = strpos($text, $stopToken, $tokenLength - 1);
if ($stop !== false && $text[$stop - 1] === "\n") {
$length = $stop - ($start + $tokenLength);
$frontmatter = substr($text, $start + $tokenLength, $length);
$textStart = substr($text, 0, $start);
$text = $textStart . substr($text, $stop + $tokenLength);
}
}
return [$text, $frontmatter];
} | php | {
"resource": ""
} |
q8778 | TextFilter.jsonFrontMatter | train | public function jsonFrontMatter($text)
{
list($text, $frontmatter) = $this->extractFrontMatter($text, "{{{\n", "}}}\n");
if (!empty($frontmatter)) {
$frontmatter = json_decode($frontmatter, true);
if (is_null($frontmatter)) {
throw new Exception("Failed parsing JSON frontmatter.");
}
}
return [
"text" => $text,
"frontmatter" => $frontmatter
];
} | php | {
"resource": ""
} |
q8779 | TextFilter.yamlFrontMatter | train | public function yamlFrontMatter($text)
{
list($text, $frontmatter) = $this->extractFrontMatter($text, "---\n", "...\n");
if (!empty($frontmatter)) {
$frontmatter = $this->yamlParse("---\n$frontmatter...\n");
}
return [
"text" => $text,
"frontmatter" => $frontmatter
];
} | php | {
"resource": ""
} |
q8780 | TextFilter.yamlParse | train | public function yamlParse($text)
{
if (function_exists("yaml_parse")) {
// Prefer php5-yaml extension
$parsed = yaml_parse($text);
if ($parsed === false) {
throw new Exception("Failed parsing YAML frontmatter.");
}
return $parsed;
}
if (method_exists("Symfony\Component\Yaml\Yaml", "parse")) {
// symfony/yaml
$parsed = \Symfony\Component\Yaml\Yaml::parse($text);
return $parsed;
}
if (function_exists("spyc_load")) {
// mustangostang/spyc
$parsed = spyc_load($text);
return $parsed;
}
throw new Exception("Could not find support for YAML.");
} | php | {
"resource": ""
} |
q8781 | TextFilter.getTitleFromFirstH1 | train | public function getTitleFromFirstH1($text)
{
$matches = [];
$title = null;
if (preg_match("#<h1.*?>(.*)</h1>#", $text, $matches)) {
$title = strip_tags($matches[1]);
}
return $title;
} | php | {
"resource": ""
} |
q8782 | TextFilter.getTitleFromFirstHeader | train | public function getTitleFromFirstHeader($text)
{
$matches = [];
$title = null;
if (preg_match("#<h[1-6].*?>(.*)</h[1-6]>#", $text, $matches)) {
$title = strip_tags($matches[1]);
}
return $title;
} | php | {
"resource": ""
} |
q8783 | TextFilter.purify | train | public function purify($text)
{
$config = \HTMLPurifier_Config::createDefault();
$config->set("Cache.DefinitionImpl", null);
//$config->set('Cache.SerializerPath', '/home/user/absolute/path');
$purifier = new \HTMLPurifier($config);
return $purifier->purify($text);
} | php | {
"resource": ""
} |
q8784 | TextFilter.markdown | train | public function markdown($text)
{
$text = \Michelf\MarkdownExtra::defaultTransform($text);
$text = \Michelf\SmartyPantsTypographer::defaultTransform(
$text,
"2"
);
return $text;
} | php | {
"resource": ""
} |
q8785 | MorphOneOrMany.getRelationQuery | train | public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
$query = parent::getRelationQuery($query, $parent, $columns);
return $query->where($this->morphType, $this->morphClass);
} | php | {
"resource": ""
} |
q8786 | AbstractAccessor.choose | train | public function choose($val, $isMultiple = null)
{
$arguments = array(json_encode($val));
if (null !== $isMultiple) {
$arguments[] = (bool) $isMultiple ? 'true' : 'false';
}
$this->con->executeStep(
sprintf('_sahi._setSelected(%s, %s)', $this->getAccessor(), implode(', ', $arguments))
);
} | php | {
"resource": ""
} |
q8787 | AbstractAccessor.setFile | train | public function setFile($path)
{
$this->con->executeStep(
sprintf('_sahi._setFile(%s, %s)', $this->getAccessor(), json_encode($path))
);
} | php | {
"resource": ""
} |
q8788 | AbstractAccessor.dragDrop | train | public function dragDrop(AbstractAccessor $to)
{
$this->con->executeStep(sprintf('_sahi._dragDrop(%s, %s)', $this->getAccessor(), $to->getAccessor()));
} | php | {
"resource": ""
} |
q8789 | AbstractAccessor.dragDropXY | train | public function dragDropXY($x, $y, $relative = null)
{
$arguments = array($x, $y);
if (null !== $relative) {
$arguments[] = (bool) $relative ? 'true' : 'false';
}
$this->con->executeStep(
sprintf('_sahi._dragDropXY(%s, %s)', $this->getAccessor(), implode(', ', $arguments))
);
} | php | {
"resource": ""
} |
q8790 | AbstractAccessor.keyPress | train | public function keyPress($charInfo, $combo = null)
{
$this->con->executeStep(
sprintf('_sahi._keyPress(%s, %s)', $this->getAccessor(), $this->getKeyArgumentsString($charInfo, $combo))
);
} | php | {
"resource": ""
} |
q8791 | AbstractAccessor.setValue | train | public function setValue($val)
{
$this->con->executeStep(
sprintf('_sahi._setValue(%s, %s)', $this->getAccessor(), json_encode($val))
);
} | php | {
"resource": ""
} |
q8792 | AbstractAccessor.getAttr | train | public function getAttr($attr)
{
$attributeValue = $this->con->evaluateJavascript(sprintf('%s.getAttribute(%s)', $this->getAccessor(), json_encode($attr)));
if ($attributeValue === false) {
// see https://github.com/kriswallsmith/Buzz/pull/138 bug
return '';
}
return $attributeValue;
} | php | {
"resource": ""
} |
q8793 | AbstractAccessor.getKeyArgumentsString | train | private function getKeyArgumentsString($charInfo, $combo)
{
$arguments = json_encode($charInfo);
if (null !== $combo) {
$arguments .= ', ' . json_encode($combo);
}
return $arguments;
} | php | {
"resource": ""
} |
q8794 | AbstractOTP.setSecret | train | public function setSecret($secret)
{
if (!$secret instanceof Seed) {
$secret = new Seed($secret);
}
$this->secret = $secret;
return $this;
} | php | {
"resource": ""
} |
q8795 | AbstractOTP.truncateHash | train | protected static function truncateHash($hash)
{
$offset = ord($hash[19]) & 0xf;
$value = (ord($hash[$offset + 0]) & 0x7f) << 24;
$value |= (ord($hash[$offset + 1]) & 0xff) << 16;
$value |= (ord($hash[$offset + 2]) & 0xff) << 8;
$value |= (ord($hash[$offset + 3]) & 0xff);
return $value;
} | php | {
"resource": ""
} |
q8796 | AbstractOTP.counterToString | train | protected static function counterToString($counter)
{
$temp = '';
while ($counter != 0) {
$temp .= chr($counter & 0xff);
$counter >>= 8;
}
return substr(str_pad(strrev($temp), 8, "\0", STR_PAD_LEFT), 0, 8);
} | php | {
"resource": ""
} |
q8797 | CheckCommand.checkBackups | train | private function checkBackups(SymfonyStyle $io, array $backups)
{
/** @var PluginRegistry $plugins */
$plugins = $this->getContainer()->get('plugins');
foreach ($backups as $name => $backup) {
$this->checkBackup($plugins, $io, $name, $backup);
}
} | php | {
"resource": ""
} |
q8798 | CheckCommand.checkBackup | train | private function checkBackup(PluginRegistry $plugins, SymfonyStyle $io, $name, array $backup)
{
$io->section('Backup: ' . $name);
if (!$plugins->has($backup['plugin'])) {
$io->warning(sprintf('Plugin "%s" not found', $backup['plugin']));
return false;
}
$optionsResolver = new OptionsResolver();
$plugins->getPlugin($backup['plugin'])->configureOptionsResolver($optionsResolver);
try {
$parameter = $optionsResolver->resolve($backup['parameter']);
} catch (InvalidArgumentException $e) {
$io->warning(sprintf('Parameter not valid' . PHP_EOL . PHP_EOL . 'Message: "%s"', $e->getMessage()));
return false;
}
$io->write('Process: ');
$process = 'All';
if (0 < count($backup['process'])) {
$process = '["' . implode('", "', $backup['process']) . '""]';
}
$io->writeln($process);
$io->write('Parameter:');
$messages = array_filter(explode("\r\n", Yaml::dump($parameter)));
$io->block($messages, null, null, ' ');
$io->writeln('OK');
return true;
} | php | {
"resource": ""
} |
q8799 | CheckCommand.getBackups | train | private function getBackups()
{
$backups = $this->getContainer()->getParameter('nanbando.backup');
$preset = [];
if ($name = $this->getParameter('nanbando.application.name')) {
/** @var PresetStore $presetStore */
$presetStore = $this->getContainer()->get('presets');
$preset = $presetStore->getPreset(
$name,
$this->getParameter('nanbando.application.version'),
$this->getParameter('nanbando.application.options')
);
}
return array_merge($preset, $backups);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.