/**
  * @return array
  */
 public function crudAction()
 {
     try {
         $url = $this->request->get('_url');
         if (!$url) {
             throw new \PPA\Rest\Exception('_url is mast specific');
         }
         if (Analyzer::isSaving($url)) {
             return $this->save();
         }
         if (Analyzer::isDeleting($url)) {
             return $this->delete();
         }
         $params = Params::getMergeParams($this->request);
         $query = Operators::buildQuery($url, $params);
         $data = $query->execute();
         $this->securityManager->check(array('model' => $data, 'action' => CrudOperations::READ, 'modelName' => Analyzer::getModelName($url), 'params' => $params));
         if (!$data) {
             return array();
         }
         return $this->getFinallyFullData($data, $params, $url);
     } catch (\PPA\Rest\Acl\Exception $e) {
         $this->response->setStatusCode(401);
         return array('msg' => $e->getMessage(), 'url' => $url);
     } catch (\PPA\Rest\Exception $e) {
         $this->response->setStatusCode(500);
         return array('msg' => $e->getMessage(), 'trace' => $e->getTrace());
     }
 }
 public function testBuild()
 {
     foreach (self::$expectedUrls as $url => $expected) {
         $query = Operators::buildQuery($url, $expected['params']);
         $query->execute();
         $this->assertEquals($query->getSql()['sql'], $expected['sql'], '$query->getSql() returns expected value');
         $this->assertEquals($query->getBindParams(), $expected['prepareParams'], '$query->getBindParams() returns expected value');
     }
 }
Пример #3
0
 /**
  * @param array $params
  */
 private function initParamsPortion(array $params)
 {
     $preparedUrl = Operators::getPrepareUrlOperators($this->fullUrl);
     $andList = array_filter(explode('|', $preparedUrl));
     foreach ($andList as $and) {
         $orList = array_filter(explode('-', $and));
         foreach ($orList as $or) {
             $paramKey = $this->findKeyParamByPortionString($params, $or);
             if ($paramKey === false) {
                 continue;
                 //throw new InvalidArgumentException('for portion ' . $or . ' is not set param');
             }
             $this->paramsPortion[$paramKey] = new Portion($or);
         }
     }
 }