Create URL string from RuleCollection instance

@param array $data
@param RuleCollection $collection
@param Url|null $url
@return string
559270
public static function makeUrl( array $data, RuleCollection $collection, Url $url = null ): string
	{
		$path = [];
		$get = [];
		$close = true;
		$protocol = "";
		$host = "";
		$port = 80;

		/** @var RuleInterface $item */
		foreach( $collection as $item )
		{
			if( $item instanceof RuleHost )
			{
				$protocol = $item->getProtocol();
				$host = $item->getHost();
				$port = $item->getPort();
			}

			else if( $item instanceof RuleStatic )
			{
				$path[] = $item->getSegment();
				$close = ! $item->isOpen();
			}

			else if( $item instanceof RuleSegment )
			{
				$name = $item->getName();
				if( ! isset($data[$name]) || is_array($data[$name]) && ! count($data[$name]) )
				{
					if( $item->isRequired() )
					{
						throw new \InvalidArgumentException("Insufficient data");
					}
				}

				else if( $item->isSingle() )
				{
					$path[] = $item->getPrefix() . ( is_array($data[$name]) ? current($data[$name]) : $data[$name] ) . $item->getSuffix();
				}

				else
				{
					$values = is_array($data[$name]) ? $data[$name] : [$data[$name]];
					foreach($values as $segment)
					{
						$path[] = $item->getPrefix() . $segment . $item->getSuffix();
					}
				}
			}
			else if( $item instanceof RuleGet )
			{
				$name = $item->getName();
				if( !isset($data[$name]) || ! $item->match($data[$name]))
				{
					if( $item->isRequired() )
					{
						throw new \InvalidArgumentException("Insufficient data");
					}
				}
				else
				{
					$get[$item->getQueryName()] = $data[$name];
				}
			}
		}

		// create path

		if( count($path) )
		{
			$path = "/" . implode("/", $path);
			if( $close )
			{
				$path .= "/";
			}
		}
		else
		{
			$path = "/";
		}

		if( count($get) )
		{
			$path .= "?" . http_build_query($get);
		}

		// create host

		if( ! strlen($host) )
		{
			if( ! is_null($url) )
			{
				$protocol = $url->getHost();
			}
			else if( defined("APP_HOST") )
			{
				$protocol = APP_HOST;
			}
			else if( App::getInstance()->loadIs("Url") )
			{
				$protocol = App::Url()->getHost();
			}
			else
			{
				return $path;
			}
		}

		// create protocol

		if( ! strlen($protocol) )
		{
			if( ! is_null($url) )
			{
				$protocol = $url->getProtocol();
			}
			else if( defined("BASE_PROTOCOL") )
			{
				$protocol = BASE_PROTOCOL;
			}
			else
			{
				$protocol = "http";
			}
		}

		// add port

		if( $port !== 80 )
		{
			$host .= ":" . $port;
		}

		return $protocol . "://" . $host . $path;
	}
189640
private function decodeDataUrl($data_url)
    {
        if (!is_string($data_url)) {
            return null;
        }

        $pattern = "/^data:(?:image\/[a-zA-Z\-\.]+)(?:charset=\".+\")?;base64,(?P<data>.+)$/";
        preg_match($pattern, $data_url, $matches);

        if (is_array($matches) && array_key_exists('data', $matches)) {
            return base64_decode($matches['data']);
        }

        return null;
    }
499044
public function createQuery(array $data = [], array $bookmarks = [])
    {
        $data = empty($data) ? [] : $data;

        $request = $this->createRequestData(['options' => $data], $bookmarks);

        return UrlBuilder::buildRequestString($request);
    }
704301
public function post($url, $data) {
        foreach ($data as $key => $v) {
            if (is_array($v)) {
                foreach ($v as $k => $vv) {
                    if ($vv{0} == '@') {
                        $data[ $key ][ $k ] = new \CURLFile(substr($vv, 1));
                    }
                }
            } else if ($v{0} == '@') {
                $data[ $key ] = new \CURLFile(substr($v, 1));
            }
        }
        $options = [
            CURLOPT_URL            => $url,
            CURLOPT_POST           => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS     => $data
        ];
        curl_setopt_array($this->ch, $options);
        $rst = curl_exec($this->ch);
        if ($rst === false) {
            $this->error     = curl_error($this->ch);
            $this->errorCode = '500';
            $rst             = false;
        } else {
            $code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
            if ($code != '200') {
                $this->error     = '[' . $code . ']' . get_status_header_desc($code);
                $this->errorCode = $code;
                $rst             = false;
            }
        }

        return $rst;
    }
