public function __construct($elements = array()) { parent::__construct($elements); foreach ($this as $key => $value) { $this[$key] = static::convertToType($value); } }
protected function matchTubeNames($tubesSearch, OutputInterface $output) { $matchedTubes = new ArrayCollection(); $queue = $this->getQueue(); $error = false; foreach ((array) $tubesSearch as $tubeSearch) { $matched = $queue->tubes()->filter(function (Tube $tube) use($tubeSearch) { return Str::contains($tube->name(), $tubeSearch, false); }); if ($matched->isEmpty()) { $output->writeln("<warn>No tubes matched to: {$tubeSearch}</warn>"); $error = true; } $matchedTubes->merge($matched); } return array($matchedTubes, $error); }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $queue = $this->getQueue(); $stats = new ArrayCollection(); foreach ($input->getArgument('id') as $id) { $jobStats = $queue->statsJob($id); if ($jobStats->id() !== -1) { $stats->add($jobStats); } else { $output->writeln("Job <info>#{$id}</info> does not exist"); } } if (!$stats->isEmpty()) { $output->writeln($this->renderStats($stats)); } }
public function render(Environment $twig) { $templates = ArrayCollection::create($this->template)->map(function ($template) { return Str::endsWith($template, '.twig') ? $template : $template . '.twig'; }); $this->setContent($twig->resolveTemplate($templates->toArray())->render($this->variables->toArray())); $this->rendered = true; }
/** @inheritdoc */ public function getIterator() { if ($this->jobData instanceof ArrayCollection) { return $this->jobData->getIterator(); } elseif (is_array($this->jobData)) { return new \ArrayIterator($this->jobData); } else { return new \ArrayIterator(array('data' => $this->jobData)); } }
public function unserialize($data) { $params = new ArrayCollection(json_decode($data, true)); if ($params->count() === 1 && $params->containsKey('data')) { $data = $params['data']; if ($this->nativeUnserialize($data, $unserialized)) { return $unserialized; } } if ($params->containsKey('class')) { /** @var ISerializable|string $cls */ $cls = $params['class']; if (!class_exists($cls)) { throw new NotSerializableException($cls . ' does not exist'); } return $cls::fromArray($params->toArray()); } foreach ($params as $key => $value) { if (is_string($value)) { $value = trim($value); if ($this->nativeUnserialize($value, $data)) { $value = $data; } $params[$key] = $value; } elseif (is_array($value) && array_key_exists('class', $value)) { /** @var ISerializable|string $cls */ $cls = $value['class']; if (!class_exists($cls)) { throw new NotSerializableException($cls . ' does not exist'); } $params[$key] = $cls::fromArray($value); } } return $params; }
protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $stats = $this->getQueue()->statsServer(); if ($input->getOption('list')) { foreach ($stats->getKeys() as $key) { $output->writeln($key); } return; } if ($input->getOption('stat')) { foreach ($input->getOption('stat') as $statName) { if (!$stats->containsKey($statName)) { $output->writeln("<error>Stat: \"{$statName}\" does not exist</error>"); continue; } $output->write($stats->get($statName, 0), count($input->getOption('stat')) > 1); } return; } $optionNames = ArrayCollection::create(array('current', 'cmd', 'binlog', 'other')); if ($optionNames->forAll(function ($key, $value) use($input) { return !$input->getOption($value); })) { $input->setOption('current', true); $input->setOption('cmd', true); $input->setOption('binlog', true); $input->setOption('other', true); } foreach ($optionNames as $opt) { if (!$input->getOption($opt)) { continue; } $this->renderStats($output, $opt, $stats->{"get{$opt}Stats"}()); } }
private function getHelpText() { $exampleStats = ArrayCollection::create(array(new TubeStats(array('name' => 'TubeA')), new TubeStats(array('name' => 'SendApi')), new TubeStats(array('name' => 'ReceiveApi')))); $stats = preg_replace("#\n#", "\n ", $this->renderStats($exampleStats, 78)); return <<<EOF The <info>%command.name%</info> command displays information about the current tubes <comment>Example command:</comment> <info>php %command.full_name% tubeA api</info> will output: {$stats} Notice case sensitivity doesn't matter and both the <info>SendApi</info> and <info>ReceiveApi</info> tubes are matched. <comment>Header Explanation:</comment> Tube The tube's name Ready The number of ready jobs Buried The number of buried jobs Reserved The number of jobs reserved by all clients Delayed The number of delayed jobs Urgent The number of ready jobs with priority < 1024 Total The cumulative count of jobs created for the tube in the current beanstalkd process Using The number of open connections that are currently using the tube Watching The number of open connections that are currently watching the tube Waiting The number of open connections that have issued a reserve command while watching the tube but not yet received a response Pause Elapsed The number of seconds the tube has been paused for Pause Left The number of seconds until the tube is un-paused Delete Count The cumulative number of delete commands for the tube Pause Count The cumulative number of pause commands for the tube EOF; }
protected function getWorkerInfoList() { if ($this->workerInfoList) { return $this->workerInfoList; } return $this->workerInfoList = ArrayCollection::create(ClassFinder::create($this->workerDir)->isInstantiable()->isSubclassOf('\\GMO\\Beanstalk\\Worker\\WorkerInterface')->map(function (\ReflectionClass $class) { return new WorkerInfo($class); }))->sortKeys(); }
private function getProcessLines() { $workerDir = $this->workerDir; return ArrayCollection::create(file(__DIR__ . '/process_list.txt'))->map(function ($line) use($workerDir) { return str_replace('{WORKER_DIR}', $workerDir, $line); }); }
/** * Reads the composer lock file based on the project directory * and parses the version for the specified package name. * * @param string $packageName * @param string $projectDir * * @return null|string */ protected static function findPackageVersion($packageName, $projectDir) { if ($packageName === null || $projectDir === null) { return null; } $composerFile = file_exists("{$projectDir}/vendor") ? "{$projectDir}/composer.lock" : "{$projectDir}/../../../composer.lock"; if (!file_exists($composerFile)) { return null; } $composer = json_decode(file_get_contents($composerFile), true); $packages = ArrayCollection::create($composer['packages'])->filter(function ($package) use($packageName) { return $package['name'] === $packageName; }); if ($packages->isEmpty()) { return null; } $package = ArrayCollection::create($packages->first()); $version = ltrim($package->get('version'), 'v'); return $version; }
public function statsAllTubes() { $stats = new ArrayCollection(); foreach ($this->tubes as $tube) { $stats->set($tube, $this->statsTube($tube)); } return $stats; }
private function assertCollection($expected, ArrayCollection $actual) { $this->assertSame($expected, $actual->toArray()); }
/** * @param ArrayCollection|Traversable|array|stdClass $collection * @return array */ protected static function normalize($collection) { if ($collection instanceof ArrayCollection) { return $collection->toArray(); } elseif ($collection instanceof Traversable) { return iterator_to_array($collection, true); } elseif ($collection === null) { return array(); } elseif (is_scalar($collection)) { return array($collection); } elseif ($collection instanceof stdClass) { return get_object_vars($collection); } else { return $collection; } }
public function listTubes() { $tubes = ArrayCollection::create($this->pheanstalk->listTubes())->sortValues(); $tubes->removeElement(Pheanstalk\PheanstalkInterface::DEFAULT_TUBE); return $tubes; }
protected function isTraversable($key) { return $this->doExists($key) && ArrayCollection::isTraversable($this->data[$key]); }
/** * @inheritdoc * @return Job */ public function removeLast() { return parent::removeLast(); }
protected static function doSetConfig() { $file = Path::truePath(static::setConfigFile(), static::getProjectDir()); if (!file_exists($file)) { throw new ConfigException("Config file doesn't exist"); } $type = pathinfo($file, PATHINFO_EXTENSION); if ($type === "ini") { static::$config = parse_ini_file($file, true); static::$configFileType = "ini"; } elseif ($type === "json") { static::$config = json_decode(file_get_contents($file), true); static::$configFileType = "json"; } elseif ($type === 'yml') { static::$config = Yaml::parse(file_get_contents($file)); static::$configFileType = "yaml"; } else { throw new ConfigException("Unknown config file format"); } if (!static::$config) { throw new ConfigException("Unable to parse {$type} file: {$file}"); } static::$config = ArrayCollection::createRecursive(static::$config); }