Ejemplo n.º 1
0
 /**
  * @param string $definingFilePath
  * @param int $definingLineNumber
  * @param IdentifyingType $IdentifyingType
  * @param ImplementingType $ImplementingType
  * @param FactoryFunction $FactoryFunction
  * @param InitFunction $InitFunction
  */
 public function __construct($definingFilePath, $definingLineNumber, IdentifyingType $IdentifyingType, ImplementingType $ImplementingType = null, FactoryFunction $FactoryFunction = null, InitFunction $InitFunction = null)
 {
     $this->definingFilePath = $definingFilePath;
     $this->definingLineNumber = $definingLineNumber;
     $this->IdentifyingType = $IdentifyingType->getType();
     if ($ImplementingType === null) {
         $this->ImplementingType = null;
     } else {
         if ($ImplementingType->isSameAsIdentifyingType()) {
             $this->ImplementingType = $this->IdentifyingType;
         } else {
             $this->ImplementingType = $ImplementingType->getType();
         }
     }
     $this->FactoryFunction = $FactoryFunction !== null ? $FactoryFunction->getFactoryFunction() : null;
     $this->InitFunction = $InitFunction !== null ? $InitFunction->getInitFunction() : null;
 }
Ejemplo n.º 2
0
 /**
  * Defines a service. The service is identified by a type. This can be a class
  * or an interface. It is implemented by a class, that is an instance of the
  * identifying type. If both are the same, the second parameter can also be
  * an instance of ImplementingTypeIsSameAsIdentifyingType. To define a
  * service, an optional init or/and an optional factory function could be
  * passed. The factory function is passed as the third parameter, the init
  * function as fourthe or, if no init function is passed, as third parameter.
  *
  * @param IdentifyingType $IdentifyingType
  * @param IImplementingTypeOrFactoryFunction $ImplementingTypeOrFactoryFunction
  * @param InitFunction $InitFunction
  * @return self
  */
 public function add(IdentifyingType $IdentifyingType, IImplementingTypeOrFactoryFunction $ImplementingTypeOrFactoryFunction, InitFunction $InitFunction = null)
 {
     $definingFilePath = debug_backtrace()[0]['file'];
     $definingLineNumber = debug_backtrace()[0]['line'];
     $Type = $IdentifyingType->getType();
     $identifyingTypeName = $Type->getName();
     if ($this->has($Type)) {
         $AlreadyDefinedServiceDefinition = $this->get($Type);
         $InvalidServiceDefinition = new ServiceDefinition($definingFilePath, $definingLineNumber, $IdentifyingType);
         $message = 'A service of type ' . $identifyingTypeName . ' has already been defined in ' . $AlreadyDefinedServiceDefinition->getDefiningFilePath() . ' on line ' . $AlreadyDefinedServiceDefinition->getDefiningLineNumber() . '. ';
         $message .= 'There cannot be defined two services with the same identifying type.';
         throw new InvalidServiceDefinition($InvalidServiceDefinition, $message);
     }
     if ($ImplementingTypeOrFactoryFunction instanceof ImplementingType) {
         $ImplementingType = $ImplementingTypeOrFactoryFunction;
         $FactoryFunction = null;
     } else {
         $ImplementingType = null;
         $FactoryFunction = $ImplementingTypeOrFactoryFunction;
     }
     $this->serviceDefinitions[$identifyingTypeName] = new ServiceDefinition($definingFilePath, $definingLineNumber, $IdentifyingType, $ImplementingType, $FactoryFunction, $InitFunction);
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * @param IdentifyingType $IdentifyingType
  * @param object $ServiceInstance
  * @return self
  */
 public function addService(IdentifyingType $IdentifyingType, $ServiceInstance)
 {
     $this->builtServices[$IdentifyingType->getType()->getName()] = $ServiceInstance;
     return $this;
 }