827676
protected static function _summonerSpell( string $url, array $data )
	{
		$url = $url . self::STATIC_SUMMONERSPELLS_BY_KEY;
		$data_by_key = $data;
		$data_by_key['data'] = [];

		array_walk($data['data'], function( $d ) use (&$data_by_key) {
			$data_by_key['data'][(int)$d['key']] = $d;
		});
		self::saveSataicData(md5($url), $data_by_key);
	}
692734
private function executeQuery(string $url): AddressCollection
    {
        $content = $this->getUrlContents($url);
        $data = json_decode($content, true);

        if (empty($data) || 'OK' !== $data['statusCode']) {
            return new AddressCollection([]);
        }

        $timezone = null;
        if (isset($data['timeZone'])) {
            $timezone = timezone_name_from_abbr('', (int) substr($data['timeZone'], 0, strpos($data['timeZone'], ':')) * 3600, 0);
        }

        return new AddressCollection([
            Address::createFromArray([
                'providedBy' => $this->getName(),
                'latitude' => $data['latitude'] ?? null,
                'longitude' => $data['longitude'] ?? null,
                'locality' => $data['cityName'] ?? null,
                'postalCode' => $data['zipCode'] ?? null,
                'adminLevels' => isset($data['regionName']) ? [['name' => $data['regionName'], 'level' => 1]] : [],
                'country' => $data['countryName'] ?? null,
                'countryCode' => $data['countryName'] ?? null,
                'timezone' => $timezone,
            ]),
        ]);
    }
1204624
static public function getJson($url, $data=null, $options=null)
    {
        $instance = new static('GET', $url, $data, $options);
        return $instance->toJson();
    }
1374479
public static function view($url, $view, $data = null)
    {
        $callback = function () use ($view, $data) {
            $view = view($view);

            if (!is_null($data)) {
                foreach ($data as $key => $value) {
                    $view = $view->with($key, $value);
                }
            }

            return $view;
        };

        static::get($url, $callback);
    }
1250336
public function postJSON($url, $data = null)
    {
        $responseBody = $this->post($url, json_encode($data), 'application/json');

        return json_decode($responseBody);
    }
1017557
private function executeQuery(string $url): AddressCollection
    {
        $content = $this->getUrlContents($url);
        $json = json_decode($content, true);

        // See https://mapzen.com/documentation/search/api-keys-rate-limits/
        if (isset($json['meta'])) {
            switch ($json['meta']['status_code']) {
                case 403:
                    throw new InvalidCredentials('Invalid or missing api key.');
                case 429:
                    throw new QuotaExceeded('Valid request but quota exceeded.');
            }
        }

        if (!isset($json['type']) || 'FeatureCollection' !== $json['type'] || !isset($json['features']) || 0 === count($json['features'])) {
            return new AddressCollection([]);
        }

        $locations = $json['features'];

        if (empty($locations)) {
            return new AddressCollection([]);
        }

        $results = [];
        foreach ($locations as $location) {
            $bounds = [
                'south' => null,
                'west' => null,
                'north' => null,
                'east' => null,
            ];
            if (isset($location['bbox'])) {
                $bounds = [
                    'south' => $location['bbox'][3],
                    'west' => $location['bbox'][2],
                    'north' => $location['bbox'][1],
                    'east' => $location['bbox'][0],
                ];
            }

            $props = $location['properties'];

            $adminLevels = [];
            foreach (['region', 'county', 'locality', 'macroregion', 'country'] as $i => $component) {
                if (isset($props[$component])) {
                    $adminLevels[] = ['name' => $props[$component], 'level' => $i + 1];
                }
            }

            $results[] = Address::createFromArray([
                'providedBy' => $this->getName(),
                'latitude' => $location['geometry']['coordinates'][1],
                'longitude' => $location['geometry']['coordinates'][0],
                'bounds' => $bounds,
                'streetNumber' => isset($props['housenumber']) ? $props['housenumber'] : null,
                'streetName' => isset($props['street']) ? $props['street'] : null,
                'subLocality' => isset($props['neighbourhood']) ? $props['neighbourhood'] : null,
                'locality' => isset($props['locality']) ? $props['locality'] : null,
                'postalCode' => isset($props['postalcode']) ? $props['postalcode'] : null,
                'adminLevels' => $adminLevels,
                'country' => isset($props['country']) ? $props['country'] : null,
                'countryCode' => isset($props['country_a']) ? strtoupper($props['country_a']) : null,
            ]);
        }

        return new AddressCollection($results);
    }
