Exemple #1
0
 public function test_does_not_contain()
 {
     $this->assertFalse(Str::contains("this", "q"));
     $this->assertFalse(Str::contains("this", "qthis"));
     $this->assertFalse(Str::contains("this", "thisq"));
     $this->assertFalse(Str::contains("this", "THIS"));
 }
Exemple #2
0
 protected static function convertToType($value)
 {
     if (is_numeric($value)) {
         if (Str::contains($value, '.')) {
             return floatval($value);
         }
         return intval($value);
     }
     return $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);
 }
Exemple #4
0
 /**
  * Additional functionality:
  * One or more strings can be passed in to match to tube name
  *
  * @param string|string[]|callable|null $p
  * @return static
  */
 public function filter($p)
 {
     if (is_string($p)) {
         $p = array($p);
     }
     if (is_array($p)) {
         $terms = $p;
         $p = function (Tube $tube) use($terms) {
             foreach ($terms as $term) {
                 if (Str::contains($tube->name(), $term, false)) {
                     return true;
                 }
             }
             return false;
         };
     }
     return parent::filter($p);
 }
Exemple #5
0
 /**
  * Get a collection of {@see WorkerInfo}'s that implement {@see WorkerInterface}
  * @param null|string|array $filter [optional] worker(s) filter
  * @return WorkerInfo[]|ArrayCollection
  */
 public function getWorkers($filter = null)
 {
     $processes = $this->processor->grepForPids(sprintf('runner \\"%s\\"', $this->getWorkerDir()));
     return $this->getWorkerInfoList()->map(function (WorkerInfo $worker) use($processes) {
         foreach ($processes as $process) {
             if ($worker->getFullyQualifiedName() === $process[0]) {
                 $worker->addPid($process[1]);
             }
         }
         return $worker;
     })->filter(function (WorkerInfo $worker) use($filter) {
         if (!$filter) {
             return true;
         }
         if (!is_array($filter)) {
             $filter = array($filter);
         }
         foreach ($filter as $f) {
             if (Str::contains($worker->getName(), $f, false)) {
                 return true;
             }
         }
         return false;
     });
 }
Exemple #6
0
 public static function isAbsolute($path)
 {
     return substr($path, 0, 1) === "/" && !Str::contains($path, './') && !Str::contains($path, '..');
 }