Maslosoft Zamm API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/zamm
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/zamm/
*/
namespace Maslosoft\Zamm;
use Maslosoft\EmbeDi\EmbeDi;
use Maslosoft\Zamm\Interfaces\ConverterInterface;
use Maslosoft\Zamm\Converters\PhpConverter;
use Maslosoft\Zamm\Decorators\StarRemover;
use Maslosoft\Zamm\Extractors\AddendumExtractor;
use Maslosoft\Zamm\Interfaces\Extractors\ExtractorInterface;
use Maslosoft\Zamm\Extractors\NullExtractor;
use Maslosoft\Zamm\Interfaces\FileDecoratorInterface;
use Maslosoft\Zamm\FileDecorators\IgnoreFileDecorator;
use Maslosoft\Zamm\FileDecorators\MadeByFileDecorator;
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface;
use Maslosoft\Zamm\Outputs\FileOutput;
use Maslosoft\Zamm\Interfaces\OutputInterface;
use Maslosoft\Zamm\Renderers\ClassRenderer;
use Maslosoft\Zamm\Interfaces\Renderers\ClassRendererInterface;
use Maslosoft\Zamm\Interfaces\Renderers\MethodRendererInterface;
use Maslosoft\Zamm\Interfaces\Renderers\PropertyRendererInterface;
use Maslosoft\Zamm\Interfaces\Renderers\RendererInterface;
use Maslosoft\Zamm\Renderers\MethodRenderer;
use Maslosoft\Zamm\Renderers\PropertyRenderer;
/**
* Zamm: PHP Doc extractor for code fragments
* This class allows extracting code fragments into documentation.
* It is designed to be IDE friendly. It should autocomplete and automatically reflect code refactors if properly used.
* This documentation is also processed with Zamm.
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Zamm implements SourceAccessorInterface
{
use Traits\SourceMagic;
/**
* @deprecated
* TODO See if it's used somewhere
*/
const Version = '1.0.0';
const MadeBy = 'Generated by Maslosoft Zamm';
const DefaultInstanceId = 'zamm';
/**
* Input for documentation
* Array of folders and files to process.
* @var string[]
*/
public $input = [
'docs'
];
public $output = [
];
/**
* Configuration of decorators.
* This should be array with keys of renderer interface names and values of decorator classes.
* @var string[][]
*/
public $decorators = [
// All around decorators
RendererInterface::class => [
StarRemover::class
],
// Class decorators
ClassRendererInterface::class => [
],
// Property decorators
PropertyRendererInterface::class => [
],
// Method decorators
MethodRendererInterface::class => [
],
];
/**
* Configuration of file decorators.
* This should be array with keys of converter names and values of file decorator classes.
* @var string[][]
*/
public $fileDecorators = [
// All file decorators
FileDecoratorInterface::class => [
MadeByFileDecorator::class
],
// PHP converter decorators
PhpConverter::class => [
IgnoreFileDecorator::class
]
];
/**
* Converters
* Array of class names of converters. These will be applied in order specified here, to all files.
* All converters should implement `IConverter` interface.
* @see ConverterInterface
* @var string[]
*/
public $converters = [
PhpConverter::class
];
/**
* Outputs classes
* Array of class names of outputs. These will be applied in order specified here, to all files.
* All outputs should implement `IOutput` interface.
* @see OutputInterface
* @var string[]
*/
public $outputs = [
FileOutput::class
];
/**
* Extractor class name.
* This class will be used to extract source fragments. Defaults to `AddendumExtractor`.
* It implements `IExtractor` interface.
* @see AddendumExtractor
* @see ExtractorInterface
* @var string
*/
public $extractor = AddendumExtractor::class;
/**
* Extractor instance
* @var ExtractorInterface
*/
private $_extractor = null;
/**
* Working class name
* @var string|null
*/
private $_className = '';
/**
* EmbeDi instance
* @var EmbeDi
*/
private $_di = null;
public function __construct($className = null)
{
$this->_className = $className;
$this->_di = new EmbeDi(self::DefaultInstanceId);
$this->_di->configure($this);
}
public function init()
{
$this->_di->store($this);
}
public function methods()
{
/**
* TODO Return all method names
*/
}
public function properties()
{
/**
* TODO Return all property names
*/
}
public function method($name)
{
return new MethodRenderer($this->getExtractor(), $name);
}
public function property($name)
{
return new PropertyRenderer($this->getExtractor(), $name);
}
public function setExtractor(ExtractorInterface $extractor)
{
$this->_extractor = $extractor;
}
public function getExtractor()
{
if (null === $this->_extractor)
{
if (!$this->_className)
{
$extractorClass = NullExtractor::class;
}
else
{
$extractorClass = $this->extractor;
}
$extractor = new $extractorClass();
$extractor->setClassName($this->_className);
$this->_extractor = $extractor;
}
return $this->_extractor;
}
public static function __callStatic($name, $arguments)
{
$className = get_called_class();
return new MethodRenderer((new Zamm($className))->getExtractor(), $name);
}
/**
*
* @return ClassRenderer
*/
public function __toString()
{
return (string) new ClassRenderer($this->getExtractor());
}
}
API documentation generated by ApiGen