public static function processCommand($url, $method = 'GET', $headerType = 'XML', $src = '', $returnType = 'xml')
    {
        $dispatcher = AsposeApp::getEventDispatcher();

        $method = strtoupper($method);
        $headerType = strtoupper($headerType);

        AsposeApp::getLogger()->info("Aspose Cloud SDK: processCommand called", array(
            'url' => $url,
            'method' => $method,
            'headerType' => $headerType,
            'src' => $src,
            'returnType' => $returnType,
        ));

        $session = curl_init();

        curl_setopt($session, CURLOPT_URL, $url);
        if ($method == 'GET') {
            curl_setopt($session, CURLOPT_HTTPGET, 1);
        } else {
            curl_setopt($session, CURLOPT_POST, 1);
            curl_setopt($session, CURLOPT_POSTFIELDS, $src);
            curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
        }
        curl_setopt($session, CURLOPT_HEADER, false);
        if ($headerType == 'XML') {
            curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/' . $returnType . '', 'Content-Type: application/xml', 'x-aspose-client: PHPSDK/v1.0'));
        } else {
            curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'x-aspose-client: PHPSDK/v1.0'));
        }
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        if (preg_match('/^(https)/i', $url))
            curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);

        // Allow users to register curl options before the call is executed
        $event = new ProcessCommandEvent($session);
        $dispatcher->dispatch(ProcessCommandEvent::PRE_CURL, $event);

        $result = curl_exec($session);
        $headers = curl_getinfo($session);

        if (substr($headers['http_code'], 0, 1) != '2') {

            if (curl_errno($session) !== 0) {
                throw new AsposeCurlException(curl_strerror(curl_errno($session)), $headers, curl_errno($session));
                AsposeApp::getLogger()->warning(curl_strerror(curl_errno($session)));
            } else {
                throw new Exception($result);
                AsposeApp::getLogger()->warning($result);
            }

        } else {
            if (preg_match('/You have processed/i', $result) || preg_match('/Your pricing plan allows only/i', $result)) {
                AsposeApp::getLogger()->alert($result);
                throw new Exception($result);
            }
        }

        // Allow users to alter the result
        $event = new ProcessCommandEvent($session, $result);

        /** @var ProcessCommandEvent $dispatchedEvent */
        $dispatchedEvent = $dispatcher->dispatch(ProcessCommandEvent::POST_CURL, $event);

        curl_close($session);

        // TODO test or the Event result needs to be returned in case an listener was triggered
        return $dispatchedEvent->getResult();
    }
public static function processCommand($url, $method = 'GET', $headerType = 'XML', $src = '', $returnType = 'xml')
    {
        $dispatcher = AsposeApp::getEventDispatcher();

        $method = strtoupper($method);
        $headerType = strtoupper($headerType);

        AsposeApp::getLogger()->info("Aspose Cloud SDK: processCommand called", array(
            'url' => $url,
            'method' => $method,
            'headerType' => $headerType,
            'src' => $src,
            'returnType' => $returnType,
        ));

        $session = curl_init();

        curl_setopt($session, CURLOPT_URL, $url);
        if ($method == 'GET') {
            curl_setopt($session, CURLOPT_HTTPGET, 1);
        } else {
            curl_setopt($session, CURLOPT_POST, 1);
            curl_setopt($session, CURLOPT_POSTFIELDS, $src);
            curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
        }
        curl_setopt($session, CURLOPT_HEADER, false);
        if ($headerType == 'XML') {
            curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/' . $returnType . '', 'Content-Type: application/xml', 'x-aspose-client: PHPSDK/v1.0'));
        } else {
            curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'x-aspose-client: PHPSDK/v1.0'));
        }
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        if (preg_match('/^(https)/i', $url))
            curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);

        // Allow users to register curl options before the call is executed
        $event = new ProcessCommandEvent($session);
        $dispatcher->dispatch(ProcessCommandEvent::PRE_CURL, $event);

        $result = curl_exec($session);
        $headers = curl_getinfo($session);

        if (substr($headers['http_code'], 0, 1) != '2') {

            if (curl_errno($session) !== 0) {
                throw new AsposeCurlException(curl_strerror(curl_errno($session)), $headers, curl_errno($session));
                AsposeApp::getLogger()->warning(curl_strerror(curl_errno($session)));
            } else {
                throw new Exception($result);
                AsposeApp::getLogger()->warning($result);
            }

        } else {
            if (preg_match('/You have processed/i', $result) || preg_match('/Your pricing plan allows only/i', $result)) {
                AsposeApp::getLogger()->alert($result);
                throw new Exception($result);
            }
        }

        // Allow users to alter the result
        $event = new ProcessCommandEvent($session, $result);

        /** @var ProcessCommandEvent $dispatchedEvent */
        $dispatchedEvent = $dispatcher->dispatch(ProcessCommandEvent::POST_CURL, $event);

        curl_close($session);

        // TODO test or the Event result needs to be returned in case an listener was triggered
        return $dispatchedEvent->getResult();
    }
