Pinocchio |
|
---|---|
|
|
This file is part of the Pinocchio library. (c) José Nahuel Cuesta Luengo nahuelcuestaluengo@gmail.com For the full copyright and license information, please view the LICENSE file that was distributed with this source code. |
namespace Pinocchio;
|
Pinocchio @author José Nahuel Cuesta Luengo nahuelcuestaluengo@gmail.com |
class Pinocchio
{
|
The path to the source file represented by this object. @var |
protected $path;
|
The source code. This attribute acts as a simple cache. @var |
protected $source;
|
Code blocks in the file represented by this object. @var |
protected $codeBlocks;
|
Documentation blocks in the file represented by this object. @var |
protected $docBlocks;
|
Constructor. @param |
public function __construct($path)
{
$this
->setPath($path)
->setCodeBlocks(array())
->setDocBlocks(array());
}
|
Set the path to the source file. @param @return @throws |
public function setPath($path)
{
if (!is_readable($path)) {
throw new \InvalidArgumentException('The passed path is not readable: ' . $path);
}
$this->path = $path;
$this->source = file_get_contents($path);
return $this;
}
|
Get the path to the source file. @return |
public function getPath()
{
return $this->path;
}
|
Get the source code. @return |
public function getSource()
{
return $this->source;
}
|
Get the code blocks. @return |
public function getCodeBlocks()
{
return $this->codeBlocks;
}
|
Set the code blocks. @param @return |
public function setCodeBlocks($codeBlocks)
{
$this->codeBlocks = $codeBlocks;
return $this;
}
|
Get a code block at a specific offset. @param @return |
public function getCodeBlock($index)
{
return isset($this->codeBlocks[$index]) ? $this->codeBlocks[$index] : '';
}
|
Get the documentation blocks. @return |
public function getDocBlocks()
{
return $this->docBlocks;
}
|
Get a documentation block at a specific offset. @param @return |
public function getDocBlock($index)
{
return isset($this->docBlocks[$index]) ? $this->docBlocks[$index] : '';
}
|
Set the documentation blocks. @param @return |
public function setDocBlocks($docBlocks)
{
$this->docBlocks = $docBlocks;
return $this;
}
|
Add a code block to this object. @param @return |
public function addCodeBlock($codeBlock)
{
$this->codeBlocks[] = $codeBlock;
return $this;
}
|
Add a documentation block to this object. @param @return |
public function addDocBlock($docBlock)
{
$this->docBlocks[] = $docBlock;
return $this;
}
|
Get an @return |
public function getFileInformation()
{
return new \SplFileInfo($this->getPath());
}
|
Get the name for this Pinocchio's output file. @param @return |
public function getOutputFilename($prefix = null)
{
$fileInfo = $this->getFileInformation();
$filename = str_replace('/', '_', $fileInfo->getPathname());
if (null !== $prefix) {
$filename = substr($filename, strlen($prefix));
}
return strtr(ltrim($filename, '_'), array('.' . $fileInfo->getExtension() => '.html'));
}
|
Get the title of this Pinocchio. @return |
public function getTitle()
{
$fileInfo = $this->getFileInformation();
return $fileInfo->getBasename('.' . $fileInfo->getExtension());
}
}
|