Esempio n. 1
0
 public function __construct($model)
 {
     $this->_model = $model;
     $namespaces = explode('\\', get_called_class());
     $type = Helper::underscore(array_pop($namespaces));
     $properties = get_class_vars(get_class($model));
     if (!empty($properties[$type])) {
         foreach ($properties[$type] as $metadata) {
             $name = array_shift($metadata);
             if (empty($metadata['class'])) {
                 $metadata['class'] = ucfirst(Helper::singularize($name));
             }
             $metadata['class'] = '\\' . ltrim($metadata['class'], '\\');
             $this->_metadata[$name] = $metadata;
         }
     }
 }
Esempio n. 2
0
 public function __call($method, $arguments)
 {
     $this->checkWhetherRecordOperateable();
     if (strpos($method, 'init_') === 0) {
         $relationship = ltrim($method, 'init_');
         $relationshipMetadata = $this->relationship->getMetadata($relationship);
         if ($relationshipMetadata === null) {
             $relationship = Helper::pluralize($relationship);
             $relationshipMetadata = $this->relationship->getMetadata($relationship);
             if ($relationship === null) {
                 throw new UndefinedMethodException($method, get_called_class());
             }
         }
         $this->{$relationship} = new $relationshipMetadata['class']($arguments[0]);
         return true;
     }
     if (preg_match('/_was_changed$/', $method)) {
         $attribute = preg_replace('/_was_changed$/', '', $method);
         if (array_key_exists($attribute, $this->_attributes)) {
             return array_key_exists($attribute, $this->_changedAttributes);
         }
     }
     throw new UndefinedMethodException($method, get_called_class());
 }
Esempio n. 3
0
 public function testUnderscore()
 {
     $this->assertEquals('string_to_underscore', Helper::underscore('string_to_underscore'));
     $this->assertEquals('string_to_underscore', Helper::underscore('StringToUnderscore'));
 }