public static function processCommand ( $ url , $ method = 'GET' , $ headerType = 'XML' , $ src = '' , $ returnType = 'xml' ) { $ dispatcher = AsposeApp :: getEventDispatcher ( ) ; $ method = strtoupper ( $ method ) ; $ headerType = strtoupper ( $ headerType ) ; AsposeApp :: getLogger ( ) -> info ( "Aspose Cloud SDK: processCommand called" , array ( 'url' => $ url , 'method' => $ method , 'headerType' => $ headerType , 'src' => $ src , 'returnType' => $ returnType , ) ) ; $ session = curl_init ( ) ; curl_setopt ( $ session , CURLOPT_URL , $ url ) ; if ( $ method == 'GET' ) { curl_setopt ( $ session , CURLOPT_HTTPGET , 1 ) ; } else { curl_setopt ( $ session , CURLOPT_POST , 1 ) ; curl_setopt ( $ session , CURLOPT_POSTFIELDS , $ src ) ; curl_setopt ( $ session , CURLOPT_CUSTOMREQUEST , $ method ) ; } curl_setopt ( $ session , CURLOPT_HEADER , false ) ; if ( $ headerType == 'XML' ) { curl_setopt ( $ session , CURLOPT_HTTPHEADER , array ( 'Accept: application/' . $ returnType . '' , 'Content-Type: application/xml' , 'x-aspose-client: PHPSDK/v1.0' ) ) ; } else { curl_setopt ( $ session , CURLOPT_HTTPHEADER , array ( 'Content-Type: application/json' , 'x-aspose-client: PHPSDK/v1.0' ) ) ; } curl_setopt ( $ session , CURLOPT_RETURNTRANSFER , true ) ; if ( preg_match ( '/^(https)/i' , $ url ) ) curl_setopt ( $ session , CURLOPT_SSL_VERIFYPEER , false ) ; // Allow users to register curl options before the call is executed $ event = new ProcessCommandEvent ( $ session ) ; $ dispatcher -> dispatch ( ProcessCommandEvent :: PRE_CURL , $ event ) ; $ result = curl_exec ( $ session ) ; $ headers = curl_getinfo ( $ session ) ; if ( substr ( $ headers [ 'http_code' ] , 0 , 1 ) != '2' ) { if ( curl_errno ( $ session ) !== 0 ) { throw new AsposeCurlException ( curl_strerror ( curl_errno ( $ session ) ) , $ headers , curl_errno ( $ session ) ) ; AsposeApp :: getLogger ( ) -> warning ( curl_strerror ( curl_errno ( $ session ) ) ) ; } else { throw new Exception ( $ result ) ; AsposeApp :: getLogger ( ) -> warning ( $ result ) ; } } else { if ( preg_match ( '/You have processed/i' , $ result ) || preg_match ( '/Your pricing plan allows only/i' , $ result ) ) { AsposeApp :: getLogger ( ) -> alert ( $ result ) ; throw new Exception ( $ result ) ; } } // Allow users to alter the result $ event = new ProcessCommandEvent ( $ session , $ result ) ; /** @var ProcessCommandEvent $dispatchedEvent */ $ dispatchedEvent = $ dispatcher -> dispatch ( ProcessCommandEvent :: POST_CURL , $ event ) ; curl_close ( $ session ) ; // TODO test or the Event result needs to be returned in case an listener was triggered return $ dispatchedEvent -> getResult ( ) ; }
Performs Aspose Api Request.

@param string $url Target Aspose API URL.
@param string $method Method to access the API such as GET, POST, PUT and DELETE
@param string $headerType XML or JSON
@param string $src Post data.
@param string $returnType
@return string
@throws Exception
Performs Aspose Api Request .