Example #1
0
        Mage::$task();
    }
    // End the task if running the normal Magento procedure
    if ($task == 'run') {
        exit;
    }
    // @todo: Set custom-logging
    //if($magebridge->getMeta('debug_custom_log')) {
    //    $customErrorLog = Mage::getBaseDir().DS.'var'.DS.'log'.DS.'php_errors.log';
    //    ini_set('error_log', $customErrorLog);
    //}
    // Debugging
    $debug = Mage::getSingleton('magebridge/debug');
    if (!empty($debug)) {
        $debug->notice("Mage::app({$app_value},{$app_type})", $app_time);
    }
    // Benchmarking
    yireo_benchmark('Mage::app()');
} catch (Exception $e) {
    // Debugging
    $debug = Mage::getSingleton('magebridge/debug');
    if (!empty($debug)) {
        $debug->notice("Mage::app({$app_value},{$app_type}) failed to start", $app_time);
        $debug->notice("Fallback to Mage::app()", $app_time);
    }
    // Start the Magento application with default values
    Mage::app();
}
// Run the bridge
$magebridge->run();
// End
Example #2
0
 /**
  * Helper-method to get the Front-controller
  *
  * @access public
  *
  * @param boolean $norender
  *
  * @return object
  */
 public static function getController($norender = true)
 {
     // Default variables
     $fullDispatch = (bool) Mage::getStoreConfig('magebridge/settings/full_dispatch');
     $httpResponseSendBefore = false;
     // Workaround for AJAX Cart Pro
     $awacp = isset($_REQUEST['awacp']) && $_REQUEST['awacp'] == 1 ? true : false;
     if ($awacp) {
         $fullDispatch = false;
     }
     // Singleton to initialize the front-controller
     static $controller;
     if (empty($controller)) {
         // Initialize the front-controller
         yireo_benchmark('MB_Core::getFrontController() - start');
         $controller = Mage::app()->getFrontController();
         $controller->setNoRender($norender);
         // Run the controller_front_init_before event
         Mage::dispatchEvent('controller_front_init_before', array('front' => $controller));
         if ($fullDispatch == true) {
             $controller->dispatch();
             yireo_benchmark('MB_Core::getFrontController() - fully dispatched');
         } else {
             // Replicate the dispatch() method of the front-controller, without sending a response
             $request = $controller->getRequest();
             $request->setPathInfo()->setDispatched(false);
             if (!$request->isStraight()) {
                 Mage::getModel('core/url_rewrite')->rewrite();
             }
             $controller->rewrite();
             $i = 0;
             $routers = $controller->getRouters();
             while (!$request->isDispatched() && $i++ < 50) {
                 foreach ($routers as $router) {
                     if ($router->match($controller->getRequest())) {
                         break;
                     }
                 }
             }
             Varien_Profiler::stop('mage::dispatch::routers_match');
             if ($i > 100) {
                 Mage::throwException('Front controller reached 100 router match iterations');
             }
             // Call upon events that need to do something before the layout renders
             if (Mage::registry('mb_controller_action_layout_render_before') == false) {
                 Mage::getSingleton('magebridge/debug')->notice('MB throws event "controller_action_layout_render_before"');
                 Mage::dispatchEvent('controller_action_layout_render_before');
                 Mage::register('mb_controller_action_layout_render_before', true);
             }
             // Simulate sending a response (but without outputBody())
             Mage::dispatchEvent('controller_front_send_response_before', array('front' => $controller));
             $response = $controller->getResponse();
             if ($httpResponseSendBefore) {
                 Mage::dispatchEvent('http_response_send_before', array('response' => $response));
             }
             $response->sendHeaders();
             Mage::dispatchEvent('controller_front_send_response_after', array('front' => $controller));
         }
         // Preset some HTTP-headers
         header('X-MageBridge-Customer: ' . Mage::getModel('customer/session')->getCustomer()->getEmail());
         // Note: Do not use the Magento API for this, because it is not used by magebridge.class.php > output
         yireo_benchmark('MB_Core::getFrontController() - end');
     }
     return $controller;
 }
 public function run()
 {
     Mage::getSingleton('magebridge/debug')->notice('Session: ' . session_id());
     Mage::getSingleton('magebridge/debug')->notice('Request: ' . $_SERVER['REQUEST_URI']);
     Mage::getSingleton('magebridge/debug')->trace('FILES', $_FILES);
     // Handle SSO
     if (Mage::getSingleton('magebridge/user')->doSSO() == true) {
         Mage::getSingleton('magebridge/debug')->notice('Handling SSO');
         exit;
     }
     // Now Magento is initialized, we can load the MageBridge core-class
     $bridge = Mage::getSingleton('magebridge/core');
     // Initialize the bridge
     $bridge->init($this->getMeta(), $this->getRequest());
     yireo_benchmark('MB_Core::init()');
     // Handle tests
     if (Mage::app()->getRequest()->getQuery('mbtest') == 1) {
         $bridge->setMetaData('state', 'test');
         $bridge->setMetaData('extra', 'get');
         print $bridge->output(false);
         exit;
     } elseif (Mage::app()->getRequest()->getPost('mbtest') == 1) {
         $bridge->setMetaData('state', 'test');
         $bridge->setMetaData('extra', 'post');
         print $bridge->output(false);
         exit;
     }
     // Check for the meta-data
     if (!count($this->getMeta()) > 0) {
         $bridge->setMetaData('state', 'empty metadata');
         print $bridge->output(false);
         exit;
     }
     // Match the supportkey
     if ($this->getMeta('supportkey') != $bridge->getLicenseKey() && $this->getMeta('license') != $bridge->getLicenseKey()) {
         yireo_benchmark('MageBridge supportkey failed');
         $bridge->setMetaData('state', 'supportkey failed');
         $bridge->setMetaData('extra', $bridge->getLicenseKey());
         print $bridge->output(false);
         exit;
     }
     // Authorize this request using the API credentials (set in the meta-data)
     if ($this->authenticate() == false) {
         yireo_benchmark('MageBridge authentication failed');
         $bridge->setMetaData('state', 'authentication failed');
         print $bridge->output(false);
         exit;
     }
     // Handle authentication tests
     if (Mage::app()->getRequest()->getQuery('mbauthtest') == 1) {
         $bridge->setMetaData('state', 'test');
         $bridge->setMetaData('extra', 'get');
         print $bridge->output(false);
         exit;
     } elseif (Mage::app()->getRequest()->getPost('mbauthtest') == 1) {
         $bridge->setMetaData('state', 'test');
         $bridge->setMetaData('extra', 'post');
         print $bridge->output(false);
         exit;
     }
     // Check if there's any output already set (for instance JSON, AJAX, XML, PDF) and output it right away
     if ($bridge->preoutput() == true) {
         session_write_close();
         exit;
     }
     // Fetch the actual request
     $data = $bridge->getRequestData();
     if (is_array($data) && !empty($data)) {
         // Dispatch the request to the appropriate classes
         Mage::getSingleton('magebridge/debug')->notice('Dispatching the request');
         $data = $this->dispatch($data);
         // Set the completed request as response
         $bridge->setResponseData($data);
     } else {
         Mage::getSingleton('magebridge/debug')->notice('Empty request');
     }
     Mage::getSingleton('magebridge/debug')->notice('Done with session: ' . session_id());
     //Mage::getSingleton('magebridge/debug')->trace('Response data', $data);
     //Mage::getSingleton('magebridge/debug')->trace('Session dump', $_SESSION);
     //Mage::getSingleton('magebridge/debug')->trace('Cookie dump', $_COOKIE);
     Mage::getSingleton('magebridge/debug')->trace('GET dump', $_GET);
     //Mage::getSingleton('magebridge/debug')->trace('POST dump', $_POST);
     Mage::getSingleton('magebridge/debug')->trace('PHP memory', round(memory_get_usage() / 1024));
     yireo_benchmark('MB_Core::output()');
     $bridge->setMetaData('state', null);
     $output = $bridge->output();
     header('Content-Length: ' . strlen($output));
     header('Content-Type: application/magebridge');
     echo $output;
     session_write_close();
     exit;
 }