Psecio\Gatekeeper\Gatekeeper::modelFactory PHP Метод

modelFactory() публичный статический Метод

Create and setup a new model instance
public static modelFactory ( string $type, array $data = [] ) : object
$type string Model class name
$data array
Результат object Model instance
    public static function modelFactory($type, array $data = array())
    {
        $class = '\\Psecio\\Gatekeeper\\' . $type;
        if (!class_exists($class)) {
            throw new \InvalidArgumentException('Model type "' . $class . '" does not exist!');
        }
        $model = new $class(self::$datasource, $data);
        return $model;
    }

Usage Example

Пример #1
0
 /**
  * Handle the "find by" when multiple are requested
  *
  * @param string $name Name of function called
  * @param array $args Arguments list
  * @param array $matches Matches from regex
  * @return \Modler\Collection collection
  */
 public function handleFindByMultiple($name, $args, $matches)
 {
     $data = isset($args[0]) ? $args[0] : array();
     $model = substr($name, 0, strlen($name) - 1);
     $collectionNs = '\\Psecio\\Gatekeeper\\' . $model . 'Collection';
     if (!class_exists($collectionNs)) {
         throw new \Psecio\Gatekepper\Exception\ModelNotFoundException('Collection type ' . $model . ' could not be found');
     }
     $model = g::modelFactory($model . 'Model');
     $collection = new $collectionNs($this->getDb());
     $collection = $this->getDb()->find($model, $data, true);
     return $collection;
 }
All Usage Examples Of Psecio\Gatekeeper\Gatekeeper::modelFactory