Exemplo n.º 1
0
 /**
  * @param ServiceDefinition $ServiceDefinition
  * @param mixed $value
  * @throws InvalidServiceDefinition
  */
 private function ensureValueImplementsIdentifyingType(ServiceDefinition $ServiceDefinition, $value)
 {
     $identifyingTypeName = $ServiceDefinition->getIdentifyingType()->getName();
     if (is_object($value) && $value instanceof $identifyingTypeName) {
         return;
     }
     $message = 'The factory function returned ' . self::getValueInfo($value, $identifyingTypeName) . '. ';
     $message .= 'The factory function of a service must return an object that implements the identifying type.';
     throw new InvalidServiceDefinition($ServiceDefinition, $message);
 }
Exemplo n.º 2
0
 /**
  * @param ServiceDefinition $ServiceDefinition
  * @param string $functionType
  * @param Type $RequiredType
  * @param string $parameterName
  */
 private static function ensureFactoryFunctionDoesNotRequireTheServiceItself(ServiceDefinition $ServiceDefinition, $functionType, Type $RequiredType, $parameterName)
 {
     if ($functionType === 'init') {
         return;
     }
     if ($RequiredType == $ServiceDefinition->getIdentifyingType()) {
         $message = 'The type hint of the parameter $' . $parameterName . ' is ' . $RequiredType->getName() . '. ';
         $message .= 'A factory function cannot be injected with the service it is about to build.';
         throw new InvalidServiceDefinition($ServiceDefinition, $message);
     }
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function hasInitFunction_returns_false_if_no_init_function_passed_in()
 {
     // given
     $IdentifyingType = IdentifyingType::is(Type::fromName(__CLASS__));
     $ImplementingType = ImplementingType::is(Type::fromName(__CLASS__));
     $FactoryFunction = FactoryFunction::is(function () {
     });
     // when
     $Target = new ServiceDefinition('', 0, $IdentifyingType, $ImplementingType, $FactoryFunction, null);
     // then
     $this->AssertTrue($Target->hasFactoryFunction());
     $this->AssertFalse($Target->hasInitFunction());
 }
Exemplo n.º 4
0
 /**
  * @param ServiceDefinition $ServiceDefinition
  * @param string $specificMessage
  */
 public function __construct(ServiceDefinition $ServiceDefinition, $specificMessage)
 {
     $message = sprintf("Invalid definition of the service %s in %s on line %d: %s", $ServiceDefinition->getIdentifyingType()->getName(), $ServiceDefinition->getDefiningFilePath(), $ServiceDefinition->getDefiningLineNumber(), $specificMessage);
     parent::__construct($message);
 }