コード例 #1
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;
 }
コード例 #2
0
ファイル: ArrayCollectionTest.php プロジェクト: gmo/common
 public function testCreation()
 {
     $this->assertCollection(array('a', 'b'), new ArrayCollection(array('a', 'b')));
     $this->assertCollection(array('a', 'b'), new ArrayCollection('a', 'b'));
     $this->assertCollection(array('a'), new ArrayCollection('a'));
     $this->assertCollection(array(), new ArrayCollection(null));
     $this->assertCollection(array(), new ArrayCollection());
     $this->assertCollection(array('a', 'b'), ArrayCollection::create(array('a', 'b')));
     $this->assertCollection(array('a', 'b'), ArrayCollection::create('a', 'b'));
     $this->assertCollection(array('a'), ArrayCollection::create('a'));
     $this->assertCollection(array(), ArrayCollection::create(null));
     $this->assertCollection(array(), ArrayCollection::create());
 }
コード例 #3
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"}());
     }
 }
コード例 #4
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;
    }
コード例 #5
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();
 }
コード例 #6
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);
     });
 }
コード例 #7
0
ファイル: Queue.php プロジェクト: gmo/beanstalk
 public function listTubes()
 {
     $tubes = ArrayCollection::create($this->pheanstalk->listTubes())->sortValues();
     $tubes->removeElement(Pheanstalk\PheanstalkInterface::DEFAULT_TUBE);
     return $tubes;
 }
コード例 #8
0
ファイル: ArrayPredis.php プロジェクト: gmo/cache
 public function linsert($key, $whence, $pivot, $value)
 {
     if (!$this->isTraversable($key)) {
         return 0;
     }
     $whence = strtolower($whence);
     $sub = $this->data[$key];
     $index = $sub->indexOf($pivot);
     if ($index === false) {
         return -1;
     }
     if ($whence === 'before') {
         $firstPart = $sub->slice(0, $index);
         $secondPart = $sub->slice($index);
     } else {
         $firstPart = $sub->slice(0, $index + 1);
         $secondPart = $sub->slice($index + 1);
     }
     $this->data[$key] = ArrayCollection::create($firstPart)->add($value)->merge($secondPart);
     return $this->data[$key]->count();
 }
コード例 #9
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;
 }