setMethod() public static method

Sets the request method.
public static setMethod ( string $method )
$method string
Example #1
0
 /**
  * @return Request
  */
 public static function getRequest($url, $params = [])
 {
     $req = new Request($_REQUEST, $_SERVER);
     $req->setMethod("get")->setUrl($url);
     $req->inputs = $params;
     return $req;
 }
Example #2
0
 public function execute($entity, $url = null, $method = Client::GET, $parameters = null)
 {
     if (is_object($entity)) {
         $className = get_class($entity);
     } else {
         $className = $entity;
     }
     $configuration = $this->getEntityConfiguration($className);
     $request = new Request();
     $request->setUrl($url);
     $request->setMethod($method);
     $request->setParameters($parameters);
     $request->setUsername($configuration->getUsername());
     $request->setPassword($configuration->getPassword());
     $request->setResponseType($configuration->getResponseType());
     $request->setResponseTransformerImpl($configuration->getResponseTransformerImpl());
     $result = $this->_client->execute($request);
     if (is_array($result)) {
         $name = $configuration->getName();
         $identifierKey = $configuration->getIdentifierKey();
         $className = $configuration->getClass();
         if (isset($result[$name]) && is_array($result[$name])) {
             $collection = array();
             foreach ($result[$name] as $data) {
                 $identifier = $data[$identifierKey];
                 if (isset($this->_identityMap[$className][$identifier])) {
                     $instance = $this->_identityMap[$className][$identifier];
                 } else {
                     $instance = $configuration->newInstance();
                     $this->_identityMap[$className][$identifier] = $instance;
                 }
                 $collection[] = $this->_hydrate($configuration, $instance, $data);
             }
             return $collection;
         } else {
             if ($result) {
                 if (is_object($entity)) {
                     $instance = $entity;
                     $this->_hydrate($configuration, $instance, $result);
                     $identifier = $this->getEntityIdentifier($instance);
                     $this->_identityMap[$className][$identifier] = $instance;
                 } else {
                     $identifier = $result[$identifierKey];
                     if (isset($this->_identityMap[$className][$identifier])) {
                         $instance = $this->_identityMap[$className][$identifier];
                     } else {
                         $instance = $configuration->newInstance();
                         $this->_identityMap[$className][$identifier] = $instance;
                     }
                     $this->_hydrate($configuration, $instance, $result);
                 }
                 return $instance;
             }
         }
     } else {
         return array();
     }
 }
Example #3
0
 public function make()
 {
     $request = new Request();
     $request->setMethod($_SERVER['REQUEST_METHOD']);
     $request->setHost($_SERVER['HTTP_HOST']);
     $request->setPath(substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?') ?: strlen($_SERVER['REQUEST_URI'])));
     $request->setGet($_GET);
     $request->setPost($_POST);
     return $request;
 }
Example #4
0
 /**
  * Custom API call function
  */
 public function updateRequest($method, $headers = array(), $data = array())
 {
     // Set the custom headers.
     \Request::getFacadeRoot()->headers->replace($headers);
     // Set the custom method.
     \Request::setMethod($method);
     // Set the content body.
     if (is_array($data)) {
         \Input::merge($data);
     }
 }
Example #5
0
 /**
  * Custom API call function
  */
 public function updateRequest($method, $headers = array(), $data = array())
 {
     // Log in as admin - header
     $headers['Authorization'] = 'Basic YWRtaW46YWRtaW4=';
     // Set the custom headers.
     \Request::getFacadeRoot()->headers->replace($headers);
     // Set the custom method.
     \Request::setMethod($method);
     // Set the content body.
     if (is_array($data)) {
         \Input::merge($data);
     }
 }
 /**
  * HTTP POST METHOD (static)
  *
  * @param  string $url
  * @param  array $params
  * @param  array $headers
  * @param  mixed $body
  * @param  array|Traversable $clientOptions
  * @throws Exception\InvalidArgumentException
  * @return Response|bool
  */
 public static function post($url, $params, $headers = [], $body = null, $clientOptions = null)
 {
     if (empty($url)) {
         return false;
     }
     $request = new Request();
     $request->setUri($url);
     $request->setMethod(Request::METHOD_POST);
     if (!empty($params) && is_array($params)) {
         $request->getPost()->fromArray($params);
     } else {
         throw new Exception\InvalidArgumentException('The array of post parameters is empty');
     }
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = Client::ENC_URLENCODED;
     }
     if (!empty($headers) && is_array($headers)) {
         $request->getHeaders()->addHeaders($headers);
     }
     if (!empty($body)) {
         $request->setContent($body);
     }
     return static::getStaticClient($clientOptions)->send($request);
 }
