/**
  * @param  string     $name
  * @param  array      $arguments
  * @return mixed
  * @throws \Exception
  */
 private function __handleCall($name, array $arguments)
 {
     if (false === $this->__initProps) {
         $this->__initProps = true;
         $this->_initProps();
     }
     // needed by twig, cause it tries to call a method with the property name
     if (property_exists($this, $name)) {
         $method = Get::PREFIX . ucfirst($name);
         return $this->{$method}();
     }
     foreach (AccessorRegistry::getAccessors() as $prefix => $accessor) {
         if (strpos($name, $prefix) === 0) {
             $property = lcfirst(substr($name, strlen($prefix)));
             if (isset($this->__props[$property])) {
                 $prop = $this->__props[$property];
                 if ($prop->hasMethod($prefix)) {
                     return $accessor->callback(new CallbackBag($prop, $this, $this->{$property}, $arguments));
                 }
             }
         }
     }
     throw new \Exception('Call to undefined method ' . __CLASS__ . '::' . $name . '()');
 }
 public function testRegistryOverride()
 {
     $this->setExpectedException('Exception', 'Override Accessor is not allowed, to enhance stability!');
     AccessorRegistry::registerAccessor(new Get());
 }
示例#3
0
<?php

$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->setPsr4('Saxulum\\Tests\\Accessor\\', __DIR__);
\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
use Saxulum\Accessor\AccessorRegistry;
use Saxulum\Accessor\Accessors\Add;
use Saxulum\Accessor\Accessors\Get;
use Saxulum\Accessor\Accessors\Is;
use Saxulum\Accessor\Accessors\Remove;
use Saxulum\Accessor\Accessors\Set;
AccessorRegistry::registerAccessor(new Add());
AccessorRegistry::registerAccessor(new Get());
AccessorRegistry::registerAccessor(new Is());
AccessorRegistry::registerAccessor(new Remove());
AccessorRegistry::registerAccessor(new Set());
示例#4
0
 /**
  * @param  string $namespace
  * @return string
  */
 public function generatePhpDoc($namespace)
 {
     $phpdoc = '';
     foreach ($this->accessorPrefixes as $accessorPrefix) {
         $accessor = AccessorRegistry::getAccessor($accessorPrefix);
         $phpdoc .= $accessor->generatePhpDoc($this, $namespace) . "\n";
     }
     return $phpdoc;
 }