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
<?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\Zamm\Helpers\InlineWrapper;
use Maslosoft\Zamm\Interfaces\SourceAccessorInterface;
use Maslosoft\Zamm\Traits\SourceMagic;
use ReflectionClass;
/**
* This simply return names of methods and properties.
* This is helper for IDE's.
* Use this together with @var type hint.
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Namer implements SourceAccessorInterface
{
use SourceMagic;
/**
* Working class name
* @var string
*/
protected $className = '';
protected $info = null;
/**
*
* @var ApiUrl
*/
protected $link = null;
public function __construct($className = null)
{
assert(!empty($className), static::class . ' requires existing class name as a constructor parameter');
$this->className = $className;
$this->info = new ReflectionClass($this->className);
$this->link = new ApiUrl($className);
}
/**
* Set wrapper defaults
* @return InlineWrapper
*/
public static function defaults()
{
return InlineWrapper::defaults();
}
public function __get($name)
{
// This is to get class name formatted, without invoking property()
if ($name === 'md' || $name === 'html' || $name === 'short')
{
if (!$this->info->hasProperty($name))
{
return (new InlineWrapper($this->_type(), (string) $this->link, $this->getTitle()))->$name;
}
}
return $this->_get($name);
}
/**
*
* @param string $name
* @return InlineWrapper
*/
public function method($name)
{
assert($this->info->hasMethod($name), "Tried to get non existing method: `$name` info of " . $this->_type());
$link = $this->link->method($name);
return new InlineWrapper($this->_method($name), $link, $this->getTitle("$name()"));
}
protected function _method($name)
{
return sprintf('%s::%s()', $this->className, $name);
}
/**
*
* @param string $name
* @return InlineWrapper
*/
public function property($name)
{
// Workaround for __getting html link for type.
// Should be trapped in __get, but it doesn't always do.
if ($name === 'md' || $name === 'html' || $name === 'short')
{
if (!$this->info->hasProperty($name))
{
return (new InlineWrapper($this->_type(), (string) $this->link, $this->getTitle()))->$name;
}
}
assert($this->info->hasProperty($name));
$link = $this->link->property($name);
return new InlineWrapper($this->_property($name), $link, $this->getTitle($name));
}
protected function _property($name)
{
return sprintf('%s::%s', $this->className, $name);
}
public static function __callStatic($name, $arguments)
{
return new InlineWrapper(sprintf('%s', $name));
}
protected function _type()
{
return $this->className;
}
public function __toString()
{
$link = (string) $this->link;
return (string) new InlineWrapper($this->_type(), $link, $this->getTitle());
}
private function getTitle($name = '')
{
if (!empty($name))
{
return sprintf('%s::%s', $this->info->name, $name);
}
return $this->info->name;
}
}
API documentation generated by ApiGen