private function renderIncludeForContent(Content $content, $fileName, $parameters)
    {
        $directory       = dirname($fileName);
        $baseName        = basename($fileName);
        $realContentPath = realpath($this->contentPath);

        // Including a file from current directory
        if($directory == '.')
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . dirname($content->getPath()));
        }
        // Include a file based on relative path
        elseif($directory[0] == '.')
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . dirname($content->getPath()) . DIRECTORY_SEPARATOR . $directory);
        }
        // Including a file based on absolute path
        else
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . $directory);
        }

        if(strcmp($realContentPath, $realDirectory) <= 0)
        {
            $fullPath = $realDirectory . DIRECTORY_SEPARATOR . $baseName;
            if(file_exists($fullPath))
            {
                $type = pathinfo($fullPath, PATHINFO_EXTENSION);
                return $this->render(new Content($type, substr($fullPath, strlen($realContentPath))), $parameters);
            }

            throw new \InvalidArgumentException("Include file [$fullPath] does not exist.");
        }

        throw new \InvalidArgumentException($content->getPath() . "Unable to render [$realDirectory/$fileName]. It is outside of allowed content root path [$realContentPath].");
    }
private function renderIncludeForContent(Content $content, $fileName, $parameters)
    {
        $directory       = dirname($fileName);
        $baseName        = basename($fileName);
        $realContentPath = realpath($this->contentPath);

        // Including a file from current directory
        if($directory == '.')
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . dirname($content->getPath()));
        }
        // Include a file based on relative path
        elseif($directory[0] == '.')
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . dirname($content->getPath()) . DIRECTORY_SEPARATOR . $directory);
        }
        // Including a file based on absolute path
        else
        {
            $realDirectory = realpath($this->contentPath . DIRECTORY_SEPARATOR . $directory);
        }

        if(strcmp($realContentPath, $realDirectory) <= 0)
        {
            $fullPath = $realDirectory . DIRECTORY_SEPARATOR . $baseName;
            if(file_exists($fullPath))
            {
                $type = pathinfo($fullPath, PATHINFO_EXTENSION);
                return $this->render(new Content($type, substr($fullPath, strlen($realContentPath))), $parameters);
            }

            throw new \InvalidArgumentException("Include file [$fullPath] does not exist.");
        }

        throw new \InvalidArgumentException($content->getPath() . "Unable to render [$realDirectory/$fileName]. It is outside of allowed content root path [$realContentPath].");
    }
private function renderIncludeForContent ( Content $ content , $ fileName , $ parameters ) { $ directory = dirname ( $ fileName ) ; $ baseName = basename ( $ fileName ) ; $ realContentPath = realpath ( $ this -> contentPath ) ; // Including a file from current directory if ( $ directory == '.' ) { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . dirname ( $ content -> getPath ( ) ) ) ; } // Include a file based on relative path elseif ( $ directory [ 0 ] == '.' ) { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . dirname ( $ content -> getPath ( ) ) . DIRECTORY_SEPARATOR . $ directory ) ; } // Including a file based on absolute path else { $ realDirectory = realpath ( $ this -> contentPath . DIRECTORY_SEPARATOR . $ directory ) ; } if ( strcmp ( $ realContentPath , $ realDirectory ) <= 0 ) { $ fullPath = $ realDirectory . DIRECTORY_SEPARATOR . $ baseName ; if ( file_exists ( $ fullPath ) ) { $ type = pathinfo ( $ fullPath , PATHINFO_EXTENSION ) ; return $ this -> render ( new Content ( $ type , substr ( $ fullPath , strlen ( $ realContentPath ) ) ) , $ parameters ) ; } throw new \ InvalidArgumentException ( "Include file [$fullPath] does not exist." ) ; } throw new \ InvalidArgumentException ( $ content -> getPath ( ) . "Unable to render [$realDirectory/$fileName]. It is outside of allowed content root path [$realContentPath]." ) ; }
Render a file to include

@param  string $fileName   File name to be rendered from include paths or a relative file name
@param  array  $parameters Parameters from template
@return string rendered include
Render a file to include