Пример #1
0
 /**
  * Binds callable to type by name
  * @param mixed $typeName
  * @param string $name
  * @param callable $callback
  */
 public static function bind($typeName, $name, callable $callback = null)
 {
     $model = persistr\Registry::getModelByName($typeName);
     $objectRegistry = $model->getRegistry();
     $instances = $objectRegistry->getInstances();
     if (!empty($instances)) {
         foreach ($instances as $instance) {
             self::bindTo($instance, $name, $callback);
         }
     }
 }
Пример #2
0
 /**
  * Constructor for empty object registry
  * @param mixed $model
  * @param string $typeName
  * @throws persistr\Exception
  */
 public function __construct($model, $typeName)
 {
     $typeName = str_replace('/', '\\', $typeName);
     $this->typeName = $typeName;
     if ($model instanceof persistr\Model\Blank) {
         return;
     }
     if (persistr\Registry::persisted($typeName)) {
         $persistor = persistr\Registry::persistor($typeName);
     } else {
         $persistor = persistr\Registry::getPersistorByName($typeName);
     }
     if ($persistor instanceof persistr\Persistor) {
         $this->persistor = $persistor;
         $dataFilters = [];
         $outputFilters = [];
         if ($persistor->hasDataFilters()) {
             $dataFilterClasses = $persistor->getDataFilters();
             foreach ($dataFilterClasses as $filterClass) {
                 if (@class_exists($filterClass)) {
                     $filter = new $filterClass($typeName);
                     $dataFilters[] = $filter;
                 }
             }
         }
         if ($persistor->hasOutputFilters()) {
             $outputFilterClasses = $persistor->getOutputFilters();
             if (is_array($outputFilterClasses)) {
                 foreach ($outputFilterClasses as $filterClass) {
                     if (@class_exists($filterClass)) {
                         $filter = new $filterClass($typeName);
                         $outputFilters[] = $filter;
                     }
                 }
             }
         }
         self::$datafilters[$typeName] = $dataFilters;
         self::$outputfilters[$typeName] = $outputFilters;
     } else {
         throw new persistr\Exception('Class not persisted, cannot instantiate ' . $typeName);
     }
 }
 protected function tearDown()
 {
     persistr\Registry::clearPersistors();
 }