コード例 #1
0
ファイル: RestService.php プロジェクト: nchervyakov/evolve2
 /**
  * Does the real handling of the request.
  * @param array $cookie
  */
 protected function doHandleRequest($cookie = [])
 {
     $request = $this->request;
     $pixie = $this->pixie;
     $pixie->cookie->set_cookie_data($cookie);
     $controllerName = implode('', array_map('ucfirst', preg_split('/_/', $request->param('controller'))));
     $controller = Controller::createController($controllerName, $request, $pixie);
     // Run all necessary filters
     $this->pixie->dispatcher->dispatch(Events::PRE_PROCESS_ACTION, new PreActionEvent($request, $controller));
     $action = strtolower($request->method);
     $action = $action == 'head' ? 'get' : $action;
     if (!$controller instanceof NoneController) {
         if (!$request->param('id')) {
             if (in_array($this->request->method, ['GET', 'HEAD'])) {
                 $action .= '_collection';
             }
         } else {
             if ($request->param('property')) {
                 $action .= '_' . $request->param('property');
             }
         }
     }
     $controller->run($action);
     $this->response = $controller->response;
 }
コード例 #2
0
ファイル: Product.php プロジェクト: guitarooman14/hackazon
 public function action_get_collection()
 {
     $ids = $this->request->get($this->model->id_field);
     if ($ids) {
         $ids = array_unique(preg_split('/\\s*,\\s*/', $ids, -1, PREG_SPLIT_NO_EMPTY));
         if (count($ids) > 0) {
             $this->model->where($this->model->id_field, 'IN', $this->pixie->db->expr('(' . implode(',', $ids) . ')'));
         }
     }
     if ($catId = $this->request->get("categoryID")) {
         $categoryIds = [$catId];
         $category = $this->pixie->orm->get('Category', $catId);
         if (!$category->loaded()) {
             throw new NotFoundException("Category {$catId} Not Found");
         }
         // Find child categories
         $categoryChildren = $category->nested->children()->find_all();
         /** @var Category $child */
         foreach ($categoryChildren as $child) {
             $categoryIds[] = $child->id();
         }
         $this->model->where('categoryID', 'IN', $this->pixie->db->expr('(' . implode(',', $categoryIds) . ')'));
     }
     return parent::action_get_collection();
 }
コード例 #3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->modelClass === null) {
         throw new InvalidConfigException('The "modelClass" property must be set.');
     }
 }
コード例 #4
0
ファイル: Order.php プロジェクト: guitarooman14/hackazon
 public function action_patch($data = null)
 {
     if ($data === null) {
         $data = $this->request->post();
     }
     $data['customer_id'] = $this->user->id();
     return parent::action_patch($data);
 }
コード例 #5
0
 public function action_post($data = null)
 {
     if ($this->request->param('id')) {
         throw new HttpException('You can\'t create already existing object.', 400, null, 'Bad Request');
     }
     if ($data === null) {
         $data = $this->request->post();
     }
     $data['customer_id'] = $this->user->id();
     return parent::action_post($data);
 }
コード例 #6
0
ファイル: Cart.php プロジェクト: guitarooman14/hackazon
 public function action_get()
 {
     if ($this->request->param('id') == 'my') {
         $cartItems = $this->item->getCartItemsModel();
         $cartItems->getCart($this->request->get("uid"));
         $data = $this->asArrayWith(parent::action_get(), ['items']);
         $data['total_price'] = $cartItems->getItemsTotal();
         return $data;
     } else {
         throw new NotFoundException();
     }
 }
コード例 #7
0
ファイル: Category.php プロジェクト: scottleedavis/hackazon
 /**
  * @return \App\Model\BaseModel|null
  * @Vuln\Description("Fetches the category with given ID")
  * @Vuln\Route("rest", params={"action": "get", "id": "_id_"})
  */
 public function action_get()
 {
     return parent::action_get();
 }
コード例 #8
0
ファイル: rest.php プロジェクト: nchervyakov/evolve2
                    <div class="form-group">
                        <input type="text" class="form-control js-url-field" placeholder="Resource URL" name="url" required>
                    </div>

                    <div class="form-group">
                        <input type="text" class="form-control js-name-field" placeholder="Username" name="username" required>
                    </div>

                    <div class="form-group">
                        <input type="text" class="form-control js-password-field" placeholder="Password" name="password" required>
                    </div>

                    <div class="form-group">
                        <select name="method" id="requestMethod" class="form-control js-method-field">
                            <?php 
foreach (\App\Rest\Controller::allowedMethods() as $method) {
    ?>
                                <option value="<?php 
    echo $method;
    ?>
"><?php 
    echo $method;
    ?>
</option>
                            <?php 
}
?>
                            <option value="DISALLOWED">DISALLOWED</option>
                        </select>
                    </div>
コード例 #9
0
ファイル: User.php プロジェクト: scottleedavis/hackazon
 public function action_get_collection()
 {
     $username = $this->request->getWrap('username');
     if ($username) {
         $this->model->where('and', ['username', '=', $username]);
     }
     return parent::action_get_collection();
 }
コード例 #10
0
ファイル: CartItems.php プロジェクト: scottleedavis/hackazon
 public function action_put($data = null)
 {
     return parent::action_put($data);
 }
コード例 #11
0
ファイル: User.php プロジェクト: nchervyakov/evolve2
 public function exposedFields()
 {
     $fields = parent::exposedFields();
     return $this->removeValues($fields, ['password']);
 }
コード例 #12
0
 protected function preloadModel()
 {
     $this->model->where('customer_id', '=', $this->getUser()->id());
     parent::preloadModel();
 }