/**
  * @param string $boxableType name of an IBoxable class
  * @param DBType $dbType type to use to store the value
  */
 function __construct($boxableType, DBType $dbType)
 {
     Assert::isTrue(TypeUtils::isInherits($boxableType, 'IBoxable'));
     $this->boxableType = $boxableType;
     $this->dbType = $dbType;
     parent::__construct($dbType);
 }
 /**
  * All we need to know is the associative entity (the container), because the association
  * is build between this one property and the identifier of the container
  * @throws OrmModelIntegrityException
  */
 function __construct(IQueryable $container, AssociationMultiplicity $multiplicity, AssociationBreakAction $action)
 {
     $identifier = $container->getLogicalSchema()->getIdentifier();
     if (!$identifier) {
         throw new OrmModelIntegrityException('Cannot associate to an entity ' . $container->getLogicalSchema()->getEntityName() . ' without id');
     }
     $this->container = $container;
     Assert::isTrue(TypeUtils::isInherits($identifier->getType(), 'IOrmPropertyReferencable'));
     $this->fkType = $identifier->getType()->getReferenceType($multiplicity);
     $this->multiplicity = $multiplicity;
     $this->action = $action;
 }
예제 #3
0
 /**
  * @return IQueryable
  */
 private static function getQueriable($class)
 {
     if (is_object($class) && $class instanceof IOrmRelated) {
         $class = get_class($class);
     }
     if (is_scalar($class) && TypeUtils::isInherits($class, 'IOrmRelated')) {
         $class = call_user_func(array($class, 'orm'));
     }
     return $class;
 }
 /**
  * Resolution order:
  *  - IDaoRelated (check a class existance within the global scope and withing the domain scope) --> AssociationPropertyType
  *  - IOrmRelated --> CompositionPropertyType
  *  - IOrmPropertyAssignable --> IOrmPropertyAssignable::getOrmProperty()
  *  - IBoxable --> BoxablePropertyType
  *  - DBType
  *  - any type with public ctor
  * @return OrmPropertyType
  */
 private function getPropertyType(SimpleXMLElement $element, AssociationMultiplicity $multiplicity)
 {
     $name = (string) $element['type'];
     $parameters = $this->getTypeParameters($element);
     if ($class = $this->importEntity($name)) {
         // force recursion
         if ($class->hasDao() && $class->getIdentifier()) {
             return new AssociationPropertyType($class, $multiplicity, AssociationBreakAction::cascade());
         } else {
             return new CompositePropertyType($class);
         }
     } else {
         if (DBType::hasMember($name)) {
             $parameters['id'] = $name;
             if (!isset($parameters['nullable'])) {
                 $parameters['nullable'] = $multiplicity->isNullable() ? 'true' : 'false';
             }
             $dbType = $this->makeObject('DBType', $parameters);
             return $dbType->getOrmPropertyType();
         } else {
             if (@class_exists($name, true)) {
                 if (TypeUtils::isInherits($name, 'IDaoRelated')) {
                     return new AssociationPropertyType(call_user_func(array($name, 'orm')), $multiplicity, AssociationBreakAction::cascade());
                 } else {
                     if (TypeUtils::isInherits($name, 'IOrmRelated')) {
                         $orm = call_user_func(array($name, 'orm'));
                         return new CompositePropertyType($orm);
                     } else {
                         if (TypeUtils::isInherits($name, 'IOrmPropertyAssignable')) {
                             return call_user_func(array($name, 'getOrmPropertyType'), $multiplicity);
                         } else {
                             if (TypeUtils::isInherits($name, 'IBoxable')) {
                                 $parameters['id'] = DBType::VARCHAR;
                                 if (!isset($parameters['nullable'])) {
                                     $parameters['nullable'] = $multiplicity->isNullable() ? 'true' : 'false';
                                 }
                                 return new BoxablePropertyType($name, $this->makeObject('DBType', $parameters));
                             } else {
                                 if (TypeUtils::isInherits($name, 'ISqlType')) {
                                     // for RawSqlType
                                     return new PrimitivePropertyType($this->makeObject($name, $parameters));
                                 } else {
                                     if (TypeUtils::isInherits($name, 'OrmPropertyType')) {
                                         // OrmPropertyType with public ctor
                                         return $this->makeObject($name, $parameters);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     throw new OrmModelIntegrityException('Unknown type of ' . (string) $element['name'] . ' property:  ' . $name);
 }
예제 #5
0
 /**
  * Default error handler, that casts covered errors to their appropriate exceptions
  * @return boolean
  */
 function errorHandler($errno, $errstr, $errfile, $errline)
 {
     if (!error_reporting()) {
         return false;
     }
     if (!($errno & $this->mask)) {
         if (!$this->supressUncovered) {
             if ($this->previousErrorHandler) {
                 $args = func_get_args();
                 call_user_func_array($this->prevErrorHandler, $args);
             } else {
                 return false;
             }
         }
         return true;
     }
     if (isset($this->exceptionsTable[$errno])) {
         $exceptionClass = $this->exceptionsTable[$errno];
         Assert::isTrue(TypeUtils::isInherits($exceptionClass, 'IErrorExceptionFactory'));
         $exceptionObject = call_user_func_array(array($exceptionClass, 'makeException'), array($errstr, $errno, $errfile, $errline));
     } else {
         $exceptionObject = null;
     }
     if (!$exceptionObject instanceof Exception) {
         $exceptionClass = $this->defaultException;
         Assert::isTrue(TypeUtils::isInherits($exceptionClass, 'IErrorExceptionFactory'));
         $exceptionObject = call_user_func_array(array($exceptionClass, 'makeException'), array($errstr, $errno, $errfile, $errline));
     }
     throw $exceptionObject;
 }