find() abstract public method

Find and populate a model based on the model type and where criteria
abstract public find ( Modler\Model $model, array $where = [] ) : object
$model Modler\Model Model instance
$where array "Where" data to locate record
return object Either a collection or model instance
Exemplo n.º 1
0
 /**
  * Delete the token by token string
  *
  * @param string $token Token hash string
  * @return boolean Success/fail of token record deletion
  */
 public function deleteToken($token)
 {
     $tokenModel = new \Psecio\Gatekeeper\AuthTokenModel($this->datasource);
     $token = $this->datasource->find($tokenModel, array('token' => $token));
     if ($token !== false) {
         return $this->datasource->delete($token);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Build the model instance with data given
  *
  * @param string $action Action called (ex: "delete" or "create")
  * @param string $name Function nname
  * @param array $args Arguments set
  * @throws \Exception\ModelNotFoundException If model type is not found
  * @return object Model instance
  */
 public static function buildModel($action = 'find', $name, array $args)
 {
     $name = str_replace($action, '', $name);
     preg_match('/By(.+)/', $name, $matches);
     if (empty($matches) && $args[0] instanceof \Modler\Model) {
         $model = $name;
         $data = $args[0]->toArray();
     } else {
         $property = lcfirst($matches[1]);
         $model = str_replace($matches[0], '', $name);
         $data = array($property => $args[0]);
     }
     $modelNs = '\\Psecio\\Gatekeeper\\' . $model . 'Model';
     if (!class_exists($modelNs)) {
         throw new Exception\ModelNotFoundException('Model type ' . $model . ' could not be found');
     }
     $instance = new $modelNs(self::$datasource);
     $instance = self::$datasource->find($instance, $data);
     return $instance;
 }