예제 #1
0
파일: Container.php 프로젝트: elfet/simple
 public function set($closure)
 {
     if ($closure instanceof \Closure) {
         if ($this->protect) {
             $closure = $this->pimple->protect($closure);
         }
         if (!empty($this->inject)) {
             $factories = array();
             foreach ($this->inject as $id) {
                 $factory = $this->pimple->raw($id);
                 if (!$factory instanceof \Closure) {
                     throw new \InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id));
                 }
                 $factories[] = $factory;
             }
             $closure = function ($c) use($closure, $factories) {
                 $params = array_map(function ($factory) use($c) {
                     return $factory($c);
                 }, $factories);
                 $params[] = $c;
                 return call_user_func_array($closure, $params);
             };
         }
         if ($this->share) {
             $closure = $this->pimple->share($closure);
         }
     }
     $this->pimple[$this->key] = $closure;
     $this->restore();
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function raw($id)
 {
     return $this->container->raw($id);
 }