215991
public function aError($message,$url='',$data=[])
    {
        $url=is_null($url) || $url=='' ? 'javascript:history.back(-1)' : $url;
        if(Request::isAjax() ){
            return $this->json(1,$message,array_merge($data,['url'=>$url]));
        }else{
            return $this->error($message,$url);
        }
    }
851627
public function delete($url, $data=null)
    {
      $url = $this->join($url);
      return $this->request(API::API_METHOD_DEL, $url, $data);
    }
325720
public function get($url, $data = null)
    {
        if ($this->cache) {
            $result = $this->cache->get($url, array('$data' => $data));
            if (array_key_exists('$data', (array)$result)) {
                return $this->response_data($result, 'get', $url);
            }
        }

        return $this->request('get', $url, $data);
    }
641119
protected static function _champion( string $url, array $data )
	{
		$url = $url . self::STATIC_CHAMPION_BY_KEY;
		$data_by_key = $data;
		$data_by_key['data'] = [];

		array_walk($data['data'], function( $d ) use (&$data_by_key) {
			$data_by_key['data'][(int)$d['key']] = $d;
		});
		self::saveSataicData(md5($url), $data_by_key);
	}
45883
public function get($url, $data = []) {
        if (!empty($data)) {
            if (is_array($data)) {
                $data = http_build_query($data);
            }
            if (strpos($url, '?') !== false) {
                $url .= '&' . $data;
            }
            else {
                $url .= '?' . $data;
            }
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);

        $this->_parse_result($ch);

        $content = curl_exec($ch);
        curl_close($ch);

        if ($this->handle_referer) {
            $this->referer = $url;
        }

        return $this->_parse_result($content);
    }
393758
function RouteRule_createUrl(route, params) {
        var escape = [], i, len, c, url;

        if (this.route !== route) {
            if (!this.routeRule) {
                return false;
            }
            escape = this.match(this.routeRule, this.trim(route, '/'));
            if (!escape.length) {
                return false;
            }
            escape.forEach(function (item) {
                if (item.key.indexOf('<') === -1) {
                    item.key = '<' + item.key + '>';
                }
            });
        }

        len = this.paramRules.length;

        for (i = 0; i < len; ++i) {
            c = this.paramRules[i];
            if (params.hasOwnProperty(c.key) && (c.value === '' || (Type.isRegExp(c.value) && c.value.test(params[c.key])) || this.match(c.value, params[c.key].toString()).length > 0)) {
                escape.push({
                    key: '<' + c.key + '>',
                    value: params[c.key].toString()
                });
                delete params[c.key];
            } else if (Type.isUndefined(params[c.key])) {
                return false;
            }
        }

        url = this.trim(this.escape(this.template, escape), '/');

        if (this.match(this.pattern.regex, url).length === 0) {
            return false;
        }

        if (Object.keys(params).length > 0) {
            url += "?" + this.buildQuery(params);
        }
        return url;
    }
24987
function getAll(url, collection) {
    // Initialise array
    collection = typeof collection === 'undefined' ? [] : collection;

    return makeRequest(url).then(function (data) {
      // Add each item to array
      var length = data.results.length;
      for (var i = 0; i < length; ++i) {
        collection.push(data.results[i]);
      }

      if (data.next === null) {
        // Return on final page
        return collection;
      } else {
        return getAll(data.next, collection);
      }
    }).catch(function (err) {
      throw err;
    });
  }