⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 technorati.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     * Validates TopTags query options.     *     * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _validateTopTags(array $options)    {        static $validOptions = array('key',             'limit', 'start', 'format');        // Validate keys in the $options array        $this->_compareOptions($options, $validOptions);        // Validate limit (optional)        $this->_validateOptionLimit($options);        // Validate start (optional)        $this->_validateOptionStart($options);        // Validate format (optional)        $this->_validateOptionFormat($options);    }        /**     * Validates BlogInfo query options.     *     * @param   array   $options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _validateBlogInfo(array $options)    {        static $validOptions = array('key', 'url',            'format');        // Validate keys in the $options array        $this->_compareOptions($options, $validOptions);        // Validate url (required)        $this->_validateOptionUrl($options);        // Validate format (optional)        $this->_validateOptionFormat($options);    }        /**     * Validates TopTags query options.     *     * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _validateBlogPostTags(array $options)    {        static $validOptions = array('key', 'url',             'limit', 'start', 'format');        // Validate keys in the $options array        $this->_compareOptions($options, $validOptions);        // Validate url (required)        $this->_validateOptionUrl($options);        // Validate limit (optional)        $this->_validateOptionLimit($options);        // Validate start (optional)        $this->_validateOptionStart($options);        // Validate format (optional)        $this->_validateOptionFormat($options);    }    /**     * Checks whether an option is in a given array.     *     * @param   string $name    option name     * @param   array $options     * @param   array $array    array of valid options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _validateInArrayOption($name, $options, array $array)    {        if (isset($options[$name]) && !in_array($options[$name], $array)) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "Invalid value '{$options[$name]}' for '$name' option");        }    }        /**     * Checks whether mandatory $name option exists and it's valid.     *      * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _validateMandatoryOption($name, $options)     {        if (!isset($options[$name]) || !trim($options[$name])) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "Empty value for '$name' option");        }    }        /**     * Checks whether $name option is a valid integer and casts it.     *      * @param   array $options     * @return  void     * @access  protected     */    protected function _validateIntegerOption($name, $options)     {        if (isset($options[$name])) {            $options[$name] = (int) $options[$name];        }    }        /**     * Makes and HTTP GET request to given $path with $options.     * HTTP Response is first validated, then returned.     *      * @param   string $path     * @param   array $options     * @return  Zend_Http_Response     * @throws  Zend_Service_Technorati_Exception on failure     * @access  protected     */    protected function _makeRequest($path, $options = array())    {        $restClient = $this->getRestClient();        $restClient->getHttpClient()->resetParameters();        $response = $restClient->restGet($path, $options);        self::_checkResponse($response);        return $response;    }    /**     * Checks whether 'claim' option value is valid.      *      * @param   array $options     * @return  void     * @access  protected     */    protected function _validateOptionClaim(array $options)     {        $this->_validateIntegerOption('claim', $options);    }        /**     * Checks whether 'format' option value is valid.      * Be aware that Zend_Service_Technorati supports only XML as format value.     *      * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception if 'format' value != XML     * @access  protected     */    protected function _validateOptionFormat(array $options)     {        if (isset($options['format']) && $options['format'] != 'xml') {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "Invalid value '" . $options['format'] . "' for 'format' option. " .                        "Zend_Service_Technorati supports only 'xml'");        }    }        /**     * Checks whether 'limit' option value is valid.      * Value must be an integer greater than PARAM_LIMIT_MIN_VALUE     * and lower than PARAM_LIMIT_MAX_VALUE.     *      * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception if 'limit' value is invalid     * @access  protected     */    protected function _validateOptionLimit(array $options)     {        if (!isset($options['limit'])) return;                $options['limit'] = (int) $options['limit'];        if ($options['limit'] < self::PARAM_LIMIT_MIN_VALUE ||             $options['limit'] > self::PARAM_LIMIT_MAX_VALUE) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "Invalid value '" . $options['limit'] . "' for 'limit' option");        }    }        /**     * Checks whether 'start' option value is valid.      * Value must be an integer greater than 0.     *      * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception if 'start' value is invalid     * @access  protected     */    protected function _validateOptionStart(array $options)     {        if (!isset($options['start'])) return;                $options['start'] = (int) $options['start'];        if ($options['start'] < self::PARAM_START_MIN_VALUE) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "Invalid value '" . $options['start'] . "' for 'start' option");        }    }    /**     * Checks whether 'url' option value exists and is valid.      * 'url' must be a valid HTTP(s) URL.     *      * @param   array $options     * @return  void     * @throws  Zend_Service_Technorati_Exception if 'url' value is invalid     * @access  protected     * @todo    support for Zend_Uri_Http     */    protected function _validateOptionUrl(array $options)     {        $this->_validateMandatoryOption('url', $options);    }        /**     * Checks XML response content for errors.     *     * @param   DomDocument $dom    the XML response as a DOM document     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @link    http://technorati.com/developers/api/error.html Technorati API: Error response     * @access  protected     */    protected static function _checkErrors(DomDocument $dom)    {        $xpath = new DOMXPath($dom);        $result = $xpath->query("/tapi/document/result/error");        if ($result->length >= 1) {            $error = $result->item(0)->nodeValue;            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception($error);        }    }    /**     * Converts $response body to a DOM object and checks it.     *      * @param   Zend_Http_Response $response     * @return  DOMDocument     * @throws  Zend_Service_Technorati_Exception if response content contains an error message     * @access  protected     */    protected function _convertResponseAndCheckContent(Zend_Http_Response $response)    {        $dom = new DOMDocument();        $dom->loadXML($response->getBody());        self::_checkErrors($dom);        return $dom;    }        /**     * Checks ReST response for errors.     *     * @param   Zend_Http_Response $response    the ReST response     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected static function _checkResponse(Zend_Http_Response $response)    {        if ($response->isError()) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(sprintf(                        'Invalid response status code (HTTP/%s %s %s)',                        $response->getVersion(), $response->getStatus(), $response->getMessage()));        }    }    /**     * Checks whether user given options are valid.     *      * @param   array $options        user options     * @param   array $validOptions   valid options     * @return  void     * @throws  Zend_Service_Technorati_Exception     * @access  protected     */    protected function _compareOptions(array $options, array $validOptions)    {        $difference = array_diff(array_keys($options), $validOptions);        if ($difference) {            /**             * @see Zend_Service_Technorati_Exception             */            require_once 'Zend/Service/Technorati/Exception.php';            throw new Zend_Service_Technorati_Exception(                        "The following parameters are invalid: '" .                         implode("', '", $difference) . "'");        }    }    /**     * Prepares options for the request     *     * @param   array $options        user options     * @param   array $defaultOptions default options     * @return  array Merged array of user and default/required options.     * @access  protected     */    protected function _prepareOptions($options, array $defaultOptions)    {        $options = (array) $options; // force cast to convert null to array()        $options['key'] = $this->_apiKey;        $options = array_merge($defaultOptions, $options);        return $options;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -