예제 #1
0
 /**
  * @param string $id
  * @return mixed
  * @throws CircularDependencyException
  */
 private function createService($id)
 {
     if (isset($this->servicesCreating[$id])) {
         $msg = 'Circular dependency: ' . implode(' => ', array_keys($this->servicesCreating)) . " => {$id}";
         throw new CircularDependencyException($msg);
     }
     $this->servicesCreating[$id] = true;
     $service = $this->factory->create($id, $this);
     unset($this->servicesCreating[$id]);
     $this->repository->add($id, $service);
     return $service;
 }
예제 #2
0
 /**
  * Gets the instance via lazy initialization (created on first usage)
  *
  * @param $id
  *
  * @throws CircularDependencyException
  *
  * @return a registered service
  */
 public function get($id)
 {
     $service = $this->repository->get($id);
     if (is_null($service)) {
         if (isset($this->servicesCreating[$id])) {
             $msg = 'Circular dependency detected: ' . implode(' => ', array_keys($this->servicesCreating)) . " => {$id}";
             throw new CircularDependencyException($msg);
         }
         // remmember ids called
         $this->servicesCreating[$id] = true;
         // pass the container to force only one instantiation per class
         $service = $this->factory->create($id, $this);
         unset($this->servicesCreating[$id]);
         $this->repository->add($id, $service);
     }
     return $service;
 }
예제 #3
0
 /**
  * Load data by given Identity
  *
  * @param string $serviceId
  * @return Service
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function getById($serviceId)
 {
     $service = $this->serviceFactory->create();
     $this->resource->load($service, $serviceId);
     if (!$service->getId()) {
         throw new NoSuchEntityException(__('Item with id "%1" does not exist.', $serviceId));
     }
     return $service;
 }
예제 #4
0
 /**
  * Creates the appropriate mapper service for the current environment.
  *
  * @param string $mapperClass the class to instantiate; overrides the current configuration.
  * @return Social_IdMappingService
  */
 public static function create($mapperClass = null)
 {
     return ServiceFactory::create('Social_IdMappingService', self::DEFAULT_MAPPING_SERVICE, $mapperClass);
 }