You are here

public static function ClosureExpressionVisitor::getObjectFieldValue in Plug 7

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 lib/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php
Helper for sorting arrays of objects based on multiple fields + orientations.
ClosureExpressionVisitor::walkComparison in lib/doctrine/collections/lib/Doctrine/Common/Collections/Expr/ClosureExpressionVisitor.php
Converts a comparison expression into the target query language output.

File

lib/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};
}