Example #1
0
 public final function SetPropertyMode($PropertyMode)
 {
     if ($PropertyMode !== self::PropertiesAreGetters && $PropertyMode !== self::PropertiesAreSetters && $PropertyMode !== self::PropertiesAreGettersOrSetters) {
         throw new FunctionException('The supplied property mode is invalid: %s given', \Storm\Core\Utilities::GetTypeOrClass($PropertyMode));
     }
     $this->PropertyMode = $PropertyMode;
 }
 /**
  * {@inheritDoc}
  */
 public final function Initialize(DomainDatabaseMap $DomainDatabaseMap)
 {
     $this->OnInitialize($DomainDatabaseMap);
     $this->EntityMap = $this->EntityMap($DomainDatabaseMap->GetDomain());
     $this->EntityType = $this->EntityMap->GetEntityType();
     if (!$this->EntityMap instanceof Object\IEntityMap) {
         throw new \Storm\Core\UnexpectedValueException('Return value from %s->EntityMap() must be an instance of %s, %s given', get_class($this), Object\IEntityMap::IEntityMapType, \Storm\Core\Utilities::GetTypeOrClass($this->EntityMap));
     }
     $Database = $DomainDatabaseMap->GetDatabase();
     $Registrar = new Registrar(IPropertyMapping::IPropertyMappingType);
     $this->RegisterPropertyMappings($Registrar, $this->EntityMap, $Database);
     foreach ($Registrar->GetRegistered() as $PropertyMapping) {
         $this->AddPropertyMapping($PropertyMapping);
     }
     foreach ($this->MappedReviveColumns as $MappedReviveColumn) {
         $Table = $MappedReviveColumn->GetTable();
         $this->ReviveTables[$Table->GetName()] = $Table;
     }
     foreach ($this->MappedPersistColumns as $MappedPersistColumn) {
         $Table = $MappedPersistColumn->GetTable();
         $this->PersistTables[$Table->GetName()] = $Table;
     }
     if ($this->PrimaryKeyTable === null) {
         throw new MappingException('The property mappings of %s must contain atleast 1 identity primary key mapping', get_class($this));
     }
     $this->OnInitialized($DomainDatabaseMap);
 }
Example #3
0
 protected function PersistRelationshipChanges(Object\Domain $Domain, Object\UnitOfWork $UnitOfWork, $ParentEntity, $CurrentValue, $HasOriginalValue, $OriginalValue)
 {
     $RelationshipChanges = [];
     $OriginalEntities = [];
     $CurrentEntities = [];
     if ($HasOriginalValue) {
         $OriginalEntities =& $OriginalValue;
     }
     if (is_array($CurrentValue)) {
         $CurrentEntities =& $CurrentValue;
     } else {
         throw new Object\ObjectException('Invalid value for property on entity %s, array expected, %s given', $this->GetEntityType(), \Storm\Core\Utilities::GetTypeOrClass($CurrentValue));
     }
     if ($CurrentEntities === $OriginalEntities) {
         return $RelationshipChanges;
     }
     $NewEntities = array_udiff($CurrentEntities, $OriginalEntities, [$this, 'ObjectComparison']);
     $RemovedEntities = array_udiff($OriginalEntities, $CurrentEntities, [$this, 'ObjectComparison']);
     foreach ($NewEntities as $NewEntity) {
         $RelationshipChanges[] = new Object\RelationshipChange($this->RelationshipType->GetPersistedRelationship($Domain, $UnitOfWork, $ParentEntity, $NewEntity), null);
     }
     foreach ($RemovedEntities as $RemovedEntity) {
         $RelationshipChanges[] = new Object\RelationshipChange(null, $this->RelationshipType->GetDiscardedRelationship($Domain, $UnitOfWork, $ParentEntity, $RemovedEntity));
     }
     return $RelationshipChanges;
 }
 public function ToPersistedValue($PropertyValue)
 {
     if (!$PropertyValue instanceof \DateTime) {
         throw new Columns\DataTypeException('The supplied property values must be an instance of \\DateTime: %s given', \Storm\Core\Utilities::GetTypeOrClass($PropertyValue));
     }
     return $PropertyValue->getTimestamp();
 }
 public function __construct(array $BooleanExpressions, $LogicalOperator = Binary::LogicalAnd)
 {
     if ($LogicalOperator !== Binary::LogicalAnd && $LogicalOperator !== Binary::LogicalOr) {
         throw new \Storm\Core\UnexpectedValueException('The supplied operator must be the logical and/or, %s given', \Storm\Core\Utilities::GetTypeOrClass($LogicalOperator));
     }
     $this->LogicalOperator = $LogicalOperator;
     $this->BooleanExpressions = $BooleanExpressions;
 }
