/**
  * return the array values that match the search regex
  *
  * @param  array|Traversable $data
  *         the collection of input strings to check
  * @param  string $searchRegex
  *         the regex to match
  * @return array
  *         returns the elements of $data that match the regex
  *         will be an empty array if no matches found
  */
 public static function againstTraversable($data, $searchRegex)
 {
     // robustness!
     RequireTraversable::checkMixed($data, E4xx_UnsupportedType::class);
     RequirePcreRegex::check($searchRegex, E4xx_InvalidPcreRegex::class);
     return self::matchArray($data, $searchRegex);
 }
 /**
  * return the array values that do not contain the search string
  *
  * @param  array|Traversable $data
  *         the collection of input strings to check
  * @param  string $searchString
  *         the string to search for
  * @return array
  *         returns the elements of $data that do not contain $searchString
  *         will be an empty array if no matches found
  */
 public static function againstTraversable($data, $searchString)
 {
     // robustness!
     RequireTraversable::checkMixed($data, E4xx_UnsupportedType::class);
     RequireStringy::checkMixed($searchString, E4xx_UnsupportedType::class);
     return self::matchArray($data, $searchString);
 }
예제 #3
0
 /**
  * expand a list of ranges
  *
  * @param  array|Traversable $data
  *         the list of ranges to expand
  * @return array
  *         the expanded ranges
  */
 public static function fromTraversable($data)
 {
     // robustness!
     RequireTraversable::checkMixed($data, E4xx_UnsupportedType::class);
     $retval = [];
     foreach ($data as $key => $range) {
         $retval[$key] = self::fromString($range);
     }
     return $retval;
 }
예제 #4
0
 /**
  * our constructor
  *
  * @param array<ComparisonExpression> $rangeExpressions
  *        the list of comparison expressions that make up this version range
  */
 public function __construct($rangeExpressions)
 {
     // robustness
     RequireTraversable::check($rangeExpressions, E4xx_UnsupportedType::class);
     $this->rangeExpressions = [];
     foreach ($rangeExpressions as $rangeExpression) {
         RequireObjectOfType::check($rangeExpression, ComparisonExpression::class, E4xx_UnsupportedType::class);
         $this->rangeExpressions[] = $rangeExpression;
     }
 }
 /**
  * write an array of data to the stream
  *
  * @param  array $data
  *         the data to write to the stream
  * @return void
  */
 public function writeArray($data)
 {
     // robustness!
     RequireTraversable::check($data, E4xx_UnsupportedType::class);
     foreach ($data as $item) {
         // we do not know what $item is, so send it to our generic
         // write method
         $this->write($item);
     }
 }
 /**
  * merge their array into our array
  *
  * @param  array &$ours
  *         the array that we want to merge into
  * @param  array|Traversable $theirs
  *         the array that we want to merge from
  * @return void
  */
 public static function fromArray(&$ours, $theirs)
 {
     // robustness!
     RequireIndexable::check($ours, E4xx_UnsupportedType::class);
     RequireTraversable::check($theirs, E4xx_UnsupportedType::class);
     // copy from them to us
     foreach ($theirs as $key => $value) {
         self::mergeKeyIntoArray($ours, $key, $value);
     }
     // all done
 }
 /**
  * create an escaped string from a collection of command + args
  *
  * @param  array|Traversable $data
  *         the data to escape
  * @return string
  *         the command to execute
  */
 public static function fromArray($data)
 {
     // robustness!
     RequireTraversable::checkMixed($data);
     // escape everything
     $retval = [];
     foreach ($data as $part) {
         $retval[] = escapeshellarg((string) $part);
     }
     // all done
     return implode(' ', $retval);
 }
 public function __construct($command, $returnCode, $output)
 {
     // robustness!
     RequireTraversable::checkMixed($command, E4xx_UnsupportedType::class);
     RequireNumeric::check($returnCode, E4xx_UnsupportedType::class);
     RequireStringy::checkMixed($output, E4xx_UnsupportedType::class);
     $this->setCommand($command);
     $this->setReturnCode($returnCode);
     $this->setOutput($output);
     // all done
     $this->makeReadOnly();
 }
 /**
  * run a CLI command using the popen() interface
  *
  * @param  array|Traversable $command
  *         the command to execute
  * @param  int|null $timeout
  *         how long before we force the command to close?
  * @param  string|null $cwd
  *         the folder to run the command inside
  * @param  EventStream $eventStream
  *         helper to send events to
  * @return ProcessResult
  *         the result of executing the command
  */
 public static function run($command, $timeout = null, $cwd = null, EventStream $eventStream = null)
 {
     // robustness
     RequireTraversable::checkMixed($command, E4xx_UnsupportedType::class);
     RequireTimeoutOrNull::check($timeout);
     RequireAbsoluteFolderOrNull::check($cwd);
     $eventStream = GuaranteeEventStream::from($eventStream);
     return self::runCommand($command, $timeout, $cwd, $eventStream);
 }
 /**
  * @covers ::check
  * @covers ::checkMixed
  * @dataProvider provideNonTraversables
  * @expectedException GanbaroDigital\Reflection\Exceptions\E4xx_UnsupportedType
  */
 public function testRejectsNonTraversablesWhenCalledStatically($item)
 {
     // ----------------------------------------------------------------
     // setup your test
     // ----------------------------------------------------------------
     // perform the change
     RequireTraversable::check($item);
 }
 /**
  * extract the columns from an array of strings
  *
  * @param  array|Traversable $data
  *         the data to be filtered
  * @param  string $columnNos
  *         the columns to be extracted
  * @param  string $columnSeparator
  *         the column delimiter
  * @return array
  *         a list of the filtered strings
  */
 public static function fromTraversable($data, $columnNos, $columnSeparator)
 {
     // robustness!
     RequireTraversable::checkMixed($data, E4xx_UnsupportedType::class);
     RequireStringy::checkMixed($columnNos, E4xx_UnsupportedType::class);
     RequireStringy::checkMixed($columnSeparator, E4xx_UnsupportedType::class);
     $colsToMatch = array_flip(ExpandRange::from($columnNos));
     return self::filterArray($data, $columnSeparator, $colsToMatch);
 }