예제 #1
0
 public function register(Application $app)
 {
     $app['model'] = function (Application $app) {
         $manager = new Manager();
         $manager->setFinder($app['model.finder']);
         $storageHandlerServices = $app['model.storage.handlers'];
         if (!is_array($storageHandlerServices)) {
             throw new \InvalidArgumentException("Service 'model.storage.handlers' must be an array of storage handlers");
         }
         if (!count($storageHandlerServices)) {
             throw new \InvalidArgumentException("Service 'model.storage.handlers' contains no storage handler service(s). Please register atleast one.");
         }
         foreach ($storageHandlerServices as $storageHandlerName => $storageHandlerService) {
             if (is_string($storageHandlerService)) {
                 $storageHandlerService = $app[$storageHandlerService];
             }
             $manager->setModelStorageHandler($storageHandlerService, $storageHandlerName);
         }
         $storageMap = isset($app['model.storage.handler.map']) ? $app['model.storage.handler.map'] : array();
         $manager->setModelToStorageHandlerMap($storageMap);
         return $manager;
     };
     $app['model.finder'] = function (Application $app) {
         $finder = new Finder\FileFinder();
         $finder->setNamespace($app['model.finder.namespace']);
         $finder->setBasePath($app['model.finder.path']);
         return $finder;
     };
 }
예제 #2
0
 /**
  * test get method model for unregisterd model
  * @expectedException Skip\Model\StorageHandlerNotFoundException
  */
 public function testGetModelWithNoStorageHandler()
 {
     $manager = new Manager();
     $mockModel = $this->getMock('Skip\\Model\\ModelInterface', array('setStorageHandler'), array(), '', FALSE);
     $mockModelClass = get_class($mockModel);
     $mockFinder = $this->getMock('Skip\\Model\\ModelFinderInterface', array('getModelClassList'), array(), '', FALSE);
     $mockFinder->expects($this->once())->method('getModelClassList')->will($this->returnValue(array('model.class.a' => $mockModelClass)));
     $manager->setFinder($mockFinder);
     $manager->get('model.class.a');
 }