本文整理汇总了PHP中Zend_Uri_Http::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Uri_Http::check方法的具体用法?PHP Zend_Uri_Http::check怎么用?PHP Zend_Uri_Http::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Uri_Http
的用法示例。
在下文中一共展示了Zend_Uri_Http::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
/**
* Returns true if and only if $value meets the validation requirements
*
* If $value fails validation, then this method returns false, and
* getMessages() will return an array of messages that explain why the
* validation failed.
*
* @param mixed $value the value to validate
*
* @throws Zend_Valid_Exception If validation of $value is impossible
* @return boolean
*/
public function isValid($value)
{
$value = (string) $value;
$this->_setValue($value);
if (!Zend_Uri_Http::check($value)) {
$this->_error(self::MALFORMED_URL);
return false;
}
return true;
}
示例2: get
/**
* Send a GET HTTP Request
*
* @param int $redirectMax Maximum number of HTTP redirections followed
* @return Zend_Http_Response
*/
public function get($redirectMax = 5)
{
/**
* @todo Implement ability to send Query Strings
*/
// Follow HTTP redirections, up to $redirectMax of them
for ($redirect = 0; $redirect <= $redirectMax; $redirect++) {
// Build the HTTP request
$hostHeader = $this->_uri->getHost() . ($this->_uri->getPort() == 80 ? '' : ':' . $this->_uri->getPort());
$request = array_merge(array('GET ' . $this->_uri->getPath() . '?' . $this->_uri->getQuery() . ' HTTP/1.0', 'Host: ' . $hostHeader, 'Connection: close'), $this->_headers);
// Open a TCP connection
$socket = $this->_openConnection();
// Make the HTTP request
fwrite($socket, implode("\r\n", $request) . "\r\n\r\n");
// Fetch the HTTP response
$response = $this->_read($socket);
// If the HTTP response was a redirect, and we are allowed to follow additional redirects
if ($response->isRedirect() && $redirect < $redirectMax) {
// Fetch the HTTP response headers
$headers = $response->getHeaders();
// Attempt to find the Location header
foreach ($headers as $headerName => $headerValue) {
// If we have a Location header
if (strtolower($headerName) == "location") {
// Set the URI to the new value
if (Zend_Uri_Http::check($headerValue)) {
// If we got a well formed absolute URI, set it
$this->setUri($headerValue);
} else {
// Split into path and query and set the query
list($headerValue, $query) = explode('?', $headerValue, 2);
$this->_uri->setQueryString($query);
if (strpos($headerValue, '/') === 0) {
// If we got just an absolute path, set it
$this->_uri->setPath($headerValue);
} else {
// Else, assume we have a relative path
$path = dirname($this->_uri->getPath());
$path .= $path == '/' ? $headerValue : "/{$headerValue}";
$this->_uri->setPath($path);
}
}
// Continue with the new redirected request
continue 2;
}
}
}
// No more looping for HTTP redirects
break;
}
// Return the HTTP response
return $response;
}
示例3: __construct
/**
* Create a new request object
*
* @param Zend_Uri_Http|string $url Target URL
* @param string $method HTTP request method - default is GET
*/
public function __construct($uri, $method = 'GET')
{
if (!$uri instanceof Zend_Uri_Http) {
if (!Zend_Uri_Http::check($uri)) {
require_once 'Spizer/Exception.php';
throw new Spizer_Exception("'{$uri}' is not a valid HTTP URL");
}
$uri = Zend_Uri::factory($uri);
}
$this->_uri = $uri;
$this->_method = $method;
}
示例4: setUp
/**
* Set up the test case
*
*/
protected function setUp()
{
if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') && Zend_Uri_Http::check(TESTS_ZEND_HTTP_CLIENT_BASEURI)) {
$this->baseuri = TESTS_ZEND_HTTP_CLIENT_BASEURI;
if (substr($this->baseuri, -1) != '/') {
$this->baseuri .= '/';
}
$uri = $this->baseuri . $this->getName() . '.php';
$this->client = new Zend_Http_Client($uri, $this->config);
} else {
// Skip tests
$this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php");
}
}
示例5: suite
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend');
$suite->addTestSuite('Zend_Http_Client_StaticTest');
if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') && Zend_Uri_Http::check(TESTS_ZEND_HTTP_CLIENT_BASEURI)) {
$suite->addTestSuite('Zend_Http_Client_SocketTest');
$suite->addTestSuite('Zend_Http_Client_SocketKeepaliveTest');
} else {
$suite->addTestSuite('Zend_Http_Client_Skip_SocketTest');
}
$suite->addTestSuite('Zend_Http_Client_TestAdapterTest');
if (defined('TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY') && TESTS_ZEND_HTTP_CLIENT_HTTP_PROXY) {
$suite->addTestSuite('Zend_Http_Client_ProxyAdapterTest');
} else {
$suite->addTestSuite('Zend_Http_Client_Skip_ProxyAdapterTest');
}
//$suite->addTestSuite('Zend_Http_Client_CurlTest');
return $suite;
}
示例6: setUp
/**
* Set up the test case
*
*/
protected function setUp()
{
if (defined('TESTS_ZEND_HTTP_CLIENT_BASEURI') && Zend_Uri_Http::check(TESTS_ZEND_HTTP_CLIENT_BASEURI)) {
$this->baseuri = TESTS_ZEND_HTTP_CLIENT_BASEURI;
if (substr($this->baseuri, -1) != '/') {
$this->baseuri .= '/';
}
$name = $this->getName();
if (($pos = strpos($name, ' ')) !== false) {
$name = substr($name, 0, $pos);
}
$uri = $this->baseuri . $name . '.php';
$this->_adapter = new $this->config['adapter']();
$this->client = new Zend_Http_Client($uri, $this->config);
$this->client->setAdapter($this->_adapter);
} else {
// Skip tests
$this->markTestSkipped("Zend_Http_Client dynamic tests are not enabled in TestConfiguration.php");
}
}
示例7: setUp
public function setUp()
{
if (defined('TESTS_Zend_Feed_Pubsubhubbub_BASEURI') && Zend_Uri_Http::check(TESTS_Zend_Feed_Pubsubhubbub_BASEURI)) {
$this->_baseuri = TESTS_Zend_Feed_Pubsubhubbub_BASEURI;
if (substr($this->_baseuri, -1) != '/') {
$this->_baseuri .= '/';
}
$name = $this->getName();
if (($pos = strpos($name, ' ')) !== false) {
$name = substr($name, 0, $pos);
}
$uri = $this->_baseuri . $name . '.php';
$this->_adapter = new $this->_config['adapter']();
$this->_client = new Zend_Http_Client($uri, $this->_config);
$this->_client->setAdapter($this->_adapter);
Zend_Feed_Pubsubhubbub::setHttpClient($this->_client);
$this->_subscriber = new Zend_Feed_Pubsubhubbub_Subscriber();
$this->_subscriber->setStorage(new Zend_Feed_Pubsubhubbub_Storage_Filesystem());
} else {
// Skip tests
$this->markTestSkipped("Zend_Feed_Pubsubhubbub_Subscriber dynamic tests'\n . ' are not enabled in TestConfiguration.php");
}
}
示例8: array
Loader::helper('mime');
$error = array();
// load all the incoming fields into an array
$incoming_urls = array();
if (!function_exists('iconv_get_encoding')) {
$errors[] = t('Remote URL import requires the iconv extension enabled on your server.');
}
if (count($errors) == 0) {
for ($i = 1; $i < 6; $i++) {
$this_url = trim($_REQUEST['url_upload_' . $i]);
// did we get anything?
if (!strlen($this_url)) {
continue;
}
// validate URL
if (Zend_Uri_Http::check($this_url)) {
// URL appears to be good... add it
$incoming_urls[] = $this_url;
} else {
$errors[] = Loader::helper('text')->specialchars($this_url) . t(' is not a valid URL.');
}
}
if (!$valt->validate('import_remote')) {
$errors[] = $valt->getErrorMessage();
}
if (count($incoming_urls) < 1) {
$errors[] = t('You must specify at least one valid URL.');
}
}
$import_responses = array();
// if we haven't gotten any errors yet then try to process the form
示例9: run
/**
* Run the crawler until we hit the last URL
*
* @param string $url URL to start crawling from
*/
public function run($url)
{
if (!Zend_Uri_Http::check($url)) {
require_once 'Spizer/Exception.php';
throw new Spizer_Exception("'{$url}' is not a valid HTTP URI");
}
$this->_baseUri = Zend_Uri::factory($url);
$this->_queue->append($url);
// Set the default logger if not already set
if (!$this->logger) {
require_once 'Spizer/Logger/Xml.php';
$this->logger = new Spizer_Logger_Xml();
}
// Go!
while ($request = $this->_queue->next()) {
$this->logger->startPage();
$this->logger->logRequest($request);
// Prepare HTTP client for next request
$this->_httpClient->resetParameters();
$this->_httpClient->setUri($request->getUri());
$this->_httpClient->setMethod($request->getMethod());
$this->_httpClient->setHeaders($request->getAllHeaders());
$this->_httpClient->setRawData($request->getBody());
// Send request, catching any HTTP related issues that might happen
try {
$response = new Spizer_Response($this->_httpClient->request());
} catch (Zend_Exception $e) {
fwrite(STDERR, "Error executing request: {$e->getMessage()}.\n");
fwrite(STDERR, "Request information:\n");
fwrite(STDERR, " {$request->getMethod()} {$request->getUri()}\n");
fwrite(STDERR, " Referred by: {$request->getReferrer()}\n");
}
$this->logger->logResponse($response);
// Call handlers
$this->_callHandlers($request, $response);
// End page
$this->logger->endPage();
++$this->_requestCounter;
// Wait if a delay was set
if (isset($this->_config['delay'])) {
sleep($this->_config['delay']);
}
}
}
示例10: setCloud
/**
* Cloud to be notified of updates of the feed
* Ignored if atom is used
*
* @param string|Zend_Uri_Http $uri
* @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify
* @param string $protocol protocol to use, e.g. soap or xml-rpc
* @return Zend_Feed_Builder_Header
* @throws Zend_Feed_Builder_Exception
*/
public function setCloud($uri, $procedure, $protocol)
{
if (is_string($uri) && Zend_Uri_Http::check($uri)) {
$uri = Zend_Uri::factory($uri);
}
if (!$uri instanceof Zend_Uri_Http) {
/**
* @see Zend_Feed_Builder_Exception
*/
#require_once 'Zend/Feed/Builder/Exception.php';
throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI');
}
if (!$uri->getPort()) {
$uri->setPort(80);
}
$this->offsetSet('cloud', array('uri' => $uri, 'procedure' => $procedure, 'protocol' => $protocol));
return $this;
}
示例11: setExpressCheckout
/**
* Preform a SetExpressCheckout PayPal API call, starting an Express
* Checkout process.
*
* This call is expected to return a token which can be used to redirect
* the user to PayPal's transaction approval page
*
* @param float $amount
* @param string $returnUrl
* @param string $cancelUrl
* @param array $params Additional parameters
* @return Zend_Service_PayPal_Response
*/
public function setExpressCheckout($amount, $returnUrl, $cancelUrl, $params = array())
{
$amount = (double) $amount;
if (!Zend_Uri_Http::check($returnUrl)) {
require_once 'Zend/Service/PayPal/Exception.php';
throw new Zend_Service_PayPal_Exception('Return URL is not a valid URL');
}
if (!Zend_Uri_Http::check($cancelUrl)) {
require_once 'Zend/Service/PayPal/Exception.php';
throw new Zend_Service_PayPal_Exception('Cancel URL is not a valid URL');
}
if (!is_array($params)) {
require_once 'Zend/Service/PayPal/Exception.php';
throw new Zend_Service_PayPal_Exception('$params is expected to be an array, ' . gettype($params) . ' given');
}
$this->prepare('SetExpressCheckout');
$this->httpClient->setParameterPost(array('AMT' => $amount, 'RETURNURL' => $returnUrl, 'CANCELURL' => $cancelUrl));
foreach ($params as $k => $v) {
$this->httpClient->setParameterPost(strtoupper($k), $v);
}
return $this->process();
}
示例12: setUri
/**
* Set the URI for the next request
*
* @param Zend_Uri_Http|string $uri
*/
public function setUri($uri)
{
if (is_string($uri) && Zend_Uri_Http::check($uri)) {
$uri = Zend_Uri_Http::factory($uri);
}
if ($uri instanceof Zend_Uri_Http) {
// We have no ports, set the defaults
if (!$uri->getPort()) {
$uri->setPort($uri->getScheme() == 'https' ? 443 : 80);
}
$this->uri = $uri;
} else {
throw new Zend_Http_Exception('Passed parameter is not a valid HTTP URI.');
}
}
示例13: setURI
/**
* Extract the path, file and query string from the URI
*
* @param string $uri
* @return void
*/
protected function setURI($uri)
{
$this->uri = $uri;
if (Zend_Uri_Http::check($uri)) {
$uri = Zend_Uri::factory($uri);
$this->query_string = $uri->getQuery();
$this->path = dirname($uri->getPath());
$this->file = basename($uri->getPath());
} else {
list($this->path, $this->query_string) = explode('?', $uri, 2);
$this->file = basename($this->path);
$this->path = dirname($this->path);
}
if (!$this->path) {
$this->path = '/';
}
parse_str($this->query_string, $this->get);
}
示例14: request
/**
* Send the HTTP request and return an HTTP response object
*
* @param string $method
* @return Zend_Http_Response
*/
public function request($method = null)
{
if (!$this->uri instanceof Zend_Uri_Http) {
throw new Zend_Http_Client_Exception("No valid URI has been passed to the client");
}
if ($method) {
$this->setMethod($method);
}
$this->redirectCounter = 0;
$response = null;
// Send the first request. If redirected, continue.
do {
// Clone the URI and add the additional GET parameters to it
$uri = clone $this->uri;
$uri_params = array();
parse_str($uri->getQuery(), $uri_params);
$uri->setQuery(array_merge($uri_params, $this->paramsGet));
$body = $this->prepare_body();
$headers = $this->prepare_headers();
$request = implode("\r\n", $headers) . "\r\n" . $body;
$this->last_request = $request;
// Open the connection, send the request and read the response
$this->adapter->connect($uri->getHost(), $uri->getPort(), $uri->getScheme() == 'https' ? true : false);
$this->adapter->write($this->method, $uri, $this->config['httpversion'], $headers, $body);
$response = Zend_Http_Response::factory($this->adapter->read());
// Load cookies into cookie jar
if (isset($this->Cookiejar)) {
$this->Cookiejar->addCookiesFromResponse($response, $uri);
}
// If we got redirected, look for the Location header
if ($response->isRedirect() && ($location = $response->getHeader('location'))) {
// Check whether we send the exact same request again, or drop the parameters
// and send a GET request
if ($response->getStatus() == 303 || !$this->config['strictredirects'] && ($response->getStatus() == 302 || $response->getStatus() == 301)) {
$this->resetParameters();
$this->setMethod(self::GET);
}
// If we got a well formed absolute URI
if (Zend_Uri_Http::check($location)) {
$this->setHeaders('host', null);
$this->setUri($location);
} else {
// Split into path and query and set the query
list($location, $query) = explode('?', $location, 2);
$this->uri->setQueryString($query);
// Else, if we got just an absolute path, set it
if (strpos($location, '/') === 0) {
$this->uri->setPath($location);
// Else, assume we have a relative path
} else {
// Get the current path directory, removing any trailing slashes
$path = rtrim(dirname($this->uri->getPath()), "/");
$this->uri->setPath($path . '/' . $location);
}
}
$this->redirectCounter++;
} else {
// If we didn't get any location, stop redirecting
break;
}
} while ($this->redirectCounter < $this->config['maxredirects']);
return $response;
}
示例15: isUrl
/**
* Checks if the given value is a valid URL.
*
* @param string $value
* @return boolean True if a valid URL was passed, false otherwise.
*/
protected function isUrl($value)
{
return Zend_Uri_Http::check($value);
}