Exemple #1
0
 public static function getService($type, $serviceName = null)
 {
     if (!empty($serviceName)) {
         $service = Collection::get($serviceName);
         if ($service == null) {
             self::addNewServiceInstance($type, $serviceName);
             throw new RuntimeException("Not defined service! - name: '{$serviceName}'");
         }
         if ($type !== null && !$service instanceof $type) {
             throw new RuntimeException("Found service class mismatch with expected type! - name: '{$serviceName}' type: '{$type}'");
         }
         return $service;
     }
     $service = Collection::get($type);
     if ($service === null) {
         self::addNewServiceInstance($type);
         $service = Collection::get($type);
     }
     return $service;
 }