コード例 #1
0
ファイル: AbstractStats.php プロジェクト: gmo/beanstalk
 public function __construct($elements = array())
 {
     parent::__construct($elements);
     foreach ($this as $key => $value) {
         $this[$key] = static::convertToType($value);
     }
 }
コード例 #2
0
 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);
 }
コード例 #3
0
ファイル: JobStatsCommand.php プロジェクト: gmo/beanstalk
 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));
     }
 }
コード例 #4
0
ファイル: TwigResponse.php プロジェクト: gmo/common
 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;
 }
コード例 #5
0
ファイル: Job.php プロジェクト: gmo/beanstalk
 /** @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));
     }
 }
コード例 #6
0
ファイル: JobDataSerializer.php プロジェクト: gmo/beanstalk
 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;
 }
コード例 #7
0
ファイル: ServerStatsCommand.php プロジェクト: gmo/beanstalk
 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"}());
     }
 }
コード例 #8
0
ファイル: StatsCommand.php プロジェクト: gmo/beanstalk
    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;
    }
コード例 #9
0
ファイル: WorkerManager.php プロジェクト: gmo/beanstalk
 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();
 }
コード例 #10
0
ファイル: WorkerManagerTest.php プロジェクト: gmo/beanstalk
 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);
     });
 }
コード例 #11
0
ファイル: ConsoleApplication.php プロジェクト: gmo/console
 /**
  * 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;
 }
コード例 #12
0
ファイル: ArrayQueue.php プロジェクト: gmo/beanstalk
 public function statsAllTubes()
 {
     $stats = new ArrayCollection();
     foreach ($this->tubes as $tube) {
         $stats->set($tube, $this->statsTube($tube));
     }
     return $stats;
 }
コード例 #13
0
ファイル: ArrayCollectionTest.php プロジェクト: gmo/common
 private function assertCollection($expected, ArrayCollection $actual)
 {
     $this->assertSame($expected, $actual->toArray());
 }
コード例 #14
0
ファイル: ArrayCollection.php プロジェクト: gmo/common
 /**
  * @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;
     }
 }
コード例 #15
0
ファイル: Queue.php プロジェクト: gmo/beanstalk
 public function listTubes()
 {
     $tubes = ArrayCollection::create($this->pheanstalk->listTubes())->sortValues();
     $tubes->removeElement(Pheanstalk\PheanstalkInterface::DEFAULT_TUBE);
     return $tubes;
 }
コード例 #16
0
ファイル: ArrayPredis.php プロジェクト: gmo/cache
 protected function isTraversable($key)
 {
     return $this->doExists($key) && ArrayCollection::isTraversable($this->data[$key]);
 }
コード例 #17
0
ファイル: JobCollection.php プロジェクト: gmo/beanstalk
 /**
  * @inheritdoc
  * @return Job
  */
 public function removeLast()
 {
     return parent::removeLast();
 }
コード例 #18
0
ファイル: AbstractConfig.php プロジェクト: gmo/common
 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);
 }