You are here

public static function ClosureExpressionVisitor::getObjectFieldValue in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php \Doctrine\Common\Collections\Expr\ClosureExpressionVisitor::getObjectFieldValue()

Accesses the field of a given object. This field has to be public directly or indirectly (through an accessor get*, is*, or a magic method, __get, __call).

Parameters

object $object:

string $field:

Return value

mixed

2 calls to ClosureExpressionVisitor::getObjectFieldValue()
ClosureExpressionVisitor::sortByField in vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php
Helper for sorting arrays of objects based on multiple fields + orientations.
ClosureExpressionVisitor::walkComparison in vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php
Converts a comparison expression into the target query language output.

File

vendor/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php, line 43

Class

ClosureExpressionVisitor
Walks an expression graph and turns it into a PHP closure.

Namespace

Doctrine\Common\Collections\Expr

Code

public static function getObjectFieldValue($object, $field) {
  if (is_array($object)) {
    return $object[$field];
  }
  $accessors = array(
    'get',
    'is',
  );
  foreach ($accessors as $accessor) {
    $accessor .= $field;
    if (!method_exists($object, $accessor)) {
      continue;
    }
    return $object
      ->{$accessor}();
  }

  // __call should be triggered for get.
  $accessor = $accessors[0] . $field;
  if (method_exists($object, '__call')) {
    return $object
      ->{$accessor}();
  }
  if ($object instanceof \ArrayAccess) {
    return $object[$field];
  }
  return $object->{$field};
}