Пример #1
0
 public function create($class, Depends $depends)
 {
     $deps = [];
     foreach ($depends->get("value") as $dep) {
         if ($dep[0] === "@") {
             $dep = substr($dep, 1);
             $deps[] = $this->container->get($dep);
         } elseif ($dep[0] === "%") {
             $dep = substr($dep, 1, -1);
             $deps[] = $this->container->getParameter($dep);
         } else {
             throw new InternalErrorException("Invalid dependency: {$dep}.");
         }
     }
     return new $class(...$deps);
 }
Пример #2
0
 protected function checkConstructor(ReflectionClass $classRefl, Depends $deps)
 {
     if (count($deps->get("value")) && !$classRefl->getConstructor()) {
         throw new InternalErrorException(sprintf("Class %s has dependencies, but doesn’t have a constructor to inject them!", $classRefl->name));
     }
 }