Пример #1
0
 public function testUndefinedProperty()
 {
     $this->setExpectedException('\\Stato\\Model\\PropertyMissingException');
     $m = new Metaclass();
     $m->addProperty('foo');
     $m->defineDynamicMethods('getProperty', 'get', '', array('bar'));
 }
Пример #2
0
 public static function setMetaclass(Metaclass $metaclass)
 {
     $metaclass->defineDynamicMethods('getProperty', 'get');
     $metaclass->defineDynamicMethods('setProperty', 'set');
     $metaclass->setModelClass(get_called_class());
     static::getRepository()->addMetaclass($metaclass);
 }
Пример #3
0
 private function constructMetaclass($modelClass, $collectionName, array $options)
 {
     $metaclass = new Metaclass();
     $metaclass->setModelClass($modelClass);
     $metaclass->setStorageName($collectionName);
     if (array_key_exists('properties', $options)) {
         $properties = $options['properties'];
     } else {
         if (!$this->adapter->supportsReflection()) {
             throw new Exception("This adapter does not support reflection ; you must provide a properties array");
         }
         $properties = $this->adapter->reflect($collectionName);
     }
     $include = array_key_exists('include_properties', $options) ? $options['include_properties'] : false;
     $exclude = array_key_exists('exclude_properties', $options) ? $options['exclude_properties'] : array();
     $ref = new ReflectionClass($modelClass);
     foreach ($properties as $property) {
         if (!$ref->hasProperty($property->name)) {
             throw new Exception("Property '{$property->name}' not found in {$modelClass} ; mapping fails");
         }
         if (($include === false || in_array($property->name, $include)) && !in_array($property->name, $exclude)) {
             $metaclass->{$property->name} = $property;
         }
     }
     return $metaclass;
 }