Example #7
0
 /**
  * Create sitemap
  *
  * @return bool
  */
 public function sitemap()
 {
     // Generate a Sitemap Protocol v0.9 compliant sitemap (http://sitemaps.org)
     $this->_sitemap_xml = new XML();
     $this->_sitemap_xml->startElement('urlset', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
     // Generate Standard records
     $store_url = CC_SSL ? $GLOBALS['config']->get('config', 'ssl_url') : $GLOBALS['config']->get('config', 'standard_url');
     $this->_sitemap_link(array('url' => $store_url . '/index.php'));
     # Sale Items
     if ($GLOBALS['config']->get('config', 'catalogue_sale_mode') !== '0') {
         $this->_sitemap_link(array('url' => $store_url . '/index.php?_a=saleitems'));
     }
     # Gift Certificates
     if ($GLOBALS['config']->get('gift_certs', 'status') == '1') {
         $this->_sitemap_link(array('url' => $store_url . '/index.php?_a=certificates'));
     }
     $queryArray = array('category' => $GLOBALS['db']->select('CubeCart_category', array('cat_id'), array('status' => '1')), 'product' => $GLOBALS['db']->select('CubeCart_inventory', array('product_id', 'updated'), array('status' => '1')), 'document' => $GLOBALS['db']->select('CubeCart_documents', array('doc_id'), array('doc_parent_id' => '0', 'doc_status' => 1)));
     foreach ($queryArray as $type => $results) {
         if ($results) {
             foreach ($results as $record) {
                 switch ($type) {
                     case 'category':
                         $id = $record['cat_id'];
                         $key = 'cat_id';
                         break;
                     case 'product':
                         $id = $record['product_id'];
                         $key = 'product_id';
                         break;
                     case 'document':
                         $id = $record['doc_id'];
                         $key = 'doc_id';
                         break;
                 }
                 $this->_sitemap_link(array('key' => $key, 'id' => $id), !isset($record['updated']) ? (int) $record['updated'] : time(), $type);
             }
         }
     }
     $sitemap = $this->_sitemap_xml->getDocument(true);
     if (function_exists('gzencode')) {
         // Compress the file if GZip is enabled
         $filename = CC_ROOT_DIR . '/sitemap.xml.gz';
         $mapdata = gzencode($sitemap, 9, FORCE_GZIP);
     } else {
         $filename = CC_ROOT_DIR . '/sitemap.xml';
         $mapdata = $sitemap;
     }
     if ($GLOBALS['config']->get('config', 'offline') == '0') {
         if (file_put_contents($filename, $mapdata)) {
             // Ping Google
             $request = new Request('www.google.com', '/webmasters/sitemaps/ping');
             $request->setMethod('get');
             $request->setData(array('sitemap' => $store_url . '/' . basename($filename)));
             $request->send();
             return true;
         }
     }
     return false;
 }
Example #8
0
    unset($files);
    krsort($sorted_files);
    // Sort to time order
    foreach ($sorted_files as $file) {
        $filename = basename($file);
        $type = preg_match('/^database/', $filename) ? 'database' : 'files';
        $restore = preg_match('/^database_full|files/', $filename) ? '?_g=maintenance&node=index&restore=' . $filename . '#backup' : false;
        $existing_backups[] = array('filename' => $filename, 'delete_link' => '?_g=maintenance&node=index&delete=' . $filename . '#backup', 'download_link' => '?_g=maintenance&node=index&download=' . $filename . '#backup', 'restore_link' => $restore, 'type' => $type, 'warning' => $type == 'database' ? $lang['maintain']['restore_db_confirm'] : $lang['maintain']['restore_files_confirm'], 'size' => formatBytes(filesize($file), true));
    }
}
$GLOBALS['smarty']->assign('EXISTING_BACKUPS', $existing_backups);
## Upgrade
## Check current version
if ($request = new Request('www.cubecart.com', '/version-check/' . '2.3.22')) {
    $request->skiplog(true);
    $request->setMethod('get');
    $request->cache(true);
    $request->setSSL(true);
    $request->setUserAgent('CubeCart');
    $request->setData(array('version' => CC_VERSION));
    if (($response = $request->send()) !== false) {
        if (version_compare(trim($response), CC_VERSION, '>')) {
            $GLOBALS['smarty']->assign('OUT_OF_DATE', sprintf($lang['dashboard']['error_version_update'], $response, CC_VERSION));
            $GLOBALS['smarty']->assign('LATEST_VERSION', $response);
            $GLOBALS['smarty']->assign('UPGRADE_NOW', $lang['maintain']['upgrade_now']);
            $GLOBALS['smarty']->assign('FORCE', '0');
        } else {
            $GLOBALS['smarty']->assign('LATEST_VERSION', CC_VERSION);
            $GLOBALS['smarty']->assign('UPGRADE_NOW', $lang['maintain']['force_upgrade']);
            $GLOBALS['smarty']->assign('FORCE', '1');
        }
Example #9
0
 public function delete(Request $request)
 {
     $request->setMethod(Client::DELETE);
     return $this->execute($request);
 }
Example #10
0
 /**
  * @param Request $instance
  * @param array $params
  */
 protected function applyWebContext($instance, $params)
 {
     if (isset($params['REQUEST_METHOD'])) {
         $instance->setMethod($params['REQUEST_METHOD']);
     }
     if (isset($params['REMOTE_ADDR'])) {
         $instance->setAddress($params['REMOTE_ADDR']);
     }
 }
Example #11
0
 /**
  * 
  * HTTP DELETE
  * 
  * @param Request $request
  * @return mixed
  */
 public function delete(Request $request)
 {
     return $this->execute($request->setMethod(self::DELETE));
 }
Example #12
0
 /**
  * @param array $data
  * @throws Exception
  * @return self
  */
 public static function fromArray(array $data)
 {
     if (empty($data['jsonrpc'])) {
         throw new Exception('Request is not valid JsonRPC request: missing protocol version');
     }
     if ($data['jsonrpc'] != self::VERSION) {
         throw new Exception('Request is not valid JsonRPC request: invalid protocol version');
     }
     if (empty($data['method'])) {
         throw new Exception('Request is not valid JsonRPC request: missing method');
     }
     $request = new Request();
     $request->setMethod($data['method']);
     if (!empty($data['id'])) {
         $request->setId($data['id']);
     }
     if (!empty($data['params'])) {
         $request->setParams($data['params']);
     }
     return $request;
 }
Example #13
0
 /**
  * Creates a default Request based on the current PHP environment superglobals ($_SERVER, $_GET, $_POST, etc).
  */
 public static function extractFromEnvironment()
 {
     $getServerVar = function ($key) {
         return isset($_SERVER[$key]) ? $_SERVER[$key] : null;
     };
     $request = new Request();
     $request->setMethod($getServerVar('REQUEST_METHOD'));
     $request->setRequestUri($getServerVar('REQUEST_URI'));
     $request->setPostData($_POST);
     $request->setQueryData($_GET);
     $request->setEnvironmentData($_SERVER);
     $request->setCookieData($_COOKIE);
     $request->setFileData($_FILES);
     return $request;
 }
Example #14
0
 /**
  * Sets following request and sends it
  * @param Request $request
  * @param Response $response
  * @param int $maxRedirects
  * @return Response
  * @throws RequestException
  */
 private function doFollow(Request $request, Response $response, $maxRedirects)
 {
     /// Change method to GET
     $request->setMethod(Request::GET);
     /// Find out location
     $location = $response->getHeader('Location');
     if (strpos($location, '/') == 0 && $request->getUrl() != NULL) {
         $parsed = @parse_url($request->getUrl());
         if ($parsed == FALSE) {
             throw new \InvalidArgumentException('Invalid URL, got: ' . $request->getUrl());
         }
         $url = isset($parsed['scheme']) ? $parsed['scheme'] . '://' : '';
         if (isset($parsed['user']) && isset($parsed['pass'])) {
             $url .= $parsed['user'] . ':' . $parsed['pass'] . '@';
         }
         $url .= isset($parsed['host']) ? $parsed['host'] : '';
         $url .= isset($parsed['port']) ? ':' . $parsed['port'] : '';
         $url .= $location;
         $location = $url;
     }
     $request->setUrl($location);
     $request->addHeaders(array('Referer' => $request->getUrl()));
     $this->redirectCount++;
     return $this->send($request, true, $maxRedirects);
 }
Example #15
0
 /**
  * 生成语音文件
  * @param  string $name
  * @return string 语音数据
  */
 public function buildAudio($name = null)
 {
     $text_length = mb_strlen($this->tex, 'utf-8');
     $texParts = [];
     $index = 0;
     $max_index = ceil($text_length / self::TEXT_LIMIT) - 1;
     while ($index <= $max_index) {
         $texParts[] = mb_substr($this->tex, $index * self::TEXT_LIMIT, self::TEXT_LIMIT, 'utf-8');
         $text_length -= self::TEXT_LIMIT;
         $index++;
     }
     $requests = array();
     $counter = 1;
     foreach ($texParts as $tex) {
         $post_data = array('tex' => $this->doubleUrlencode($tex), 'lan' => $this->lan, 'tok' => $this->doubleUrlencode($this->tok), 'ctp' => $this->ctp, 'cuid' => $this->doubleUrlencode($this->cuid), 'spd' => $this->spd, 'pit' => $this->pit, 'vol' => $this->vol, 'per' => $this->per);
         $requests[] = array('url' => self::API_URL, 'options' => array(CURLOPT_HEADER => true, CURLOPT_POSTFIELDS => $this->buildPostBody($post_data)));
         $counter++;
     }
     // var_dump($requests);
     $Request = new Request();
     $Request->setMethod('post');
     $Request->setAsynRequests($requests);
     try {
         $Request->sendRequestAsyn();
         $responses = $Request->getAsynResponses();
         // var_dump($responses);
         // var_dump($post_data);
         // var_dump($Request->responseBody());
         if ($this->enableCache) {
             if ($this->mergeAudio === true) {
                 $audio_cache_name = $this->pathJoin($this->cacheRoot, $name . '.mp3');
             } else {
                 $audio_cache_dir = $this->pathJoin($this->cacheRoot, $name);
             }
             self::clearAudio($this->cacheRoot, $name, false);
         }
         $audio = '';
         $counter = 1;
         foreach ($responses as $response) {
             if ($response->responseHeaders['content-type'] == 'audio/mp3') {
                 $audio .= $response->responseBody;
                 if ($this->enableCache) {
                     if ($this->mergeAudio === true) {
                         try {
                             $this->cacheMergeAudio($response->responseBody, $audio_cache_name);
                         } catch (Exception $e) {
                             $this->error = $e->getMessage();
                             return false;
                         }
                     } else {
                         try {
                             $this->cacheAudio($response->responseBody, $audio_cache_dir, $counter . '.mp3');
                         } catch (Exception $e) {
                             $this->error = $e->getMessage();
                             return false;
                         }
                     }
                 }
             } elseif (strpos($response->responseHeaders['content-type'], 'json')) {
                 $error = json_decode($response->responseBody, true);
                 $this->error = $error['err_msg'];
                 return false;
             } else {
                 $this->error = 'Unkown error';
                 return false;
             }
             $counter++;
         }
         return $audio;
     } catch (Exception $e) {
         $this->error = $e->getMessage();
         return false;
     }
 }
Example #16
0
 protected function sendRequest($url, $content)
 {
     $request = new Request();
     $request->setMethod('POST')->setContent($content);
     return $request->send($url);
 }
Example #17
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
//Treat merge as patch
$method = Request::getMethod();
if (\DreamFactory\Library\Utility\Enums\Verbs::MERGE === strtoupper($method)) {
    Request::setMethod(\DreamFactory\Library\Utility\Enums\Verbs::PATCH);
}
Route::get('/', 'SplashController@index');
Route::get('/setup', 'SplashController@createFirstUser');
Route::post('/setup', 'SplashController@createFirstUser');
Route::get('/setup_db', 'SplashController@setupDb');
Route::post('/setup_db', 'SplashController@setupDb');
$resourcePathPattern = '[0-9a-zA-Z-_@&\\#\\!=,:;\\/\\^\\$\\.\\|\\{\\}\\[\\]\\(\\)\\*\\+\\? ]+';
$servicePattern = '[_0-9a-zA-Z-.]+';
Route::group(['prefix' => 'api'], function () use($resourcePathPattern, $servicePattern) {
    Route::get('{version}/', 'RestController@index');
    Route::get('{version}/{service}/{resource?}', 'RestController@handleGET')->where(['service' => $servicePattern, 'resource' => $resourcePathPattern]);
    Route::post('{version}/{service}/{resource?}', 'RestController@handlePOST')->where(['service' => $servicePattern, 'resource' => $resourcePathPattern]);
    Route::put('{version}/{service}/{resource?}', 'RestController@handlePUT')->where(['service' => $servicePattern, 'resource' => $resourcePathPattern]);
    Route::patch('{version}/{service}/{resource?}', 'RestController@handlePATCH')->where(['service' => $servicePattern, 'resource' => $resourcePathPattern]);
    Route::delete('{version}/{service}/{resource?}', 'RestController@handleDELETE')->where(['service' => $servicePattern, 'resource' => $resourcePathPattern]);
Example #18
0
    $GLOBALS['main']->addTabControl($lang['dashboard']['title_stock_warnings'], 'stock_warnings', null, null, $stock_count);
    $GLOBALS['smarty']->assign('STOCK_PAGINATION', $GLOBALS['db']->pagination($stock_count, $result_limit, $page, $show = 5, 'stock', 'stock_warnings', $glue = ' ', $view_all = true));
    foreach ($GLOBALS['hooks']->load('admin.dashboard.stock.post') as $hook) {
        include $hook;
    }
}
## Latest News (from RSS)
if ($GLOBALS['config']->has('config', 'default_rss_feed') && !$GLOBALS['config']->isEmpty('config', 'default_rss_feed') && filter_var($GLOBALS['config']->get('config', 'default_rss_feed'), FILTER_VALIDATE_URL)) {
    $default_rss_feed = $GLOBALS['config']->get('config', 'default_rss_feed');
    $url = preg_match('/(act=rssout&id=1|1-cubecart-news-announcements)/', $default_rss_feed) ? 'https://forums.cubecart.com/forum/1-news-announcements.xml' : $default_rss_feed;
    $url = parse_url($url);
    $path = isset($url['query']) ? $url['path'] . '?' . $url['query'] : $url['path'];
    $request = new Request($url['host'], $path);
    $request->cache(true);
    $request->skiplog(true);
    $request->setMethod('post');
    $request->setData('Null');
    if (($response = $request->send()) !== false) {
        try {
            if (($data = new SimpleXMLElement($response)) !== false) {
                foreach ($data->channel->children() as $key => $value) {
                    if ($key == 'item') {
                        continue;
                    }
                    $news[$key] = (string) $value;
                }
                if ($data['version'] >= 2) {
                    $i = 1;
                    foreach ($data->channel->item as $item) {
                        $news['items'][] = array('title' => (string) $item->title, 'link' => (string) $item->link);
                        if ($i == 5) {