Calls an object's method which is inaccessible.

@param $entity
@param string $method

@throws \ReflectionException

@return mixed|null
351379
public function callInaccessibleMethod($entity, string $method)
    {
        $rc = new \ReflectionClass($entity);

        if ($rc->hasMethod($method)) {
            $method = $rc->getMethod($method);
            $method->setAccessible(true);

            return $method->invoke($entity);
        }

        return null;
    }
1142914
public function setObject($object, $method  = null)
    {
        if (! is_object($object)) {
            throw new Exception('not object');
        }
        $ref = new \ReflectionObject($object);
        $file = $ref->getFileName();
        $this->setPath($file);

        return $this;
    }
479666
private function isGetMethod(\ReflectionMethod $method)
    {
        return (
            0 === strpos($method->name, 'get') &&
            3 < strlen($method->name) &&
            0 === $method->getNumberOfRequiredParameters()
        );
    }
1082288
public function callWith($method, $args, $object, $returnRelation = false)
    {
        if (is_string($object)) {
            $object = Reflect::create($object);
        }

        /**
         * Check if $method prefix is listed in autocallPrefixes.
         */
        foreach ($this->autocallPrefixes as $prefix) {
            if (substr($method, 0, strlen($prefix)) === $prefix
                && strtoupper(substr($method, strlen($prefix), 1)) == substr($method, strlen($prefix), 1)
            ) {
                /**
                 * We are calling relation function without arguments: $entity->something();.
                 */
                $relationMethod = lcfirst(substr($method, strlen($prefix)));
                $relation = Reflect::method($object, $relationMethod, $args);
                // $relation = $object->{$relationMethod}();

                if (isset($args[0]) && ($args[0] instanceof Closure || is_only_callable($args[0]))) {
                    /**
                     * If callback was added, we run it.
                     * Now, this is a problem if we're making join because query was already merged.
                     * So, we'll call this magically and provide both - relation and query.
                     *
                     * @T00D00
                     */
                    if (in_array($prefix, ['join', 'leftJoin', 'innerJoin'])) {
                        $rightEntity = $relation->getRightEntity();
                        $oldEntityQuery = $rightEntity->getQuery();
                        $rightEntity->setQuery($relation->getQuery());
                        Reflect::call($args[0], [$relation, $relation->getQuery()]);
                        $rightEntity->setQuery($oldEntityQuery);
                    } else {
                        Reflect::call($args[0], [$relation, $relation->getQuery()]);
                    }
                }

                if ($prefix == 'leftJoin') {
                    $relation->leftJoin();
                }
                /**
                 * We'll call $entity->with($relation), $entity->join($relation) or $entity->required($relation), and return Relation;
                 */
                $return = $object->{$prefix == 'leftJoin' ? 'join' : $prefix}($relation);

                /**
                 * Then we return relation.
                 */
                return $returnRelation
                    ? $relation
                    : $return;
            }
        }

        if (!method_exists($object, $method)) {
            throw new Exception('Method ' . $method . ' does not exist in ' . get_class($object));
        }

        /**
         * Autoprefixes failed, return relation, probably?
         */
        $relation = Reflect::method($object, $method, $args);

        if (isset($args[0]) && ($args[0] instanceof Closure || is_only_callable($args[0]))) {
            Reflect::call($args[0], [$relation, $relation->getQuery()]);
        }

        return $relation;
    }
856938
protected function firstNotNullResult($method)
    {
        $args = func_get_args();

        $method = array_shift($args);

        foreach ($this->candidates as $candidate) {

            $result = call_user_func_array([$candidate, $method], $args);

            if ($result !== null) {
                return $result;
            }

        }

        return null;
    }
174779
public function load(Entity $entity)
    {
        $data = $entity->getRawData();
        if (!is_array($data) || !isset($data[$this->getForeignKey()])) {
            return null;
        }
        /** @var Select $sql */
        $sql = call_user_func_array(
            [$this->getRelatedEntity(), 'find'],
            []
        );
        $pmk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql-> where(
            [
                "{$table}.{$pmk} = :id" => [
                    ':id' => $data[$this->getForeignKey()]
                ]
            ]
        );
        return $sql->first();
    }
243841
public function call(Entity $entity, $name, array $arguments) {
		if(isset($this->calls[$name])) {
			array_unshift($arguments, $entity);
			return call_user_func_array($this->calls[$name], $arguments);
		}
		else {
			foreach($this->callsCatchAll as $behavior) {
				$processed = false;
				$res = call_user_func_array([$behavior, 'callCatchAll'], [$entity, $name, $arguments, &$processed]);
				if($processed)
					return $res;
			}

			throw new \Exception('Method '.$name.' does not exist for entity '.$this->entityClass);
		}
	}
692154
protected function getResults($method)
    {
        if ($this->schema) {
            // set root constraints
            if (isset($this->constraints[$this->root])) {
                $this->constraints[$this->root]($this->eloquentQuery);
            }

            // set eager load constraints
            $this->eloquentQuery->setEagerLoads($this->parseRelationsFromSchema($this->schema, ''));

            // execute query
            $results = $this->eloquentQuery->$method();

            // transform to data transfer objects
            if ($results) {
                $dtos = $results->toDataTransferObject($this->root, $this->schema, $this->transformations);
                
                return [$this->root => $dtos];
            }
        }

        return null;
    }