Example #6
0
 public function ToPersistedValue($PropertyValue)
 {
     $PersistedValue = array_search($PropertyValue, $this->ValuesMap, true);
     if ($PersistedValue === false) {
         throw new DataTypeException('Cannot map enum property value to persisted value: expecting %s, %s given', implode(', ', array_map('strval', $PersistedValue)), \Storm\Core\Utilities::GetTypeOrClass($PropertyValue));
     }
     return $PersistedValue;
 }
Example #7
0
 public static function MapParameterType($ParameterType)
 {
     if (isset(self::$ParameterTypesMap[$ParameterType])) {
         return self::$ParameterTypesMap[$ParameterType];
     } else {
         throw new \Storm\Core\UnexpectedValueException('Cannot map the supplied parameter type: %s given', \Storm\Core\Utilities::GetTypeOrClass($ParameterType));
     }
 }
Example #8
0
 public function __construct($InstanceOrType)
 {
     if (!is_object($InstanceOrType) && !class_exists($InstanceOrType)) {
         throw new \Storm\Core\Object\ObjectException('The supplied value must be either an object or a valid class name: %s given', is_string($InstanceOrType) ? '\'' . $InstanceOrType . '\'' : \Storm\Core\Utilities::GetTypeOrClass($InstanceOrType));
     }
     $this->HasInstance = is_object($InstanceOrType);
     $this->ClassType = $this->HasInstance ? get_class($InstanceOrType) : $InstanceOrType;
     $this->Instance = $this->HasInstance ? $InstanceOrType : null;
 }
Example #9
0
 public function Register($Instance)
 {
     if ($this->RegistrableType !== null) {
         if (!$Instance instanceof $this->RegistrableType) {
             throw new \Storm\Core\Object\TypeMismatchException('Registered type does not match, expecting %s, supplied %s', $this->RegistrableType, \Storm\Core\Utilities::GetTypeOrClass($Instance));
         }
     }
     $this->Instances[] = $Instance;
 }
Example #10
0
 public final function ToPersistedValue($PropertyValue)
 {
     if ($PropertyValue === null) {
         return null;
     }
     if (!$PropertyValue instanceof $this->ClassType) {
         throw new DataTypeException('Invalid property value for %s: expecting %s, %s given', get_class($this), $this->ClassType, \Storm\Core\Utilities::GetTypeOrClass($PropertyValue));
     }
     return $this->PersistedValue($PropertyValue);
 }
Example #11
0
 public function __construct()
 {
     parent::__construct();
     $this->EntityConstructor = $this->EntityConstructor();
     if (!$this->EntityConstructor instanceof Construction\IEntityConstructor) {
         throw new Object\ObjectException('The supplied entity constructor must implement %s: %s given', Construction\IEntityConstructor::IEntityConstructorType, \Storm\Core\Utilities::GetTypeOrClass($this->EntityConstructor));
     }
     if ($this->EntityConstructor->HasEntityType()) {
         throw new Object\ObjectException('The supplied entity constructor %s already has an entity type %s', get_class($this->EntityConstructor), $this->EntityConstructor->GetEntityType());
     }
     $this->EntityConstructor->SetEntityType($this->GetEntityType());
 }
Example #12
0
 protected function PersistRelationshipChanges(Object\Domain $Domain, Object\UnitOfWork $UnitOfWork, $ParentEntity, $CurrentValue, $HasOriginalValue, $OriginalValue)
 {
     $RelationshipChanges = [];
     $OriginalEntities = [];
     $CurrentEntities = [];
     if (!$CurrentValue instanceof Collections\ICollection) {
         if (!$CurrentValue instanceof \Traversable) {
             throw new Object\ObjectException('Invalid value for collection property on entity %s, Traversable expected, %s given', $this->GetEntityMap()->GetEntityType(), \Storm\Core\Utilities::GetTypeOrClass($CurrentValue));
         }
         foreach ($CurrentValue as $Entity) {
             if ($this->IsValidEntity($Entity)) {
                 $CurrentEntities[] = $Entity;
             }
         }
     } else {
         if ($CurrentValue instanceof Collections\LazyCollection && !$CurrentValue->__IsLoaded()) {
             return [];
         } else {
             if (!$CurrentValue->__IsAltered()) {
                 foreach ($CurrentValue->ToArray() as $Entity) {
                     if ($Entity instanceof Proxies\IProxy && !$Entity->__IsAltered()) {
                         continue;
                     }
                     $UnitOfWork->PersistRelationships($Entity);
                 }
                 return [];
             } else {
                 $CurrentEntities = $CurrentValue->ToArray();
             }
         }
     }
     if ($HasOriginalValue) {
         $OriginalEntities = $OriginalValue->ToArray();
     }
     $NewOrAlteredEntities = $this->ComputeDifference($CurrentEntities, $OriginalEntities);
     $RemovedEntities = $this->ComputeIdentityDifference($Domain, $OriginalEntities, $CurrentEntities);
     foreach ($NewOrAlteredEntities as $NewEntity) {
         $RelationshipChanges[] = new Object\RelationshipChange($this->RelationshipType->GetPersistedRelationship($Domain, $UnitOfWork, $ParentEntity, $NewEntity), null);
     }
     foreach ($RemovedEntities as $RemovedEntity) {
         $RelationshipChanges[] = new Object\RelationshipChange(null, $this->RelationshipType->GetDiscardedRelationship($Domain, $UnitOfWork, $ParentEntity, $RemovedEntity));
     }
     return $RelationshipChanges;
 }
