Example #1
0
 /**
  * @param object $model
  *
  * @return mixed
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 public function getIdentifierMade($model)
 {
     if (!is_object($model)) {
         throw new \InvalidArgumentException(sprintf('You must give a object, "%s" given.', gettype($model)));
     }
     $methodMadeBy = 'get' . ucfirst($this->definition->getMadeBy());
     if (!method_exists($model, $methodMadeBy)) {
         throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($model), $methodMadeBy));
     }
     $modelMade = $model->{$methodMadeBy}();
     if (!is_object($modelMade)) {
         throw new \RuntimeException(sprintf('Model "%s::%s()" must already return object, "%s" given.', get_class($model), $methodMadeBy, gettype($modelMade)));
     }
     $methodMadeField = 'get' . ucfirst($this->definition->getMadeField());
     if (!method_exists($model->{'get' . $this->definition->getMadeBy()}(), $modelMade)) {
         throw new \RuntimeException(sprintf('Model "%s" must have method "%s".', get_class($modelMade), $methodMadeField));
     }
     return $model->{'get' . ucfirst($this->definition->getMadeBy())}()->{'get' . ucfirst($this->definition->getMadeField())}();
 }
Example #2
0
 /**
  * Adding associtation mapping between multi-model.
  *
  * @param boolean $isCollection
  * @param string  $field
  * @param string  $targetMultiModel
  * @param array   $compatible       (optional)
  * @param array   $references       (optional)
  *
  * @return AssociationDefinition
  */
 public function addAssociation($isCollection, $field, $targetMultiModel, array $compatible = array(), array $references = array())
 {
     $mapping = new AssociationDefinition($field, $targetMultiModel, $isCollection);
     $mapping->setCompatible($compatible);
     $mapping->setReferences($references);
     $this->associationMappings[$field] = $mapping;
     return $mapping;
 }