Пример #1
0
 /**
  * @param $className
  * @return Entity
  */
 function fromClass($className)
 {
     if (!isset($this->metas[$className])) {
         $this->metas[$className] = Entity::fromClass($this->reader, $className, $this);
     }
     return $this->metas[$className];
 }
Пример #2
0
 /**
  * @param string $property
  * @return string
  * @throws Exception
  */
 private function getSearchableProperty($property)
 {
     $property = Meta\Reflection::singularizeProperty($property);
     foreach ($this->meta->getIndexedProperties() as $p) {
         if (Meta\Reflection::singularizeProperty($p->getName()) == $property) {
             return $property;
         }
     }
     throw new Exception("Property {$property} is not indexed.");
 }
Пример #3
0
 /**
  * @param EntityManager $entityManager
  * @param Meta\Entity $meta
  */
 public function __construct(EntityManager $entityManager, Meta\Entity $meta)
 {
     $this->entityManager = $entityManager;
     $this->class = $meta->getName();
     $this->meta = $meta;
 }
Пример #4
0
    /**
     * @param ReflectionMethod $method
     * @param Meta $meta
     * @return string
     */
    private function methodProxy(ReflectionMethod $method, Meta $meta)
    {
        $property = $meta->findProperty($method->getName());
        if (!$property) {
            // No need for a proxy if not related to a property
            return null;
        }
        if ($property->isProperty()) {
            // Properties are loaded straight-up, no need for proxies
            return null;
        }
        $parts = array();
        $arguments = array();
        foreach ($method->getParameters() as $parameter) {
            $variable = '$' . $parameter->getName();
            $parts[] = $variable;
            $arg = $variable;
            if ($parameter->isOptional()) {
                $arg .= ' = ' . var_export($parameter->getDefaultValue(), true);
            }
            if ($parameter->isPassedByReference()) {
                $arg = "& {$arg}";
            } elseif ($c = $parameter->getClass()) {
                $arg = $c->getName() . ' ' . $arg;
            }
            if ($parameter->isArray()) {
                $arg = "array {$arg}";
            }
            $arguments[] = $arg;
        }
        $parts = implode(', ', $parts);
        $arguments = implode(', ', $arguments);
        $name = var_export($method->getName(), true);
        $propertyName = var_export($property->getName(), true);
        return <<<FUNC

    function {$method->getName()}({$arguments})
    {
        self::__loadProperty({$name}, {$propertyName});
        return parent::{$method->getName()}({$parts});
    }

FUNC;
    }