public function entity($path = null)
    {
        if ($path === null) {
            return $this->_context['entity'];
        }

        $oneElement = count($path) === 1;
        if ($oneElement && $this->_isCollection) {
            return false;
        }
        $entity = $this->_context['entity'];
        if ($oneElement) {
            return $entity;
        }

        if ($path[0] === $this->_rootName) {
            $path = array_slice($path, 1);
        }

        $len = count($path);
        $last = $len - 1;
        for ($i = 0; $i < $len; $i++) {
            $prop = $path[$i];
            $next = $this->_getProp($entity, $prop);
            $isLast = ($i === $last);

            if (!$isLast && $next === null && $prop !== '_ids') {
                $table = $this->_getTable($path);

                return $table->newEntity();
            }

            $isTraversable = (
                is_array($next) ||
                $next instanceof Traversable ||
                $next instanceof EntityInterface
            );
            if ($isLast || !$isTraversable) {
                return $entity;
            }
            $entity = $next;
        }
        throw new RuntimeException(sprintf(
            'Unable to fetch property "%s"',
            implode('.', $path)
        ));
    }
public function entity($path = null)
    {
        if ($path === null) {
            return $this->_context['entity'];
        }

        $oneElement = count($path) === 1;
        if ($oneElement && $this->_isCollection) {
            return false;
        }
        $entity = $this->_context['entity'];
        if ($oneElement) {
            return $entity;
        }

        if ($path[0] === $this->_rootName) {
            $path = array_slice($path, 1);
        }

        $len = count($path);
        $last = $len - 1;
        for ($i = 0; $i < $len; $i++) {
            $prop = $path[$i];
            $next = $this->_getProp($entity, $prop);
            $isLast = ($i === $last);

            if (!$isLast && $next === null && $prop !== '_ids') {
                $table = $this->_getTable($path);

                return $table->newEntity();
            }

            $isTraversable = (
                is_array($next) ||
                $next instanceof Traversable ||
                $next instanceof EntityInterface
            );
            if ($isLast || !$isTraversable) {
                return $entity;
            }
            $entity = $next;
        }
        throw new RuntimeException(sprintf(
            'Unable to fetch property "%s"',
            implode('.', $path)
        ));
    }
public function entity ( $ path = null ) { if ( $ path === null ) { return $ this -> _context [ 'entity' ] ; } $ oneElement = count ( $ path ) === 1 ; if ( $ oneElement && $ this -> _isCollection ) { return false ; } $ entity = $ this -> _context [ 'entity' ] ; if ( $ oneElement ) { return $ entity ; } if ( $ path [ 0 ] === $ this -> _rootName ) { $ path = array_slice ( $ path , 1 ) ; } $ len = count ( $ path ) ; $ last = $ len - 1 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ prop = $ path [ $ i ] ; $ next = $ this -> _getProp ( $ entity , $ prop ) ; $ isLast = ( $ i === $ last ) ; if ( ! $ isLast && $ next === null && $ prop !== '_ids' ) { $ table = $ this -> _getTable ( $ path ) ; return $ table -> newEntity ( ) ; } $ isTraversable = ( is_array ( $ next ) || $ next instanceof Traversable || $ next instanceof EntityInterface ) ; if ( $ isLast || ! $ isTraversable ) { return $ entity ; } $ entity = $ next ; } throw new RuntimeException ( sprintf ( 'Unable to fetch property "%s"' , implode ( '.' , $ path ) ) ) ; }
Fetch the leaf entity for the given path.

This method will traverse the given path and find the leaf
entity. If the path does not contain a leaf entity false
will be returned.

@param array|null $path Each one of the parts in a path for a field name
or null to get the entity passed in constructor context.
@return \Cake\Datasource\EntityInterface|\Traversable|array|bool
@throws \RuntimeException When properties cannot be read.
Fetch the leaf entity for the given path .