示例#1
0
 /**
  * @inheritdoc
  */
 public function multiRequest(array $urls)
 {
     $client = new Client();
     $requests = array();
     foreach ($urls as $urlName => $urlData) {
         if (is_string($urlData)) {
             $urlData = array($urlData, array());
         }
         $urlOptions = new Options($urlData[1]);
         $method = $urlOptions->get('method', 'GET', 'up');
         $args = $urlOptions->get('args');
         $url = 'GET' === $method ? Url::addArg((array) $args, $urlData[0]) : $urlData[0];
         $requests[$urlName] = $client->createRequest($method, $url, $this->_getClientOptions($urlOptions, $method, $args));
     }
     $httpResults = Pool::batch($client, $requests);
     /** @var string $resName */
     /** @var Response $httpResult */
     $result = array();
     $index = 0;
     $keys = array_keys($urls);
     foreach ($keys as $resName) {
         $httpResult = $httpResults->offsetGet($index++);
         $result[$resName] = array($httpResult->getStatusCode(), $httpResult->getHeaders(), $httpResult->getBody()->getContents());
     }
     return $result;
 }
示例#2
0
 /**
  * @return Soap|\SoapClient
  */
 protected function _getClient()
 {
     $host = Env::get('WEB_HOST', '127.0.0.1', Env::VAR_STRING);
     $port = Env::get('WEB_PORT', '8081', Env::VAR_STRING);
     $loc = Url::create(['host' => $host, 'port' => $port, 'path' => 'wsSSMaker.asmx']);
     /** @var Soap $client */
     $client = new \SoapClient($loc . '?WSDL', ['trace' => true, 'location' => $loc]);
     return $client;
 }
示例#3
0
文件: Helper.php 项目: JBZoo/CrossCMS
 /**
  * @param $testName
  * @param $request
  * @return Data
  */
 public function request($testName, $request)
 {
     $cms = Cms::getInstance();
     $host = Env::get('TEST_HOST', '127.0.0.1');
     $port = Env::get('TEST_PORT');
     $url = Url::create(['host' => $host, 'port' => $port]);
     $result = httpRequest($url, array_merge(['jbzoo-phpunit' => 1, 'jbzoo-phpunit-test' => $this->getTestName($testName), 'jbzoo-phpunit-type' => strtolower($cms['type'])], $request), 'GET', ['allow_redirects' => false, 'exceptions' => false, 'timeout' => 60, 'verify' => false]);
     if (!$result->getCode()) {
         var_dump($result);
     }
     return $result;
 }
示例#4
0
文件: File.php 项目: jbzoo/assets
 /**
  * Find source in variants.
  *
  * @return array
  */
 protected function _findSource()
 {
     $path = $this->_manager->getPath();
     if ($path->isVirtual($this->_source)) {
         return $path->get($this->_source);
     }
     if (Url::isAbsolute($this->_source)) {
         return $this->_source;
     }
     $fullPath = $path->get('root:' . $this->_source);
     return $fullPath;
 }
示例#5
0
文件: Image.php 项目: JBZoo/Html
 /**
  * Create img tag.
  *
  * @param string $src
  * @param string|array $class
  * @param string $id
  * @param array $attrs
  * @return string
  */
 public function render($src, $class = '', $id = '', array $attrs = array())
 {
     $attrs['class'] = false;
     $attrs = array_merge(array('fullUrl' => true), $attrs);
     $attrs['id'] = $id;
     $attrs = $this->_normalizeClassAttr($attrs, $this->_jbSrt('image'));
     if ($class !== '') {
         $attrs = $this->_normalizeClassAttr($attrs, $class);
     }
     $attrs['class'] = Str::clean($attrs['class']);
     $isFull = $attrs['fullUrl'];
     unset($attrs['fullUrl']);
     $src = FS::clean($src, '/');
     $attrs['src'] = $isFull ? Url::root() . '/' . $src : $src;
     return '<img ' . $this->buildAttrs($attrs) . ' />';
 }
