freenet-router |
Subversion Repositories: |
Compare with Previous - Blame - Download
<?php
namespace Phem\Libraries\UI\Model;
use Doctrine\Common\Annotations\AnnotationReader;
use Phem\Core\Collection;
use Phem\Core\Object;
use Phem\Environment\EnvironmentManager;
use Phem\Libraries\UI\Annotations\ContentAttr;
use Phem\Libraries\UI\Annotations\DomAttr;
use Phem\Libraries\UI\Annotations\NoUpdateAttr;
use Phem\Libraries\UI\Annotations\StyleAttr;
use Phem\ToolSuite;
use Ratchet\Wamp\Exception;
use ReflectionProperty;
/**
* @author Jakub PetrĹžĂlka <petrzilka@czweb.net>
*/
abstract class Control extends Component
{
protected $name;
protected $id;
protected $classes;
protected $parent;
/**
* @var Position
*/
protected $position;
/**
* @var Size
*/
protected $size;
public abstract function getValue();
protected abstract function setValue($value);
function __construct($parent)
{
$this->parent = $parent;
$this->position = new Position();
$this->size = new Size();
$this->classes = new Collection();
}
/* public function __call($method, $args)
{
if(method_exists($this, $method))
{
call_user_func_array(array($this,$method), $args);
if ((ToolSuite::startsWith($method, 'set') !== false)&&($method != "setValue"))
{
$attrName = lcfirst(substr($method, 3));
$reflectionProp = new ReflectionProperty($this,$attrName);
$annotationReader = new AnnotationReader();
$propAnnotations = $annotationReader
->getPropertyAnnotations($reflectionProp);
$foundAnnotations = new Collection();
foreach ($propAnnotations as $annotation)
{
if (($annotation instanceof NoUpdateAttr)
||($annotation instanceof DomAttr)
||($annotation instanceof ContentAttr)
||($annotation instanceof StyleAttr))
{
$foundAnnotations->add($annotation);
}
}
if ($foundAnnotations->count() > 1)
{
throw new Exception(get_class($this) . "::" . $method .
"() - attribute must have either 0 or 1 annotation from NoUpdateAttr, DomAttr, ContentAttr, StyleAttr");
}
else if ($foundAnnotations->count() == 1)
{
$annotation = $foundAnnotations->getFirst();
if ($annotation instanceof NoUpdateAttr)
{
return;
}
$change = new Change();
$change->setAttrName($annotation->name);
$change->setData($args[0]);
$change->setObjectName($this->getFullName());
if ($annotation instanceof StyleAttr)
{
$change->setType(ChangeType::CHANGE_STYLE);
}
else if ($annotation instanceof DomAttr)
{
$change->setType(ChangeType::CHANGE_ATTR);
}
else if ($annotation instanceof ContentAttr)
{
$change->setType(ChangeType::UPDATE_CONTENT);
}
}
else
{
$twig = EnvironmentManager::getTwig();
$data = $twig->render('@Phem/UI/' . $this->getType() . '.twig',array("control"=>$this));
$change = new Change();
$change->setType(ChangeType::REPLACE);
$change->setData($data);
$change->setObjectName($this->getFullName());
}
$this->getWorkspace()->getChanges()->put($this->getFullName()."_".$attrName,$change);
}
}
} */
public function getType()
{
return ToolSuite::getRelativeClassName($this);
}
public function getTemplateName()
{
return $this->getType();
}
public function getWorkspace()
{
$parent = $this;
while (!is_a($parent, '\Phem\Libraries\UI\Model\Workspace'))
{
$parent = $parent->getParent();
}
return $parent;
}
public function getName()
{
return $this->name;
}
protected function setName($name)
{
$this->name = $name;
}
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getClasses()
{
return $this->classes;
}
public function setClasses($classes)
{
$this->classes = $classes;
}
public function getPosition()
{
return $this->position;
}
protected function setPosition(Position $position)
{
$this->position = $position;
}
public function getSize()
{
return $this->size;
}
protected function setSize(Size $size)
{
$this->size = $size;
}
public function getParent()
{
return $this->parent;
}
}