_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q12700
BaseHandler.sendChatActionReply
train
public function sendChatActionReply(): SendChatAction { $m = $this->bot->sendChatAction(); $this->setReplyMarkup($m, false); return $m; }
php
{ "resource": "" }
q12701
TaskSubType.copyTemplateFilesToProject
train
protected function copyTemplateFilesToProject(array $filenames, $overwrite = false) { try { $filesystem = $this->taskFilesystemStack(); foreach ($filenames as $template_path => $target_path) { $target_file = ProjectX::projectRoot() . "/{$target_path}"; $template_file = $this ->templateManager() ->getTemplateFilePath($template_path); $filesystem->copy($template_file, $target_file, $overwrite); } $filesystem->run(); } catch (\Exception $e) { throw new \Exception( sprintf('Failed to copy template file(s) into project!') ); } return $this; }
php
{ "resource": "" }
q12702
ArrayUtils.arrayDropdown
train
public static function arrayDropdown(array $raw, $partition, $key, $value) { $output = array(); foreach (self::arrayPartition($raw, $partition) as $target => $data) { foreach ($data as $innerKey => $innerValue) { if (isset($innerValue[$key], $innerValue[$value])) { $output[$target][$innerValue[$key]] = $innerValue[$value]; } } } return $output; }
php
{ "resource": "" }
q12703
ArrayUtils.arrayPartition
train
public static function arrayPartition(array $raw, $key, $keepKey = true) { $result = array(); foreach ($raw as $index => $collection) { // Make the the root partition exists if (!isset($collection[$key])) { throw new LogicException(sprintf( 'The key "%s" does not exist in provided collection', $key )); } // Extract module' name as a key and put the rest into its values $target = array($collection[$key] => $collection); foreach ($target as $module => $array) { // When doesn't exist, then need to create a one if (!isset($result[$module])) { $result[$module] = array(); } if ($keepKey == false) { unset($array[$key]); } $result[$module][] = $array; } } return $result; }
php
{ "resource": "" }
q12704
ArrayUtils.arrayRecovery
train
public static function arrayRecovery(array $array, array $keys, $value) { foreach ($keys as $key) { if (!isset($array[$key])) { $array[$key] = $value; } } return $array; }
php
{ "resource": "" }
q12705
ArrayUtils.valuefy
train
public static function valuefy(array $data, $valueModue = true) { if ($valueModue === true) { $values = array_values($data); } else { $values = array_keys($data); } return array_combine($values, $values); }
php
{ "resource": "" }
q12706
ArrayUtils.sumColumnsWithAverages
train
public static function sumColumnsWithAverages(array $entities, array $averages = array(), $precision = 2) { // Count the sum of all columns $sum = self::sumColumns($entities); if (!empty($averages)) { $count = count($entities); // Make sure that the division by zero won't occur if ($count === 0) { $count = 1; } foreach ($averages as $average) { if (isset($sum[$average])) { if ($precision !== false) { } else { $sum[$average] = $sum[$average] / $count; } } } } return $sum; }
php
{ "resource": "" }
q12707
ArrayUtils.roundValues
train
public static function roundValues(array $data, $precision = 2) { return self::filterValuesRecursively($data, function($value) use ($precision) { $value = is_numeric($value) ? round($value, $precision) : $value; $value = empty($value) ? 0 : $value; return $value; }); }
php
{ "resource": "" }
q12708
ArrayUtils.arrayColumns
train
public static function arrayColumns(array $data) { // Count the amount of values from the source input $count = count($data); if ($count === 0) { return false; } if ($count === 1) { return array_keys($data[0]); } if (isset($data[0])) { return array_keys($data[0]); } else { return false; } }
php
{ "resource": "" }
q12709
ArrayUtils.sumColumns
train
public static function sumColumns(array $data) { $columns = self::arrayColumns($data); if ($columns !== false){ return self::columnSum($data, $columns); } else { return false; } }
php
{ "resource": "" }
q12710
ArrayUtils.columnSum
train
public static function columnSum(array $data, array $columns) { $result = array(); foreach ($columns as $column) { foreach ($data as $collection) { if (isset($collection[$column])) { if (isset($result[$column])) { $result[$column] += $collection[$column]; } else { $result[$column] = $collection[$column]; } } } } return $result; }
php
{ "resource": "" }
q12711
ArrayUtils.filterValuesRecursively
train
public static function filterValuesRecursively(array $array, Closure $callback = null) { foreach ($array as $index => $value) { if (is_array($value)) { $array[$index] = call_user_func(__METHOD__, $value, $callback); } else { $array[$index] = call_user_func($callback, $value); } } return $array; }
php
{ "resource": "" }
q12712
ArrayUtils.filterArray
train
public static function filterArray(array $array, Closure $callback) { foreach ($array as $index => $collection) { $array[$index] = call_user_func($callback, $collection); } return $array; }
php
{ "resource": "" }
q12713
ArrayUtils.mergeWithout
train
public static function mergeWithout(array $first, array $second, array $keys) { $result = array_merge($first, $second); return self::arrayWithout($result, $keys); }
php
{ "resource": "" }
q12714
ArrayUtils.keysExist
train
public static function keysExist(array $collection, array $keys) { $collection = array_flip($collection); foreach ($keys as $key) { if (!in_array($key, $collection)) { return false; } } return true; }
php
{ "resource": "" }
q12715
ArrayUtils.arrayOnlyWith
train
public static function arrayOnlyWith(array $array, array $keys) { $result = array(); if (!self::isSequential($array)) { foreach ($array as $key => $value) { if (in_array($key, $keys)) { $result[$key] = $value; } } } else { foreach ($array as $value) { if (in_array($value, $keys)) { $result[] = $value; } } } return $result; }
php
{ "resource": "" }
q12716
ArrayUtils.arrayCombine
train
public static function arrayCombine(array $first, array $second, $replacement = null, $order = true) { // Fix for different length if (count($first) !== count($second)) { $input = array($first, $second); $count = array_map('count', $input); // Find the largest and lowest array index $min = array_keys($count , max($count)); $max = array_keys($count , min($count)); // Find indexes $min = $min[0]; $max = $max[0]; $largest = $input[$min]; $smallest = $input[$max]; // Now fix the length foreach ($largest as $key => $value) { if (!isset($smallest[$key])) { $smallest[$key] = $replacement; } } $first = $smallest; $second = $largest; } if ($order === true) { return array_combine($second, $first); } else { return array_combine($first, $second); } }
php
{ "resource": "" }
q12717
ArrayUtils.arrayList
train
public static function arrayList(array $array, $key, $value) { $result = array(); foreach ($array as $row) { if (array_key_exists($key, $row) && array_key_exists($value, $row)) { // References $name =& $row[$key]; $text =& $row[$value]; $result[$name] = $text; } else { trigger_error(sprintf('Nested arrays must contain both %s and %s', $key, $value)); } } return $result; }
php
{ "resource": "" }
q12718
ArrayUtils.arrayWithout
train
public static function arrayWithout(array $array, array $keys) { // Shared filter function $filter = function(array $array, array $keys) { foreach ($keys as $key) { if (array_key_exists($key, $array)) { unset($array[$key]); } } return $array; }; if (self::hasAllArrayValues($array)) { // Apply on nested arrays as well return self::filterArray($array, function($collection) use ($keys, $filter){ return $filter($collection, $keys); }); } else { return $filter($array, $keys); } }
php
{ "resource": "" }
q12719
ArrayUtils.search
train
public static function search(array $haystack, $needle) { foreach ($haystack as $key => $value) { if (is_array($value)) { $target = self::search($value, $needle); } else { $target = ''; } if ($needle === $value || ($target != false && $target != null)) { if ($target == null) { return array($key); } return array_merge(array($key), $target); } } return false; }
php
{ "resource": "" }
q12720
ArrayUtils.arrayUnique
train
public static function arrayUnique(array $array) { // Serialize each array's value foreach ($array as &$value) { $value = serialize($value); } // Now remove duplicate strings $array = array_unique($array); // Now restore to its previous state with removed strings foreach ($array as &$value) { $value = unserialize($value); } return $array; }
php
{ "resource": "" }
q12721
DocumentSelector.orderBy
train
public function orderBy(string $field, int $direction = self::ASCENDING): DocumentSelector { return $this->sortBy($this->sortBy + [$field => $direction]); }
php
{ "resource": "" }
q12722
DocumentSelector.findOne
train
public function findOne(array $query = [], bool $normalizeDates = true) { if ($normalizeDates) { $query = $this->normalizeDates($query); } //Working with projection (required to properly sort results) $result = $this->collection->findOne( array_merge($this->query, $query), $this->createOptions() ); if (empty($result)) { return null; } return $this->odm->make($this->class, $result, false); }
php
{ "resource": "" }
q12723
DocumentSelector.count
train
public function count(array $query = []): int { //Create options? return $this->collection->count( array_merge($this->query, $query), ['skip' => $this->offset, 'limit' => $this->limit] ); }
php
{ "resource": "" }
q12724
DocumentSelector.normalizeDates
train
protected function normalizeDates(array $query): array { array_walk_recursive($query, function (&$value) { if ($value instanceof \DateTime) { //MongoDate is always UTC, which is good :) $value = new UTCDateTime($value); } }); return $query; }
php
{ "resource": "" }
q12725
DrupalCacheAdapter.cache_set
train
public function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT) { return cache_set($cid, $data, $bin, $expire); }
php
{ "resource": "" }
q12726
DockerServiceBase.getService
train
public function getService() { if (!isset($this->service)) { $info = $this->getInfo(); $this->service = $this->service(); // Apply the overridden property values. foreach (static::PROPERTIES_OVERRIDE as $property) { if (!isset($info[$property]) || empty($info[$property])) { continue; } $method = 'set' . ucwords($property); if (is_callable([$this->service, $method])) { call_user_func_array([$this->service, $method], [$info[$property]]); } } } return $this->service; }
php
{ "resource": "" }
q12727
DockerServiceBase.getEnvironmentValue
train
public function getEnvironmentValue($name) { $name = strtolower($name); $service = $this->getService(); foreach ($service->getEnvironment() as $environment) { list($key, $value) = explode('=', $environment); if (strtolower($key) !== $name) { continue; } return $value; } return null; }
php
{ "resource": "" }
q12728
DockerServiceBase.getHostPorts
train
public function getHostPorts() { $ports = []; $service = $this->getService(); foreach ($service->getPorts() as $port) { list($host,) = explode(':', $port); $ports[] = $host; } return $ports; }
php
{ "resource": "" }
q12729
DockerServiceBase.getPorts
train
protected function getPorts($host = null) { $ports = $this->ports(); array_walk($ports, function (&$port) use ($host) { $host = isset($host) ? $host : $port; $port = "{$host}:{$port}"; }); return $ports; }
php
{ "resource": "" }
q12730
DockerServiceBase.getServiceNames
train
protected function getServiceNames() { $names = []; foreach ($this->getServices() as $name => $info) { if (!isset($info['type'])) { continue; } $names[$name] = $info['type']; } return $names; }
php
{ "resource": "" }
q12731
DockerServiceBase.alterService
train
protected function alterService(DockerService $service) { if ($this->internal) { $service ->setNetworks([ 'internal' ]) ->setlabels([ 'traefik.enable=false' ]); if ($this->bindPorts) { $service->setPorts( $this->getPorts('0000') ); } } else { $service->setPorts($this->getPorts()); } return $service; }
php
{ "resource": "" }
q12732
DockerServiceBase.formatRunCommand
train
protected function formatRunCommand(array $commands) { $last = end($commands); return 'RUN ' . implode("\r\n && ", array_map( function ($value) use ($last) { return $last !== $value ? "{$value} \\" : $value; }, $commands )); }
php
{ "resource": "" }
q12733
DockerServiceBase.mergeConfigVariable
train
protected function mergeConfigVariable($name, array $values) { if (in_array($name, static::DOCKER_VARIABLES)) { $this->configs[$name] = array_unique( array_merge($this->configs[$name], $values) ); } return $this; }
php
{ "resource": "" }
q12734
Manager.launchNextTask
train
protected function launchNextTask() { if (! $this->numberOfThreadsToLaunch) { return false; } $taskInfos = $this->pool[$this->numberOfTasks - $this->numberOfThreadsToLaunch]; $taskInfos['task']->fork(); $this->numberOfRunningThreads++; $this->numberOfThreadsToLaunch--; return true; }
php
{ "resource": "" }
q12735
Router.match
train
public function match($segment, array $map) { foreach ($map as $index => $uriTemplate) { $matches = array(); if (preg_match($this->createRegEx($uriTemplate), $segment, $matches) === 1) { $matchedURI = array_shift($matches); $routeMatch = new RouteMatch(); $routeMatch->setMatchedUri($matchedURI) ->setMatchedUriTemplate($uriTemplate) ->setVariables($matches); return $routeMatch; } } // By default, we have no matches return false; }
php
{ "resource": "" }
q12736
Router.createRegEx
train
private function createRegEx($uriTemplate) { $pattern = str_replace($this->getPlaceholders(), $this->getPatterns(), $uriTemplate); // Match everything after question mark, if present $pattern .= '(\?(.*))?'; return '~^' . $pattern . '$~i'; }
php
{ "resource": "" }
q12737
CacheMapper.fetchAll
train
public function fetchAll() { $query = sprintf('SELECT * FROM `%s`', $this->table); $result = array(); foreach ($this->pdo->query($query) as $key => $value) { $result[$key] = $value; } return $this->parse($result); }
php
{ "resource": "" }
q12738
CacheMapper.alter
train
private function alter($key, $operator, $step) { $query = sprintf('UPDATE `%s` SET `value` = value %s %s WHERE `key` = :key', $this->table, $operator, $step); $stmt = $this->pdo->prepare($query); return $stmt->execute(array( ':key' => $key )); }
php
{ "resource": "" }
q12739
CacheMapper.insert
train
public function insert($key, $value, $ttl, $time) { if ($this->serializer->isSerializeable($value)) { $value = $this->serializer->serialize($value); } $query = sprintf('INSERT INTO `%s` (`key`, `value`, `ttl`, `created_on`) VALUES (:key, :value, :ttl, :created_on)', $this->table); $stmt = $this->pdo->prepare($query); return $stmt->execute(array( ':'.ConstProviderInterface::CACHE_PARAM_KEY => $key, ':'.ConstProviderInterface::CACHE_PARAM_VALUE => $value, ':'.ConstProviderInterface::CACHE_PARAM_TTL => $ttl, ':'.ConstProviderInterface::CACHE_PARAM_CREATED_ON => time(), )); }
php
{ "resource": "" }
q12740
CacheMapper.parse
train
private function parse(array $data) { $result = array(); foreach ($data as $index => $array) { if ($this->serializer->isSerialized($array[ConstProviderInterface::CACHE_PARAM_VALUE])) { $array[ConstProviderInterface::CACHE_PARAM_VALUE] = $this->serializer->unserialize($array[ConstProviderInterface::CACHE_PARAM_VALUE]); } $result[$array[ConstProviderInterface::CACHE_PARAM_KEY]] = array( ConstProviderInterface::CACHE_PARAM_VALUE => $array[ConstProviderInterface::CACHE_PARAM_VALUE], ConstProviderInterface::CACHE_PARAM_TTL => $array[ConstProviderInterface::CACHE_PARAM_TTL], ConstProviderInterface::CACHE_PARAM_CREATED_ON => $array[ConstProviderInterface::CACHE_PARAM_CREATED_ON] ); } return $result; }
php
{ "resource": "" }
q12741
PrimeTask.insertNewFileFunctions
train
private function insertNewFileFunctions(iterable $new): void { // early return when there is nothing to be added if (0 === \count($new)) { return; } $table = $this->getTable(); $db = $this->getDb(); foreach ($new as $file_function => $data) { $query = $db->prepare( "INSERT INTO $table (function, added_at, changed_at) VALUES (:file_function, NOW(), :changed_at)" ); $changed_at = $data->getChangedAt(); $query->bindParam(":file_function", $file_function); $query->bindParam(":changed_at", $changed_at); $query->execute(); } }
php
{ "resource": "" }
q12742
Calculator.get
train
public function get(Carbon $dt = NULL) { if (!$dt) { $dt = new Carbon(); } /* Disregard times */ $dt->setTime(0, 0, 0); /* FY is based on the -end- of the FY, thus we will work backward to determine if we need to 'rollup' the FY from the input year */ $fyStart = Carbon::create($dt->year, $this->month, $this->day, 0, 0, 0); $fyEnd = clone $fyStart; $fyEnd->addYear()->subDay(); if (!$dt->between($fyStart, $fyEnd, TRUE)) { $fyEnd->year($dt->year); } return $fyEnd; }
php
{ "resource": "" }
q12743
NumberBase.buildDigitList
train
private function buildDigitList($digitList) { if (is_int($digitList)) { return new IntegerDigitList($digitList); } elseif (is_string($digitList)) { return new StringDigitList($digitList); } elseif (is_array($digitList)) { return new ArrayDigitList($digitList); } throw new \InvalidArgumentException('Unexpected number base type'); }
php
{ "resource": "" }
q12744
NumberBase.hasDigit
train
public function hasDigit($digit) { try { $this->digits->getValue($digit); } catch (DigitList\InvalidDigitException $ex) { return false; } return true; }
php
{ "resource": "" }
q12745
NumberBase.getValues
train
public function getValues(array $digits) { $values = []; foreach ($digits as $digit) { $values[] = $this->digits->getValue($digit); } return $values; }
php
{ "resource": "" }
q12746
NumberBase.getDigits
train
public function getDigits(array $decimals) { $digits = []; foreach ($decimals as $decimal) { $digits[] = $this->digits->getDigit($decimal); } return $digits; }
php
{ "resource": "" }
q12747
NumberBase.findCommonRadixRoot
train
public function findCommonRadixRoot(NumberBase $base) { $common = array_intersect($this->getRadixRoots(), $base->getRadixRoots()); return count($common) > 0 ? max($common) : false; }
php
{ "resource": "" }
q12748
NumberBase.getRadixRoots
train
private function getRadixRoots() { $radix = count($this->digits); $roots = [$radix]; for ($i = 2; ($root = (int) ($radix ** (1 / $i))) > 1; $i++) { if ($root ** $i === $radix) { $roots[] = $root; } } return $roots; }
php
{ "resource": "" }
q12749
NumberBase.canonizeDigits
train
public function canonizeDigits(array $digits) { $result = $this->getDigits($this->getValues($digits)); return empty($result) ? [$this->digits->getDigit(0)] : $result; }
php
{ "resource": "" }
q12750
NumberBase.splitString
train
public function splitString($string) { if ($this->digits->hasStringConflict()) { throw new \RuntimeException('The number base does not support string presentation'); } $pattern = $this->getDigitPattern(); if ((string) $string === '') { $digits = []; } elseif (is_int($pattern)) { $digits = str_split($string, $this->digitPattern); } else { preg_match_all($pattern, $string, $match); $digits = $match[0]; } return $this->canonizeDigits($digits); }
php
{ "resource": "" }
q12751
NumberBase.getDigitPattern
train
private function getDigitPattern() { if (!isset($this->digitPattern)) { $lengths = array_map('strlen', $this->digits->getDigits()); if (count(array_flip($lengths)) === 1) { $this->digitPattern = array_pop($lengths); } else { $this->digitPattern = sprintf( '(%s|.+)s%s', implode('|', array_map('preg_quote', $this->digits->getDigits())), $this->digits->isCaseSensitive() ? '' : 'i' ); } } return $this->digitPattern; }
php
{ "resource": "" }
q12752
ValidatorChain.isValid
train
public function isValid() { foreach ($this->validators as $validator) { if (!$validator->isValid()) { // Prepare error messages foreach ($validator->getErrors() as $name => $messages) { if (!isset($this->errors[$name])) { $this->errors[$name] = array(); } $this->errors[$name] = $messages; } } } return !$this->hasErrors(); }
php
{ "resource": "" }
q12753
Href.replace
train
public function replace( $key, $value ) { if($value === "" || is_null($value) || $value === false) { $this->url = preg_replace("#/{" . $key . "}.*$#", "", $this->getUrl()); } else { $this->url = str_replace("{" . $key . "}", $value, $this->getUrl()); } return $this; }
php
{ "resource": "" }
q12754
Href.validate
train
public function validate() { if (!$this->isValid( $this->getUrl() )) { throw new InvalidUrl( sprintf( '"%s" is not a valid url', $this->url ) ); } return $this; }
php
{ "resource": "" }
q12755
EventTaskBase.executeCommandHook
train
protected function executeCommandHook($method, $event_type) { foreach ($this->getCommandsByMethodEventType($method, $event_type) as $command) { if (is_string($command)) { $command = (new CommandHook()) ->setType('raw') ->setCommand($command); } elseif (is_array($command)) { $command = CommandHook::createWithData($command); } if (!$command instanceof CommandHookInterface) { continue; } switch ($command->getType()) { case 'symfony': $this->executeSymfonyCmdHook($command, $method); break; default: $this->executeEngineCmdHook($command); break; } } return $this; }
php
{ "resource": "" }
q12756
EventTaskBase.executeEngineCmdHook
train
protected function executeEngineCmdHook(CommandHookInterface $hook_command) { $options = $hook_command->getOptions(); // Determine the service the command should be ran inside. $service = isset($options['service']) ? $options['service'] : null; // Determine if the command should be ran locally. $localhost = (boolean) isset($options['localhost']) ? $options['localhost'] : !isset($service); $command = $this->resolveHookCommand($hook_command); return $this->executeEngineCommand($command, $service, [], false, $localhost); }
php
{ "resource": "" }
q12757
EventTaskBase.resolveHookCommand
train
protected function resolveHookCommand(CommandHookInterface $command_hook) { $command = null; switch ($command_hook->getType()) { case 'raw': $command = $command_hook->getCommand(); break; case 'engine': $command = $this->getEngineCommand($command_hook); break; case 'project': $command = $this->getProjectCommand($command_hook); break; } return isset($command) ? $command : false; }
php
{ "resource": "" }
q12758
EventTaskBase.executeSymfonyCmdHook
train
protected function executeSymfonyCmdHook(CommandHookInterface $command_hook, $method) { $command = $command_hook->getCommand(); $container = ProjectX::getContainer(); $application = $container->get('application'); try { $info = $this->getCommandInfo($method); $command = $application->find($command); if ($command->getName() === $info->getName()) { throw new \Exception(sprintf( 'Unable to call the %s command hook due to it ' . 'invoking the parent method.', $command->getName() )); } } catch (CommandNotFoundException $exception) { throw new CommandHookRuntimeException(sprintf( 'Unable to find %s command in the project-x command ' . 'hook.', $command )); } catch (\Exception $exception) { throw new CommandHookRuntimeException($exception->getMessage()); } $exec = $this->taskSymfonyCommand($command); $definition = $command->getDefinition(); // Support symfony command options. if ($command_hook->hasOptions()) { foreach ($command_hook->getOptions() as $option => $value) { if (is_numeric($option)) { $option = $value; $value = null; } if (!$definition->hasOption($option)) { continue; } $exec->opt($option, $value); } } // Support symfony command arguments. if ($command_hook->hasArguments()) { foreach ($command_hook->getArguments() as $arg => $value) { if (!isset($value) || !$definition->hasArgument($arg)) { continue; } $exec->arg($arg, $value); } } return $exec->run(); }
php
{ "resource": "" }
q12759
EventTaskBase.getProjectCommand
train
protected function getProjectCommand(CommandHookInterface $command_hook) { $method = $command_hook->getCommand(); $project = $this->getProjectInstance(); if (!method_exists($project, $method)) { throw new CommandHookRuntimeException( sprintf("The %s method doesn't exist on the project.", $method) ); } $args = array_merge( $command_hook->getOptions(), $command_hook->getArguments() ); return call_user_func_array([$project, $method], [$args]); }
php
{ "resource": "" }
q12760
EventTaskBase.getEngineCommand
train
protected function getEngineCommand(CommandHookInterface $command_hook) { $method = $command_hook->getCommand(); $engine = $this->getEngineInstance(); if (!method_exists($engine, $method)) { throw new CommandHookRuntimeException( sprintf("The %s method doesn't exist on the environment engine.", $method) ); } $args = array_merge( $command_hook->getOptions(), $command_hook->getArguments() ); return call_user_func_array([$engine, $method], [$args]); }
php
{ "resource": "" }
q12761
EventTaskBase.getCommandsByMethodEventType
train
protected function getCommandsByMethodEventType($method, $event_type) { $hooks = ProjectX::getProjectConfig()->getCommandHooks(); if (empty($hooks)) { return []; } $info = $this->getCommandInfo($method); list($command, $action) = explode(':', $info->getName()); if (!isset($hooks[$command][$action][$event_type])) { return []; } return $hooks[$command][$action][$event_type]; }
php
{ "resource": "" }
q12762
RedisProxy.setDriversOrder
train
public function setDriversOrder(array $driversOrder) { foreach ($driversOrder as $driver) { if (!in_array($driver, $this->supportedDrivers)) { throw new RedisProxyException('Driver "' . $driver . '" is not supported'); } } $this->driversOrder = $driversOrder; return $this; }
php
{ "resource": "" }
q12763
RedisProxy.exists
train
public function exists($key) { $this->init(); $result = $this->driver->exists($key); return (bool)$result; }
php
{ "resource": "" }
q12764
RedisProxy.get
train
public function get($key) { $this->init(); $result = $this->driver->get($key); return $this->convertFalseToNull($result); }
php
{ "resource": "" }
q12765
RedisProxy.getset
train
public function getset($key, $value) { $this->init(); $result = $this->driver->getset($key, $value); return $this->convertFalseToNull($result); }
php
{ "resource": "" }
q12766
RedisProxy.expire
train
public function expire($key, $seconds) { $this->init(); $result = $this->driver->expire($key, $seconds); return (bool)$result; }
php
{ "resource": "" }
q12767
RedisProxy.pexpire
train
public function pexpire($key, $miliseconds) { $this->init(); $result = $this->driver->pexpire($key, $miliseconds); return (bool)$result; }
php
{ "resource": "" }
q12768
RedisProxy.expireat
train
public function expireat($key, $timestamp) { $this->init(); $result = $this->driver->expireat($key, $timestamp); return (bool)$result; }
php
{ "resource": "" }
q12769
RedisProxy.pexpireat
train
public function pexpireat($key, $milisecondsTimestamp) { $this->init(); $result = $this->driver->pexpireat($key, $milisecondsTimestamp); return (bool)$result; }
php
{ "resource": "" }
q12770
RedisProxy.psetex
train
public function psetex($key, $miliseconds, $value) { $this->init(); $result = $this->driver->psetex($key, $miliseconds, $value); if ($result == '+OK') { return true; } return $this->transformResult($result); }
php
{ "resource": "" }
q12771
RedisProxy.persist
train
public function persist($key) { $this->init(); $result = $this->driver->persist($key); return (bool)$result; }
php
{ "resource": "" }
q12772
RedisProxy.setnx
train
public function setnx($key, $value) { $this->init(); $result = $this->driver->setnx($key, $value); return (bool)$result; }
php
{ "resource": "" }
q12773
RedisProxy.incrby
train
public function incrby($key, $increment = 1) { $this->init(); return $this->driver->incrby($key, (int)$increment); }
php
{ "resource": "" }
q12774
RedisProxy.incrbyfloat
train
public function incrbyfloat($key, $increment = 1) { $this->init(); return $this->driver->incrbyfloat($key, $increment); }
php
{ "resource": "" }
q12775
RedisProxy.decrby
train
public function decrby($key, $decrement = 1) { $this->init(); return $this->driver->decrby($key, (int)$decrement); }
php
{ "resource": "" }
q12776
RedisProxy.dump
train
public function dump($key) { $this->init(); $result = $this->driver->dump($key); return $this->convertFalseToNull($result); }
php
{ "resource": "" }
q12777
RedisProxy.mset
train
public function mset(...$dictionary) { $this->init(); if (is_array($dictionary[0])) { $result = $this->driver->mset(...$dictionary); return $this->transformResult($result); } $dictionary = $this->prepareKeyValue($dictionary, 'mset'); $result = $this->driver->mset($dictionary); return $this->transformResult($result); }
php
{ "resource": "" }
q12778
RedisProxy.hdel
train
public function hdel($key, ...$fields) { $fields = $this->prepareArguments('hdel', ...$fields); $this->init(); return $this->driver->hdel($key, ...$fields); }
php
{ "resource": "" }
q12779
RedisProxy.hincrby
train
public function hincrby($key, $field, $increment = 1) { $this->init(); return $this->driver->hincrby($key, $field, (int)$increment); }
php
{ "resource": "" }
q12780
RedisProxy.hincrbyfloat
train
public function hincrbyfloat($key, $field, $increment = 1) { $this->init(); return $this->driver->hincrbyfloat($key, $field, $increment); }
php
{ "resource": "" }
q12781
RedisProxy.hmset
train
public function hmset($key, ...$dictionary) { $this->init(); if (is_array($dictionary[0])) { $result = $this->driver->hmset($key, ...$dictionary); return $this->transformResult($result); } $dictionary = $this->prepareKeyValue($dictionary, 'hmset'); $result = $this->driver->hmset($key, $dictionary); return $this->transformResult($result); }
php
{ "resource": "" }
q12782
RedisProxy.hmget
train
public function hmget($key, ...$fields) { $fields = array_unique($this->prepareArguments('hmget', ...$fields)); $this->init(); $values = []; foreach ($this->driver->hmget($key, $fields) as $value) { $values[] = $this->convertFalseToNull($value); } return array_combine($fields, $values); }
php
{ "resource": "" }
q12783
RedisProxy.sadd
train
public function sadd($key, ...$members) { $members = $this->prepareArguments('sadd', ...$members); $this->init(); return $this->driver->sadd($key, ...$members); }
php
{ "resource": "" }
q12784
RedisProxy.spop
train
public function spop($key, $count = 1) { $this->init(); if ($count == 1 || $count === null) { $result = $this->driver->spop($key); return $this->convertFalseToNull($result); } $members = []; for ($i = 0; $i < $count; ++$i) { $member = $this->driver->spop($key); if (!$member) { break; } $members[] = $member; } return empty($members) ? null : $members; }
php
{ "resource": "" }
q12785
RedisProxy.sscan
train
public function sscan($key, &$iterator, $pattern = null, $count = null) { if ((string)$iterator === '0') { return null; } $this->init(); if ($this->actualDriver() === self::DRIVER_PREDIS) { $returned = $this->driver->sscan($key, $iterator, ['match' => $pattern, 'count' => $count]); $iterator = $returned[0]; return $returned[1]; } return $this->driver->sscan($key, $iterator, $pattern, $count); }
php
{ "resource": "" }
q12786
RedisProxy.rpush
train
public function rpush($key, ...$elements) { $elements = $this->prepareArguments('rpush', ...$elements); $this->init(); return $this->driver->rpush($key, ...$elements); }
php
{ "resource": "" }
q12787
RedisProxy.lpop
train
public function lpop($key) { $this->init(); $result = $this->driver->lpop($key); return $this->convertFalseToNull($result); }
php
{ "resource": "" }
q12788
RedisProxy.rpop
train
public function rpop($key) { $this->init(); $result = $this->driver->rpop($key); return $this->convertFalseToNull($result); }
php
{ "resource": "" }
q12789
RedisProxy.zadd
train
public function zadd($key, ...$dictionary) { $this->init(); if (is_array($dictionary[0])) { $return = 0; foreach ($dictionary[0] as $member => $score) { $res = $this->zadd($key, $score, $member); $return += $res; } return $return; } return $this->driver->zadd($key, ...$dictionary); }
php
{ "resource": "" }
q12790
RedisProxy.zrevrange
train
public function zrevrange($key, $start, $stop, $withscores = false) { $this->init(); if ($this->actualDriver() === self::DRIVER_PREDIS) { return $this->driver->zrevrange($key, $start, $stop, ['WITHSCORES' => $withscores]); } return $this->driver->zrevrange($key, $start, $stop, $withscores); }
php
{ "resource": "" }
q12791
RedisProxy.convertFalseToNull
train
private function convertFalseToNull($result) { return $this->actualDriver() === self::DRIVER_REDIS && $result === false ? null : $result; }
php
{ "resource": "" }
q12792
RedisProxy.transformResult
train
private function transformResult($result) { if ($this->actualDriver() === self::DRIVER_PREDIS && $result instanceof Status) { $result = $result->getPayload() === 'OK'; } return $result; }
php
{ "resource": "" }
q12793
RedisProxy.prepareKeyValue
train
private function prepareKeyValue(array $dictionary, $command) { $keys = array_values(array_filter($dictionary, function ($key) { return $key % 2 == 0; }, ARRAY_FILTER_USE_KEY)); $values = array_values(array_filter($dictionary, function ($key) { return $key % 2 == 1; }, ARRAY_FILTER_USE_KEY)); if (count($keys) != count($values)) { throw new RedisProxyException("Wrong number of arguments for $command command"); } return array_combine($keys, $values); }
php
{ "resource": "" }
q12794
Dumper.dump
train
public static function dump($variable, $exit = true) { if (is_object($variable) && method_exists($variable, '__toString')) { echo $variable; } else { if (is_bool($variable)) { var_dump($variable); } else { $text = sprintf('<pre>%s</pre>', print_r($variable, true)); print $text; } } if ($exit === true) { exit(); } }
php
{ "resource": "" }
q12795
Bootstrap.router
train
public static function router($directory, $config = 'config.yml') { $request = Server::get('PHP_SELF'); $root = Server::get('DOCUMENT_ROOT'); $file = $root . $request; if(file_exists($file) && !is_dir($file)) { return false; } else { Bootstrap::start($directory, $config); return true; } }
php
{ "resource": "" }
q12796
Bootstrap.init
train
public function init() { Profiler::start('init', 'init'); $this->initTime = microtime(true); $this->init = true; Log::d('Initializing framework...'); // $this->register_error_handler(); date_default_timezone_set('Europe/Madrid'); $this->setupLanguage(); Profiler::stop('init'); $this->manager = new ModuleManager($this->config, $this->directory); $this->manager->init(); Log::d('Module manager initialized'); $this->inited = true; // Log::d('Modules initialized: ' . count($this->manager->getModules())); // Log::d(array_map(function ($a) { // return $a->title; // }, $this->manager->getModules())); }
php
{ "resource": "" }
q12797
Bootstrap.install
train
public function install() { define('GL_INSTALL', true); $this->init(); echo '<pre>'; $fail = false; $db = new DatabaseManager(); if ($db->connectAndSelect()) { $this->setDatabase($db); $this->log('Connection to database ok'); $this->log('Installing Database...'); $models = $this->getModels(); foreach ($models as $model) { $instance = new $model(null); if ($instance instanceof Model) { $diff = $instance->getStructureDifferences($db, isset($_GET['drop'])); $this->log('Installing table \'' . $instance->getTableName() . '\' generated by ' . get_class($instance) . '...', 2); foreach ($diff as $action) { $this->log('Action: ' . $action['sql'] . '...', 3, false); if (isset($_GET['exec'])) { try { DBStructure::runAction($db, $instance, $action); $this->log('[OK]', 0); } catch (\Exception $ex) { $this->log('[FAIL]', 0); $fail = true; } } echo "\n"; } } } if (!isset($_GET['exec'])) { $this->log('Please <a href="?exec">click here</a> to make this changes in the database.'); } else { $db2 = new DBStructure(); $db2->setDatabaseUpdate(); $this->log('All done site ready for develop/production!'); } } else { if ($db->getConnection() !== null) { if (isset($_GET['create_database'])) { if ($db->exec('CREATE DATABASE ' . $this->config['database']['database'])) { echo 'Database created successful! Please reload the navigator'; } else { echo 'Can not create the database!'; } } else { echo 'Can\'t select the database <a href="install.php?create_database">Try to create database</a>'; } } else { echo 'Cannot connect to database'; } } }
php
{ "resource": "" }
q12798
InstanceBuilder.build
train
public function build($class, array $args) { // Normalize class name $class = $this->normalizeClassName($class); if (isset($this->cache[$class])) { return $this->cache[$class]; } else { if (class_exists($class, true)) { $instance = $this->getInstance($class, $args); $this->cache[$class] = $instance; return $instance; } else { throw new RuntimeException(sprintf( 'Can not build non-existing class "%s". The class does not exist or it does not follow PSR-0', $class )); } } }
php
{ "resource": "" }
q12799
InstanceBuilder.getInstance
train
private function getInstance($class, array $args) { // Hack to avoid Reflection for most cases switch (count($args)) { case 0: return new $class; case 1: return new $class($args[0]); case 2: return new $class($args[0], $args[1]); case 3: return new $class($args[0], $args[1], $args[2]); case 4: return new $class($args[0], $args[1], $args[2], $args[3]); case 5: return new $class($args[0], $args[1], $args[2], $args[3], $args[4]); case 6: return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); default: $reflection = new ReflectionClass(); return $reflection->newInstanceArgs($args); } }
php
{ "resource": "" }