示例#6
0
 /**
  * @inheritdoc
  */
 public function multiRequest(array $urls)
 {
     $client = new Client();
     $promises = array();
     foreach ($urls as $urlName => $urlData) {
         if (is_string($urlData)) {
             $urlData = array($urlData, array());
         }
         $urlOptions = new Options($urlData[1]);
         $method = $urlOptions->get('method', 'GET', 'up');
         $args = $urlOptions->get('args');
         $url = 'GET' === $method ? Url::addArg((array) $args, $urlData[0]) : $urlData[0];
         $promises[$urlName] = $client->requestAsync($method, $url, $this->_getClientOptions($urlOptions, $method, $args));
     }
     $httpResults = Promise\unwrap($promises);
     /** @var string $resName */
     /** @var Response $httpResult */
     $result = array();
     foreach ($httpResults as $resName => $httpResult) {
         $result[$resName] = array($httpResult->getStatusCode(), $httpResult->getHeaders(), $httpResult->getBody()->getContents());
     }
     return $result;
 }
示例#7
0
 /**
  * @inheritdoc
  */
 public function multiRequest(array $urls)
 {
     $requests = array();
     foreach ($urls as $urlName => $urlData) {
         if (is_string($urlData)) {
             $urlData = array($urlData, array());
         }
         $urlOptions = new Options($urlData[1]);
         $method = $urlOptions->get('method', 'GET', 'up');
         $args = $urlOptions->get('args');
         $url = 'GET' === $method ? Url::addArg((array) $args, $urlData[0]) : $urlData[0];
         $args = 'GET' !== $method ? $args : array();
         $requests[$urlName] = array('url' => $url, 'headers' => $urlOptions->getHeaders(), 'data' => $args, 'type' => $method, 'options' => $this->_getClientOptions($urlOptions));
     }
     $httpResults = \Requests::request_multiple($requests);
     /** @var string $resName */
     /** @var \Requests_Response $httpResult */
     $result = array();
     foreach ($httpResults as $resName => $httpResult) {
         $result[$resName] = array($httpResult->status_code, $httpResult->headers->getAll(), $httpResult->body);
     }
     return $result;
 }
示例#8
0
 /**
  * @param string            $url
  * @param string|array|null $args
  * @param string            $method
  * @param array             $options
  * @return Response
  * @throws Exception
  */
 public function request($url, $args = null, $method = Options::DEFAULT_METHOD, array $options = array())
 {
     $method = Filter::up($method);
     $url = 'GET' === $method ? Url::addArg((array) $args, $url) : $url;
     $options = new Options(array_merge($this->_options->getArrayCopy(), $options));
     $client = $this->_getClient($options);
     $response = new Response();
     try {
         list($code, $headers, $body) = $client->request($url, $args, $method, $options);
         $response->setCode($code);
         $response->setHeaders($headers);
         $response->setBody($body);
     } catch (\Exception $e) {
         if ($options->isExceptions()) {
             throw new Exception($e->getMessage(), $e->getCode(), $e);
         } else {
             $response->setCode($e->getCode());
             $response->setHeaders(array());
             $response->setBody($e->getMessage());
         }
     }
     return $response;
 }
