extractExpression() public static method

public static extractExpression ( $selector, $accessPrivate = false )
Beispiel #1
0
 /**
  * Returns comparator which compares objects by using values computed using given expressions.
  * Expressions should comply with format accepted by <code>Functions::extractExpression</code>.
  * Comparator returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
  *
  * @param mixed ...
  * @return callable
  */
 public static function compareBy()
 {
     $expressions = func_get_args();
     $comparators = Arrays::map($expressions, function ($expression) {
         return new EvaluatingComparator(Functions::extractExpression($expression));
     });
     return sizeof($comparators) == 1 ? $comparators[0] : new CompoundComparator($comparators);
 }
Beispiel #2
0
 public function transform(&$results)
 {
     if ($this->field) {
         $fields = FluentArray::from($results)->map(Functions::extractExpression($this->field))->flatten()->filterNotBlank()->toArray();
         $this->transformer->transform($fields);
     } else {
         $this->transformer->transform($results);
     }
 }
 /**
  * Returns comparator which compares objects by using values computed using given expression.
  * Expression should comply with format accepted by <code>Functions::extractExpression</code>.
  * Comparator returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
  *
  * @param $expression
  * @return callable
  */
 public static function compareBy($expression)
 {
     return new EvaluatingComparator(Functions::extractExpression($expression));
 }
Beispiel #4
0
 public function onProperty($property)
 {
     return new ArrayAssert(Arrays::map($this->actual, Functions::extractExpression($property, true)));
 }
Beispiel #5
0
 /**
  * @param $selector
  * @throws Exception
  * @return FluentArray
  */
 public function uniqueBy($selector)
 {
     return $this->toMap(Functions::extractExpression($selector))->values();
 }
Beispiel #6
0
 /**
  * Removes duplicate values from an array. It uses the given expression to extract value that is compared.
  *
  * Example:
  * <code>
  * $a = new stdClass();
  * $a->name = 'bob';
  *
  * $b = new stdClass();
  * $b->name = 'bob';
  *
  * $array = [$a, $b];
  * $result = Arrays::uniqueBy($array, 'name');
  * </code>
  * Result:
  * <code>
  * Array
  * (
  *      [0] => $b
  * )
  * </code>
  *
  * @param array $elements
  * @param $selector
  * @return array
  * @throws Exception
  */
 public static function uniqueBy(array $elements, $selector)
 {
     return array_values(self::toMap($elements, Functions::extractExpression($selector)));
 }
Beispiel #7
0
 /**
  * @return Node[]
  */
 public function getNoHeaderParametersNodes()
 {
     return Arrays::map($this->getNoHeaderParameters(), Functions::extractExpression('getNode()'));
 }
Beispiel #8
0
 /**
  * @test
  */
 public function shouldExtractFieldIfPhpFunctionWithTheSameNameExists()
 {
     //given
     $object = new stdClass();
     $object->date = '2012-05-12';
     //when
     $result = Functions::call(Functions::extractExpression('date'), $object);
     //then
     $this->assertEquals($object->date, $result);
 }