private function findTableName()
 {
     $reader = new DocBlockReader($this->model);
     if ($reader->getParameter("Table")) {
         return $reader->getParameter("Table")[0];
     }
     return str_replace('\\', '_', $this->model);
 }
Example #2
0
 public function isValid(array $_repositoryList = null)
 {
     $reflectionClass = new \ReflectionClass(get_class($this));
     $properties = $reflectionClass->getProperties();
     foreach ($properties as $property) {
         $reader = new DocBlockReader($property->class, $property->name, 'property');
         $property->setAccessible(true);
         $value = $property->getValue($this);
         foreach ($reader->getParameters() as $name => $parameter) {
             //Validate against validation classes
             $validationClass = '\\annotation\\validators\\' . $name;
             if (class_exists($validationClass)) {
                 if (is_array($parameter)) {
                     $validator = new $validationClass(...$parameter);
                 } else {
                     $validator = new $validationClass($parameter);
                 }
                 /** @var $validator \annotation\validation\Validation */
                 if (!$validator->Validate($value) && !($name == 'Required' && $reader->getParameter('Default'))) {
                     $this->_modelErrors[$property->name][$name] = $validator->GetMessage();
                 }
             }
             if ($_repositoryList != null) {
                 switch ($name) {
                     case 'Unique':
                     case 'Primary':
                         foreach ($_repositoryList as $item) {
                             if ($this != $item) {
                                 if ($value == $property->getValue($item)) {
                                     $message = $parameter;
                                     if (is_array($parameter)) {
                                         $message = $message[0];
                                     }
                                     $this->_modelErrors[$property->name][$name] = $message;
                                 }
                             }
                         }
                         break;
                 }
             }
         }
     }
     if (count($this->_modelErrors)) {
         return $this->_modelErrors;
     }
     return true;
 }
Example #3
0
 private function saveExternalAttributes($model)
 {
     $reader = new DocBlockReader($this->model);
     if ($reader->getParameter("ManyToMany")) {
         $relationship = $reader->getParameter("ManyToMany");
         if (is_array($relationship)) {
             $class = $relationship[0];
             $ownProperty = $relationship[1];
             $table = $relationship[2];
             $foreignPrimarykey = self::$defaultPrimaryKey;
             $foreignReader = new \ReflectionClass($class);
             foreach ($foreignReader->getProperties() as $property) {
                 $foreignDocBlock = new DocBlockReader($class, $property->name, 'property');
                 if ($foreignDocBlock->getParameter("Primary")) {
                     $foreignPrimarykey = $property->name;
                 }
             }
             $this->deleteExternalAttributes($model);
             $stmt = $this->db->prepare("INSERT INTO user_ip (" . self::getShortClassName($class) . ", " . self::getShortClassName($this->model) . ") VALUES(?,?)");
             $rfProperty = new \ReflectionProperty($this->model, $ownProperty);
             $rfProperty->setAccessible(true);
             foreach ($rfProperty->getValue($model) as $foreignObject) {
                 $foreignId = $foreignReader->getProperty($foreignPrimarykey);
                 $foreignId->setAccessible(true);
                 $stmt->execute(array($foreignId->getValue($foreignObject), $this->getPrimaryValue($model)));
             }
         }
     }
 }