Maslosoft Addendum 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
<?php
/**
* This software package is licensed under AGPL, Commercial license.
*
* @package maslosoft/addendum
* @licence AGPL, Commercial
* @copyright Copyright (c) Piotr Masełkowski <pmaselkowski@gmail.com> (Meta container, further improvements, bugfixes)
* @copyright Copyright (c) Maslosoft (Meta container, further improvements, bugfixes)
* @copyright Copyright (c) Jan Suchal (Original version, builder, parser)
* @link https://maslosoft.com/addendum/ - maslosoft addendum
* @link https://code.google.com/p/addendum/ - original addendum project
*/
namespace Maslosoft\Addendum;
use Maslosoft\Addendum\Exceptions\CircularReferenceException;
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
use Maslosoft\Addendum\Interfaces\AnnotationInterface;
use Maslosoft\Addendum\Utilities\ConflictChecker;
use Maslosoft\Addendum\Utilities\TargetChecker;
use ReflectionClass;
use ReflectionProperty;
use UnexpectedValueException;
/**
* Modernized Addendum PHP Reflection Annotations
* http://code.google.com/p/addendum/
*
* Copyright (C) 2006-2009 Jan "johno Suchal <johno@jsmf.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* */
abstract class Annotation implements AnnotationInterface
{
use Traits\MetaState;
protected $_properties = [];
protected $_publicProperties = [];
private static $_creationStack = [];
public function __construct($data = [], $target = false)
{
$reflection = new ReflectionClass($this);
$class = $reflection->name;
if (isset(self::$_creationStack[$class]))
{
throw new CircularReferenceException("Circular annotation reference on '$class'", E_USER_ERROR);
}
self::$_creationStack[$class] = true;
foreach ($data as $key => $value)
{
if ($reflection->hasProperty($key))
{
$this->$key = $value;
}
$this->_properties[$key] = $value;
}
foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $field)
{
$this->_publicProperties[] = $field->name;
}
try
{
ConflictChecker::register($this);
TargetChecker::check($this, $target);
}
catch (UnexpectedValueException $ex)
{
throw $ex;
} finally
{
unset(self::$_creationStack[$class]);
}
}
public function getProperties()
{
return $this->_properties;
}
/**
* Init annotation
*/
abstract public function init();
/**
* Convert to array
* @return mixed[]
*/
public function toArray()
{
$result = [];
foreach ($this->_publicProperties as $field)
{
$result[$field] = $this->$field;
}
return $result;
}
}
API documentation generated by ApiGen