예제 #1
0
 public function removeModel($className)
 {
     if (!$this->hasModel($className)) {
         throw new Exceptions\ModelNotInConfigException();
     }
     unset($this->configData['models'][ElegantModel::generateId($className)]);
 }
 public function __construct($modelName)
 {
     $modelId = ElegantModel::generateId($modelName);
     if (!($model = Config::getModelById($modelId))) {
         throw new \Exception('Model not found with name ' . $modelName);
     }
     $this->elegantModel = $model;
     parent::__construct($this->elegantModel->getModelInstance());
 }
 /**
  * Checks if a certain class should be considered
  * a application-level Eloquent model and if so,
  * stores the class name as a found model.
  */
 protected function checkClass($className)
 {
     if (is_a($className, self::CLASS_MATCHING_NAME, true) && $className !== self::CLASS_MATCHING_NAME && strpos((new ReflectionClass($className))->getFileName(), $this->path) === 0) {
         $this->foundModels[ElegantModel::generateId($className)] = $className;
     }
 }
예제 #4
0
 public function it_should_return_model_by_id()
 {
     $this->addModel(new TestModels\Article(), []);
     $this->getModelById(ElegantModel::generateId(TestModels\Article::class))->shouldReturnAnInstanceOf(ElegantModel::class);
 }
 public function it_should_find_existing_models()
 {
     $this->findModels()->shouldReturn([ElegantModel::generateId(TestModels\Article::class) => TestModels\Article::class, ElegantModel::generateId(TestModels\Comment::class) => TestModels\Comment::class, ElegantModel::generateId(TestModels\User::class) => TestModels\User::class]);
 }