/** * {@inheritDoc} */ public static function buildFromResponse(stdClass $response) { $eterminal = new self(); $eterminal->setUrl(isset($response->url) ? $response->url : null); $eterminal->raw = $response; return $eterminal; }
public static function post($url, $formData, $formEncoding = null) { $request = new self(); $request->setMethod('POST'); $request->setUrl($url); $request->setFormData($formData, $formEncoding); return $request->exec(); }
/** * Create Request from global arrays. * * @return Request */ public static function createFromGlobals() { $request = new self(); $request->setGetParams(filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING)); $request->setPostParams(filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING)); $request->setUrl($_SERVER['REQUEST_URI']); return $request; }
/** * fromReflection() * * @param Zend_Reflection_Docblock_Tag $reflectionTagReturn * @return Zend_CodeGenerator_Php_Docblock_Tag_License */ public static function fromReflection(Zend_Reflection_Docblock_Tag $reflectionTagLicense) { $returnTag = new self(); $returnTag->setName('license'); $returnTag->setUrl($reflectionTagLicense->getUrl()); $returnTag->setDescription($reflectionTagLicense->getDescription()); return $returnTag; }
/** * Add navigation node as a child * @staticvar int $counter * @param string $label * @param string $url * @param string $title * @return Node */ public function addNode($label, $url, $title = NULL) { $node = new self(); $node->setLabel($label); $node->setUrl($url); $node->setTitle($title); static $counter; $this->addComponent($node, ++$counter); return $node; }
/** * @param string $url * @param array $post * @param wfWAFHTTP $request * @return wfWAFHTTPResponse|bool * @throws wfWAFHTTPTransportException */ public static function post($url, $post = array(), $request = null) { if (!$request) { $request = new self(); } $request->setUrl($url); $request->setMethod('POST'); $request->setBody($post); $request->setTransport(wfWAFHTTPTransport::getInstance()); return $request->send(); }
/** * @param Campaign $campaign * @param array $array * @return Campaign|Content */ public static function createFromArray(Campaign $campaign = null, array $array = array()) { $defaults = array("view_count" => 0, "like_count" => 0, "dislike_count" => 0, "favorite_count" => 0, "comment_count" => 0, "tw_share_count" => 0, "fb_share_count" => 0); $array = array_merge($defaults, $array); $content = new self($array['id'], $campaign); $content->setSource($array['source']); $content->setFoundAt(new \DateTime($array['found_at'])); $content->setNativeId($array['native_id']); $content->setCreatedAt(new \DateTime($array['created_at'])); $content->setUrl($array['url']); $content->setThumb($array['thumb']); $content->setVideoSrc($array['video_src']); $content->setTitle($array['title']); $content->setDescription($array['description']); $content->setVideoLength($array['video_length']); $content->setUsername($array['username']); $content->setViewCount($array['view_count']); $content->setLikeCount($array['like_count']); $content->setDislikeCount($array['dislike_count']); $content->setFavCount($array['favorite_count']); $content->setCommentCount($array['comment_count']); $content->setTwCount($array['tw_share_count']); $content->setFbCount($array['fb_share_count']); $content->setProcessed($array['processed']); if ($array['processed']) { $content->setProcessedAt(new \DateTime($array['processed_at'])); } $content->setKeyword($array['keyword']); $content->setUserNativeId($array['user_native_id']); if (isset($array['popularity'])) { $content->setPopularity($array['popularity']); } if (isset($array['sr_status'])) { $content->setSrStatus($array['sr_status']); } else { if (isset($array['srstatus'])) { $content->setSrStatus($array['srstatus']); } } if (isset($array['followers'])) { $content->setUserReach($array['followers']); } return $content; }
/** * @param array $options * @return array|bool */ public static function addNotify($options = []) { if (isset($options['id'])) { $model = self::model()->findByPk((int) $options['id']); } else { $model = new self(); } if (isset($options['url'])) { $model->setUrl($options['url']); } if (isset($options['image'])) { $model->setImage($options['image']); } $model->setAttributes($options, false); if ($model->save()) { if (isset($options['read']) && (isset($options['user_id']) && (int) $options['user_id'] > 0)) { self::changeReadStatusById($model->id, $options['user_id'], $options['read']); } if (isset($options['id'])) { $model->onUpdateNotify($model); } else { $model->onAddNotify($model); } return true; } else { return $model->getErrors(); } }
/** * Create instance of self * * @param string $response * @param string $url * @param array $post_data * * @return \Namecheap\Connect\NamecheapResponse */ private static function instantiateSelf($response, $url, $post_data) { $instance = new self(); $instance->setResponse($response); $instance->setUrl($url); $instance->setPostData($post_data); return $instance; }
public function translate() { // Initialize the response with the current state $request = new self(array(), $this->url, $this->status); // Attempt to translate the url until no more translations are found do { // If this flag is set to true, then translation will continue another round $translated = false; // Routes is formatted as `array(url-pattern-to-match => rewrite-instructions, ...)`. // Step through each route and try to match the base URL pattern with the current URL foreach ($this->routes as $route) { // A match with the current URL was found if (preg_match($route->pattern, $request->url)) { // Rewrite the URL $request->setUrl(preg_replace($route->pattern, $route->rewrite, $request->url)); $translated = true; // Optional: If a new status was provided, set it if ($route->status !== false) { $request->setStatus($route->status); } // If the `last` flag is set or a redirect is required, then stop all translations if (!empty($route->is_last) || $request->isStatusRedirect()) { $translated = false; break; } } } } while ($translated); // Make sure that the URL is set strictly as a path $url_parts = parse_url($request->getUrl(false)); $request->setUrl($url_parts['path']); // Inject rewritten URL params into _GET if (!empty($url_parts['query'])) { $params = array(); parse_str($url_parts['query'], $params); $_GET = array_merge($_GET, $params); } // If the new status is a redirect if ((int) ($request->status / 100) == 3) { // Clean up the query string before creeating the new request unset($_GET[GOBE_QUERY_PATH]); unset($_GET[GOBE_QUERY_STATUS]); header("Location: " . $url_parts['path'] . '?' . http_build_query($_GET), true, $request->status); die; } // Set the new status in the HTTP header // header("gobe-status", true, $request->status); return $request; }
public static function create($data, $obj = null) { $obj = new self(); $obj->setUrl($data['image']); parent::create($data, $obj); }
/** * * @param array $data * @return Folder */ public static function create(array $data = array()) { $defaults = array('id' => null, 'parent_id' => null, 'name' => null, 'url' => null, 'uuid' => null, 'data' => new IdentifiableDataContainer(array())); $data = array_merge($defaults, $data); $obj = new self(); $obj->setId($data['id']); $obj->setParentId($data['parent_id']); $obj->setName($data['name']); $obj->setUrl($data['url']); $obj->setUuid($data['uuid']); $obj->setData($data['data']); return $obj; }
/** * Create an instance from a stringified request. * @param string $str the stringified request * @return \vakata\http\Request the request instance * @codeCoverageIgnore */ public static function fromString($str) { $req = new self(); $break = strpos($str, "\r\n\r\n") === false ? "\n" : "\r\n"; // just in case someone breaks RFC 2616 list($headers, $message) = explode($break . $break, $str, 2); $headers = explode($break, preg_replace("(" . $break . "\\s+)", " ", $headers)); if (isset($headers[0]) && strlen($headers[0])) { $temp = explode(' ', $headers[0]); if (in_array($temp[0], ['GET', 'POST', 'HEAD', 'PATCH', 'PUT', 'OPTIONS', 'TRACE', 'DELETE'])) { $req->setMethod($temp[0]); $req->setUrl($temp[1]); if (isset($temp[2])) { $req->setProtocolVersion(substr($temp[2], 5)); } unset($headers[0]); $headers = array_values($headers); } } foreach (array_filter($headers) as $v) { $v = explode(':', $v, 2); $req->setHeader(trim($v[0]), trim($v[1])); } if ($req->hasHeader('Host')) { $host = explode(':', $req->getHeader('Host'), 2); $req->getUrl()->setHost($host[0]); if (isset($host[1]) && (int) $host[1]) { $req->getUrl()->setPort($host[1]); } } if (strpos($req->getHeader('Content-Type'), 'multipart') !== false) { $bndr = trim(explode(' boundary=', $req->getHeader('Content-Type'))[1], '"'); $parts = explode($break . '--' . $bndr, $break . $message); array_pop($parts); array_shift($parts); $post = []; foreach ($parts as $item) { list($head, $body) = explode($break . $break, $item, 2); $head = explode($break, preg_replace("(" . $break . "\\s+)", " ", $head)); foreach ($head as $h) { if (strpos(strtolower($h), 'content-disposition') === 0) { $cd = explode(';', $h); $name = ''; $file = ''; foreach ($cd as $p) { if (strpos(trim($p), 'name=') === 0) { $name = trim(explode('name=', $p)[1], ' "'); } if (strpos(trim($p), 'filename=') === 0) { $file = trim(explode('filename=', $p)[1], ' "'); } } if ($file) { $req->addUpload($name, $body, $file); } else { $post[$name] = $body; } } } } $req->setBody(http_build_query($post)); } elseif (strlen($message)) { $req->setBody($message); } $req->removeHeader('Content-Length'); $req->removeHeader('Transfer-Encoding'); return $req; }
/** * Return a request based on a simple url. * @param string $url * @param string $stripHost * @return Request */ public static function fromURL($url, $stripHost) { $data = parse_url($url); $parameters = array(); if (!empty($data['query'])) { parse_str($data['query'], $parameters); } $request = new self(); if ($stripHost) { $request->setUrl($data['path']); } else { $request->setUrl($data['scheme'] . '://' . $data['host'] . (isset($data['port']) ? ':' . $data['port'] : '') . $data['path']); } $request->setParameters($parameters); return $request; }
/** * Creates a new Deployment from parsed response body. * * @param array $parsed The parsed response body in array representation. * * @return Deployment */ public static function create($parsed) { $result = new self(); $name = Utilities::tryGetValue($parsed, Resources::XTAG_NAME); $label = Utilities::tryGetValue($parsed, Resources::XTAG_LABEL); $url = Utilities::tryGetValue($parsed, Resources::XTAG_URL); $locked = Utilities::tryGetValue($parsed, Resources::XTAG_LOCKED); $rollbackAllowed = Utilities::tryGetValue($parsed, Resources::XTAG_ROLLBACK_ALLOWED); $sdkVersion = Utilities::tryGetValue($parsed, Resources::XTAG_SDK_VERSION); $inputEndpointList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_INPUT_ENDPOINT_LIST, Resources::XTAG_INPUT_ENDPOINT); $roleList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ROLE_LIST, Resources::XTAG_ROLE); $roleInstanceList = Utilities::tryGetKeysChainValue($parsed, Resources::XTAG_ROLE_INSTANCE_LIST, Resources::XTAG_ROLE_INSTANCE); $status = Utilities::tryGetValue($parsed, Resources::XTAG_STATUS); $slot = Utilities::tryGetValue($parsed, Resources::XTAG_DEPLOYMENT_SLOT); $privateId = Utilities::tryGetValue($parsed, Resources::XTAG_PRIVATE_ID); $configuration = Utilities::tryGetValue($parsed, Resources::XTAG_CONFIGURATION); $upgradeDomainCount = Utilities::tryGetValue($parsed, Resources::XTAG_UPGRADE_DOMAIN_COUNT); $upgradeStatus = Utilities::tryGetValue($parsed, Resources::XTAG_UPGRADE_STATUS); $result->setConfiguration($configuration); $result->setLabel($label); $result->setLocked(Utilities::toBoolean($locked)); $result->setName($name); $result->setPrivateId($privateId); $result->setRollbackAllowed(Utilities::toBoolean($rollbackAllowed)); $result->setSdkVersion($sdkVersion); $result->setSlot($slot); $result->setStatus($status); $result->setUpgradeDomainCount(intval($upgradeDomainCount)); $result->setUpgradeStatus(UpgradeStatus::create($upgradeStatus)); $result->setUrl($url); $result->setRoleInstanceList(Utilities::createInstanceList(Utilities::getArray($roleInstanceList), 'WindowsAzure\\ServiceManagement\\Models\\RoleInstance')); $result->setRoleList(Utilities::createInstanceList(Utilities::getArray($roleList), 'WindowsAzure\\ServiceManagement\\Models\\Role')); $result->setInputEndpointList(Utilities::createInstanceList(Utilities::getArray($inputEndpointList), 'WindowsAzure\\ServiceManagement\\Models\\InputEndpoint')); return $result; }
/** * @param ShopEntity $shop * @return Shop */ public static function createFromShopEntity(ShopEntity $shop) { $struct = new self(); $struct->setId($shop->getId()); $struct->setParentId($shop->getMain() ? $shop->getMain()->getId() : $shop->getId()); $struct->setIsDefault($shop->getDefault()); $struct->setName($shop->getName()); $struct->setHost($shop->getHost()); $struct->setPath($shop->getBasePath()); $struct->setUrl($shop->getBaseUrl()); $struct->setSecure($shop->getSecure()); $struct->setSecureHost($shop->getSecureHost()); $struct->setSecurePath($shop->getSecureBasePath()); if ($shop->getCategory()) { $struct->setCategory(Category::createFromCategoryEntity($shop->getCategory())); } if ($shop->getFallback()) { $struct->setFallbackId($shop->getFallback()->getId()); } return $struct; }
/** * Check the url links. * * @param string $url * @param array $config * @return array */ public static function validate($url, array $config = []) { $validator = new self($config); $validator->setUrl($url)->analysis($validator->url); return $validator->errors; }
public static function createFromRawEvent(RawEvent $rawEvent) { $event = new self(); $event->setStatus($rawEvent->getStatus()); $event->setMessage($rawEvent->getMessage()); $event->setUnique($rawEvent->isUnique()); $event->setUrl($rawEvent->getUrl()); $event->setValue($rawEvent->getValue()); $event->setComponentId($rawEvent->getComponentId()); return $event; }
/** * {@inheritdoc} */ public static function fromArray(array $values) { $message = new self(); $values = array_merge(['asset_id' => null, 'url' => null, 'size' => null, 'checksum' => null], $values); $message->setAssetId($values['asset_id']); $message->setUrl($values['url']); $message->setSize($values['size']); $message->setChecksum($values['checksum']); return $message; }