Beispiel #1
0
 public function execute(Request $request)
 {
     $url = $request->getUrl();
     $method = $request->getMethod();
     $parameters = $request->getParameters();
     $responseType = $request->getResponseType();
     // GET api/user/1.xml (get)
     if ($method === 'GET' && preg_match_all('/api\\/' . $this->name . '\\/([0-9]).xml/', $url, $matches)) {
         $id = $matches[1][0];
         return $this->execServer($request, array('_method' => $method, '_format' => $responseType, '_entity' => $this->name, '_action' => 'get', '_id' => $id), $parameters, $responseType);
     }
     // GET api/user.xml (list)
     if ($method === 'GET' && preg_match_all('/api\\/' . $this->name . '.xml/', $url, $matches)) {
         return $this->execServer($request, array('_method' => $method, '_format' => $responseType, '_entity' => $this->name, '_action' => 'list'), $parameters, $responseType);
     }
     // PUT api/user.xml (insert)
     if ($method === 'PUT' && preg_match_all('/api\\/' . $this->name . '.xml/', $url, $matches)) {
         return $this->execServer($request, array('_method' => $method, '_format' => $responseType, '_entity' => $this->name, '_action' => 'insert'), $parameters, $responseType);
     }
     // POST api/user/1.xml (update)
     if ($method === 'POST' && preg_match_all('/api\\/' . $this->name . '\\/([0-9]).xml/', $url, $matches)) {
         return $this->execServer($request, array('_method' => $method, '_format' => $responseType, '_entity' => $this->name, '_action' => 'update', '_id' => $parameters['id']), $parameters, $responseType);
     }
     // DELETE api/user/1.xml (delete)
     if ($method === 'DELETE' && preg_match_all('/api\\/' . $this->name . '\\/([0-9]).xml/', $url, $matches)) {
         return $this->execServer($request, array('_method' => $method, '_format' => $responseType, '_entity' => $this->name, '_action' => 'delete', '_id' => $matches[1][0]), $parameters, $responseType);
     }
 }
Beispiel #2
0
 public function execute(Request $request)
 {
     $url = $request->getUrl();
     $method = $request->getMethod();
     $parameters = $request->getParameters();
     $username = $request->getUsername();
     $password = $request->getPassword();
     $this->last = get_defined_vars();
     if ($url === 'http://api.people.com/article.xml') {
         if ($method === Client::PUT) {
             return array('id' => 1, 'title' => 'test');
         } else {
             if ($method === Client::POST) {
                 return $parameters;
             } else {
                 if ($method === Client::GET) {
                     return array('article' => array(array('id' => 1, 'title' => 'test1'), array('id' => 2, 'title' => 'test2')));
                 }
             }
         }
         return array();
     } else {
         if ($url === 'http://api.people.com/article/1.xml') {
             if ($method === Client::DELETE) {
                 return array('id' => 1, 'title' => 'test');
             } else {
                 if ($method === Client::GET) {
                     return array('id' => 1, 'title' => 'test');
                 }
             }
         }
     }
     return array();
 }