1168857
public function triggerMethod($method) {
		$result = null;
		// handling actual method
		if (!empty($this->wrapper_methods[$method])) {
			foreach ($this->wrapper_methods[$method] as $k => $v) {
				$result = call_user_func_array($v, [& $this]);
			}
		}
		return $result;
	}
1015977
public function call($method, array $params = array())
    {
        $params = array($this->getSession(), $method, $params);
        return $this->getClient()->call('call', $params);
    }
879144
protected function callWithRelation($method, $args, $entity)
    {
        $relation = $entity->callWith($method, $args, $entity, true);

        if (!$relation && prod()) {
            return null;
        }

        if ($this instanceof Collection) {
            $relation->fillCollection($this);
        } else if ($this instanceof Record) {
            $relation->fillRecord($this);
        }

        return $relation;
    }
935153
public function id($entity)
    {
        $idField = $this->idField();

        if (method_exists($entity, $idField)) {
            return call_user_func([$entity, $idField]);
        } elseif (method_exists($entity, 'get' . ucfirst($idField))) {
            return call_user_func([$entity, 'get' . ucfirst($idField)]);
        }

        throw new \Exception(
            sprintf(
                'You have configured "%s" as id field, not %s public property found nor %s() ' .
                'nor, get%s() methods found', $idField, $idField, $idField, ucfirst($idField)
            )
        );
    }
48909
protected function getProperty($reflectionObject, $entity, $name)
    {
        $property = $reflectionObject->getProperty($name);
        $property->setAccessible(true);
        return $property->getValue($entity);
    }
943434
public function evaluateAnnotation(
        Request $request,
        Annotation $annotation,
        ReflectionMethod $method
    ) {
        /**
         * Annotation is only loaded if is typeof AnnotationEntity.
         */
        if ($annotation instanceof LoadEntity) {

            /**
             * Creating new instance of desired entity.
             */
            $entityNamespace = $this
                ->entityProvider
                ->evaluateEntityNamespace($annotation->getNamespace());

            /**
             * Tries to get a mapped instance of this entity. If not found,
             * return null.
             */
            $entity = $this->evaluateMapping($annotation, $entityNamespace);

            if (!$entity instanceof $entityNamespace) {
                $entity = $this
                    ->entityProvider
                    ->create($annotation);
            }

            /**
             * Persists entity if defined.
             */
            $this->resolvePersist($annotation, $entity);

            /**
             * If is decided this entity has to be persisted into manager.
             */
            $this->evaluateSetters(
                $request->attributes,
                $entity,
                $annotation->getSetters()
            );

            /**
             * Get the parameter name. If not defined, is set as defined in
             * parameters.
             */
            $parameterName = $annotation->getName()
                ?: $this->defaultName;

            $request->attributes->set(
                $parameterName,
                $entity
            );
        }
    }
844635
public function setMethod(string $method): void
    {
        if (!\in_array($method, $this->getAvailableMethods(), true)) {
            throw new SessionException(\sprintf('Method unknowed: %s', $method));
        }

        $this->method = $method;
    }
1324198
public function extract($entity)
    {
        //if entity is required then delete the entity
        $property = $this->getRepository()
                         ->getDescription()
                         ->getProperty($this->_property);
                         
        if ($property->isRequired()) {
            $entity->delete();
        } else {
            $entity->set($this->_property, null);
        }
    }
558325
public function execute($method=null) {
    $isDebugEnabled = $this->logger->isDebugEnabled();
    if ($isDebugEnabled) {
      $this->logger->debug('Executing: '.get_class($this).($method ? '::'.$method: ''));
      $this->logger->debug('Request: '.$this->request);
    }

    // validate controller data
    $validationFailed = false;
    if (!$this->validate()) {
      $validationFailed = true;
    }

    // execute controller logic
    if (!$validationFailed) {
      try {
        $this->doExecute($method);
        $this->endTransaction(true);
      }
      catch (\Exception $ex) {
        if ($ex instanceof ApplicationException) {
          $error = $ex->getError();
          $this->response->addError($error);
          $this->response->setStatus($error->getStatusCode());
        }
        else {
          $this->getLogger()->error($ex);
          $error = ApplicationError::fromException($ex);
          $this->response->addError($error);
          $this->response->setStatus($error->getStatusCode());
        }
        $this->endTransaction(false);
      }
    }

    // return the last error
    $errors = array_merge($this->request->getErrors(), $this->response->getErrors());
    if (sizeof($errors) > 0) {
      $error = array_pop($errors);
      $this->response->setValue('errorCode', $error->getCode());
      $this->response->setValue('errorMessage', $error->getMessage());
      $this->response->setValue('errorData', $error->getData());
      $this->response->setStatus($error->getStatusCode());
    }

    // log errors
    for ($i=0,$count=sizeof($errors); $i<$count; $i++) {
      $error = $errors[$i];
      $message = $error->__toString();
      switch ($error->getLevel()) {
        case ApplicationError::LEVEL_WARNING:
          $this->logger->warn($message);
          break;
        default:
          $this->logger->error($message);
      }
    }

    if ($isDebugEnabled) {
      $this->logger->debug('Response: '.$this->response);
    }
  }