Example #13
0
 /**
  * Verifies an object to be of the type represented by this entity map.
  * 
  * @param object $Entity The entity to verify
  * @throws TypeMismatchException
  */
 private function VerifyEntity($Method, $Entity)
 {
     if (!$Entity instanceof $this->EntityType) {
         throw new TypeMismatchException('The supplied entity to %s must be of the type %s: %s given', $Method, $this->EntityType, \Storm\Core\Utilities::GetTypeOrClass($Entity));
     }
 }
Example #14
0
 /**
  * Verifies an entity to be valid for use in this repository.
  * 
  * @param string $Method __METHOD__
  * @param object $Entity The entity to verify
  * @throws Object\TypeMismatchException
  */
 protected final function VerifyEntity($Method, $Entity)
 {
     if (!$Entity instanceof $this->EntityType) {
         throw new Object\TypeMismatchException('Call to method %s with invalid entity: %s expected, %s given', $Method, $this->EntityType, \Storm\Core\Utilities::GetTypeOrClass($Entity));
     }
 }
 private function UnsupportedLoadingMode($LoadingMode)
 {
     return new Mappings\MappingException('The supplied loading mode is unsupported: %s given', \Storm\Core\Utilities::GetTypeOrClass($LoadingMode));
 }
 public final function ReviveValue(Domain $Domain, $Entity, $PropertyRevivalValue)
 {
     if ($PropertyRevivalValue === null) {
         return $this->ReviveNull($Domain, $Entity);
     }
     if ($PropertyRevivalValue instanceof Object\RevivalData) {
         $this->AddBackReference($PropertyRevivalValue, $Entity);
         return $this->ReviveRevivalData($Domain, $Entity, $PropertyRevivalValue);
     }
     if ($PropertyRevivalValue instanceof LazyRevivalData) {
         $this->AddBackReference($PropertyRevivalValue->GetAlreadyKnownRevivalData(), $Entity);
         return $this->ReviveLazyRevivalData($Domain, $Entity, $PropertyRevivalValue);
     }
     if ($PropertyRevivalValue instanceof MultipleLazyRevivalData) {
         $this->AddBackReference($PropertyRevivalValue->GetAlreadyKnownRevivalData(), $Entity);
         return $this->ReviveMultipleLazyRevivalData($Domain, $Entity, $PropertyRevivalValue);
     } else {
         if (is_array($PropertyRevivalValue)) {
             if ($this->IsAll($PropertyRevivalValue, function ($I) {
                 return $I instanceof Object\RevivalData;
             })) {
                 $this->AddBackReferences($PropertyRevivalValue, $Entity);
                 return $this->ReviveArrayOfRevivalData($Domain, $Entity, $PropertyRevivalValue);
             }
             if ($this->IsAll($PropertyRevivalValue, function ($I) {
                 return $I instanceof LazyRevivalData;
             })) {
                 foreach ($PropertyRevivalValue as $LazyRevivalData) {
                     $this->AddBackReference($LazyRevivalData->GetAlreadyKnownRevivalData(), $Entity);
                 }
                 return $this->ReviveArrayOfLazyRevivalData($Domain, $Entity, $PropertyRevivalValue);
             }
         }
     }
     throw new \Storm\Core\UnexpectedValueException('%s cannot revive supplied value: %s given', __CLASS__, \Storm\Core\Utilities::GetTypeOrClass($PropertyRevivalValue));
 }
Example #17
0
 private function InvalidEntityAndIsRequired($CurrentValue)
 {
     return new Object\ObjectException('Invalid value for required relationship property on entity %s, %s expected, %s given', $this->GetEntityMap()->GetEntityType(), $this->GetEntityType(), \Storm\Core\Utilities::GetTypeOrClass($CurrentValue));
 }
Example #18
0
 /**
  * Set the range amount.
  * 
  * @param type $RangeAmount Specify null to remove the limit
  * @throws \InvalidArgumentException If the parameter is not a integer or null
  */
 public final function SetRangeAmount($RangeAmount)
 {
     if (!is_int($RangeAmount) && $RangeAmount !== null) {
         throw new \Storm\Core\UnexpectedValueException('The supplied range amount must be a valid integer or null: %s given', \Storm\Core\Utilities::GetTypeOrClass($RangeAmount));
     }
     $this->RangeAmount = $RangeAmount;
 }