示例#9
0
文件: PathTest.php 项目: JBZoo/Path
 public function testFullUrl()
 {
     $path = Path::getInstance(__METHOD__);
     $fs = new Filesystem();
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/custom';
     $paths = array($this->_root . DS . 'my-folder', $this->_root . DS . 'my-folder2' . DS . 'dir', $this->_root);
     foreach ($paths as $key => $p) {
         $fs->mkdir($p);
         $fs->dumpFile($p . DS . 'file' . $key . '.txt', '');
     }
     $fs->dumpFile($this->_root . DS . 'my-folder2' . DS . 'my-file.txt', '');
     list($path1, $path2) = $paths;
     $path->setRoot($this->_root);
     $path->set('default', $paths);
     $current = Url::root() . '/';
     $file1 = $current . 'my-folder2/dir/file1.txt';
     $file2 = $current . 'my-folder/file0.txt';
     $file3 = $current . 'my-folder2/my-file.txt';
     $this->_is($file1, $path->url('default:file1.txt'));
     $this->_is($file3, $path->url('default:my-folder2/my-file.txt'));
     $this->_is($file3, $path->url('default:my-folder2\\\\my-file.txt'));
     $this->_is($file3, $path->url('default:\\my-folder2\\my-file.txt'));
     $this->_is($file1, $path->url($path2 . DS . 'file1.txt'));
     $this->_is($file2, $path->url($path1 . DS . 'file0.txt'));
     $this->_is($file2, $path->url($path1 . '/file0.txt'));
     $this->_is($file3, $path->url($this->_root . '\\my-folder2\\my-file.txt'));
     $this->_is($file3, $path->url($this->_root . '/my-folder2////my-file.txt'));
     $this->_is($file3, $path->url($this->_root . DS . 'my-folder2' . DS . 'my-file.txt'));
     $this->_is($file2 . '?data=test&value=hello', $path->url($path1 . DS . 'file0.txt?data=test&value=hello'));
     isNull($path->url('default:file.txt'));
     isNull($path->url('alias:file.txt'));
     isNull($path->url($this->_root . DS . 'my-folder2' . DS . 'file.txt'));
     isNull($path->url($this->_root . 'my/' . DS . 'file.txt'));
     $fs->remove(array($path1, $path2, $this->_root . DS . 'my-folder2', $this->_root . DS . 'file2.txt'));
 }
示例#10
0
文件: UrlTest.php 项目: jbzoo/utils
 public function testRootBugWithPost3()
 {
     $_SERVER['HTTP_HOST'] = '127.0.0.1';
     $_SERVER['SERVER_PORT'] = 80;
     isSame('http://127.0.0.1', Url::root());
 }
示例#11
0
 /**
  * @return string
  */
 public function getUri()
 {
     return Url::current();
 }
示例#12
0
 public function testRedirect()
 {
     $url = Url::addArg(array('url' => 'http://example.com'), 'http://httpbin.org/redirect-to');
     $result = $this->_getClient()->request($url);
     isSame(200, $result->code);
     isContain('text/html', $result->find('headers.content-type'));
     isContain('Example', $result->body);
 }
示例#13
0
文件: Image.php 项目: JBZoo/Image
 /**
  * Get full URL to image (if not CLI mode)
  *
  * @return string
  * @throws Exception
  */
 public function getUrl()
 {
     return Url::root() . '/' . $this->getPath();
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 public function request($url, $args = array(), array $options = array())
 {
     $result = null;
     // Merge with default
     $options = array_merge($this->_defaultOptions, (array) $options);
     $options = new Data($options);
     // Prepare options for request
     $args = is_string($args) ? $args : (array) $args;
     $timeout = (int) $options->get('timeout');
     $isDebug = (int) $options->get('debug');
     $sslVerify = (int) $options->get('ssl_verify');
     $headers = (array) $options->get('headers');
     $userAgent = trim($options->get('user_agent'));
     $resultType = Str::clean($options->get('response'), true);
     // Prepare options for cache
     $isCache = (int) $options->get('cache');
     $cacheTTL = (int) $options->get('cache_ttl');
     $cacheId = array('url' => $url, 'data' => $args, 'options' => $options->getArrayCopy());
     try {
         // Check cache
         if ($isCache && ($result = $this->_cms['cache']->get($cacheId, self::CACHE_GROUP))) {
             return $result;
         }
         $method = $this->_getMethod($options->get('method'));
         // Add args to url for GET methods
         if (self::METHOD_GET === $method) {
             $url = Url::addArg($args, $url);
             $args = array();
         }
         // Request via CMS API
         $apiResp = $this->_request($url, $args, new Data(array('timeout' => $timeout, 'headers' => $headers, 'method' => $method, 'debug' => $isDebug, 'user_agent' => $userAgent, 'ssl_verify' => $sslVerify)));
     } catch (\Exception $e) {
         $apiResp = new Data(array('body' => 'CrossCMS Error: ' . $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString(), 'headers' => array(), 'code' => 0));
     }
     // Prepare response format
     $response = $this->_compactResponse($apiResp);
     $result = $this->_getResultByType($response, $resultType);
     // Store to cache
     if ($isCache && null !== $result) {
         $this->_cms['cache']->set($cacheId, $result, self::CACHE_GROUP, true, $cacheTTL);
     }
     return $result;
 }
示例#15
0
use JBZoo\Utils\Env;
use JBZoo\Utils\Url;
use Slim\Http\Request;
use Slim\Http\Response;
$_SERVER['SCRIPT_NAME'] = '/index.php';
// #F**K!!! https://bugs.php.net/bug.php?id=61286
if (!isset($app)) {
    // For PHPUnit reports
    return;
}
/** @var \Slim\App $app */
$app->any('/wsSSMaker.asmx', function (Request $req, Response $resp) {
    $serverHost = Env::get('WEB_HOST', $_SERVER['HTTP_HOST'], Env::VAR_STRING);
    $serverPort = Env::get('WEB_PORT', $_SERVER['SERVER_PORT'], Env::VAR_STRING);
    $cleanHost = str_replace(':' . $serverPort, '', $serverHost);
    $location = Url::create(['host' => $cleanHost, 'port' => $serverPort, 'path' => '/wsSSMaker.asmx']);
    $wsdlFile = __DIR__ . '/ssmaker.wsdl';
    if ($req->getParam('WSDL') === '') {
        /** @var Response $resp */
        $resp = $resp->withHeader('Expires', 'Wed, 11 Jan 1984 05:00:00 GMT');
        $resp = $resp->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
        $resp = $resp->withHeader('Cache-Control', 'no-cache, must-revalidate, max-age=0');
        $resp = $resp->withHeader('Pragma', 'no-cache');
        $resp = $resp->withHeader('Content-type', 'application/wsdl+xm');
        $resp->getBody()->write(file_get_contents($wsdlFile));
        return $resp;
    } else {
        $server = new SoapServer($wsdlFile, ['location' => $location]);
        $server->setClass('JBZoo\\SSmakerServer\\Soap');
        $server->handle();
    }
示例#16
0
文件: Path.php 项目: JBZoo/Path
 /**
  * Get url to a file.
  *
  * @param string    $source (example: "default:file.txt" or "C:\server\test.dev\file.txt")
  * @param bool|true $full
  * @return null|string
  */
 public function url($source, $full = true)
 {
     $details = explode('?', $source);
     $path = $details[0];
     $path = $this->_cleanPath($path);
     $path = $this->_getUrlPath($path, true);
     if (!empty($path)) {
         if (isset($details[1])) {
             $path .= '?' . $details[1];
         }
         $path = '/' . $path;
         return $full ? Url::root() . $path : $path;
     }
     return null;
 }
示例#17
0
文件: Less.php 项目: jbzoo/less
 /**
  * @param string|null $basepath
  * @param string      $default
  * @return string
  */
 protected function _prepareBasepath($basepath, $default)
 {
     $basepath = $basepath ?: $default;
     if (!Url::isAbsolute($basepath)) {
         $basepath = trim($basepath, '\\/');
         $basepath = $this->_options->get('root_url') . '/' . $basepath;
     }
     return $basepath;
 }
示例#18
0
文件: User.php 项目: JBZoo/CrossCMS
 /**
  * Get user avatar by email
  *
  * @param int    $avatarSize
  * @param string $defaultPic
  * @return string
  */
 public function getAvatar($avatarSize = 64, $defaultPic = 'identicon')
 {
     $md5 = md5(trim($this->_email));
     $avatarSize = (int) $avatarSize;
     $defaultPic = trim($defaultPic);
     $validList = array('404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
     if (strpos($defaultPic, 'http') === 0) {
         $default = urlencode($defaultPic);
     } elseif (Arr::in((string) $defaultPic, $validList)) {
         $default = $defaultPic;
     } else {
         $default = 'identicon';
     }
     if (Url::isHttps()) {
         $avatarUrl = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatarSize . '&d=' . $default;
     } else {
         $avatarUrl = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatarSize . '&d=' . $default;
     }
     return $avatarUrl;
 }