Ejemplo n.º 1
0
 protected function _initStoreRoutes()
 {
     $request = new Zend_Controller_Request_Http();
     $path = explode('/', trim($request->getPathInfo(), '/'));
     $requestedPath = array_shift($path);
     $requestedHost = $request->getHttpHost();
     if ($store = Cosmos_Api::get()->cosmos->getStoreByHostPath($requestedHost, $requestedPath)) {
         $this->bootstrap('session');
         Zend_Registry::set('csession', new Zend_Session_Namespace("cosmos_{$store['group_id']}"));
         Zend_Registry::get('log')->info($store);
         if ($store['path']) {
             $this->bootstrap('frontcontroller');
             $front = Zend_Controller_Front::getInstance();
             $request = $front->getRequest();
             $dispatcher = $front->getDispatcher();
             $defaultRoute = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
             $front->getRouter()->removeDefaultRoutes();
             $defaults = array('path' => $store['path'], 'module' => $dispatcher->getDefaultModule());
             $pathRoute = new Zend_Controller_Router_Route(':path', $defaults);
             Zend_Registry::set('cosmosRoute', $pathRoute);
             // This is to catch empty requests because for some reason 'default' doesn't.
             $front->getRouter()->addRoute('default-empty', $pathRoute);
             $front->getRouter()->addRoute('default', $pathRoute->chain($defaultRoute));
             Zend_Registry::set('mode', 'path');
         } else {
             Zend_Registry::set('mode', 'host');
         }
     } else {
         die('fail');
         // no matching store?
     }
     Cosmos_Addon::getInstance($store['addons']);
 }
Ejemplo n.º 2
0
 public function indexAction()
 {
     Cosmos_Profiler::start('calc.multiply');
     // This is not typical because a core action would not be using add-on methods.
     $this->view->result = Cosmos_Api::get()->calc->divide(10, 2);
     $this->view->service_plugin_result = Cosmos_Api::get()->sample->add(5, 5);
     Cosmos_Profiler::stop('calc.multiply');
 }
Ejemplo n.º 3
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // 404, try a custom url...
     if (!Zend_Controller_Front::getInstance()->getDispatcher()->isDispatchable($request)) {
         $temp = $request->getRequestUri();
         $checker = Cosmos_Api::get()->url->check($temp);
         if ($checker) {
             // @todo: this should allow for regular redirects, or dispatching a different controller/action/module without actually redirecting.
             Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoSimple($checker['action'], $checker['controller'], $checker['module']);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * This is a universal method all client types must implement to
  * take a Cosmos_Api_Request object and make the call via the
  * underlying client object.
  * 
  * @param Cosmos_Api_Request $request
  * @return Cosmos_Api_Response
  */
 public function cosmosRequest(Cosmos_Api_Request $request)
 {
     $apiKey = Cosmos_Api::getApiKey($request->getOauthParam('oauth_consumer_key'));
     if (!$apiKey) {
         Zend_Debug::dump($apiKey);
         //			throw new Cosmos_Api_Exception('Unauthorized - Bad consumer key provided', 401);
     }
     $this->_server->setRequest($request);
     $response = $this->_server->handle();
     return $response;
     //        return $response->getResponseValue();
 }
Ejemplo n.º 5
0
 protected function _validateOauthRequest()
 {
     $apiKey = Cosmos_Api::getApiKey($this->_oauthParams['oauth_consumer_key']);
     if (!$apiKey) {
         throw new Cosmos_Api_Exception('Unauthorized - Bad consumer key provided', 401);
     }
     $this->setOauthConsumerSecret($apiKey['private_key']);
     $signature = $this->_generateOauthSignature('POST');
     if ($signature !== $this->_oauthSignature) {
         throw new Cosmos_Api_Server_Exception('Unauthorized - Bad signature provided', 401);
     }
     return true;
 }
Ejemplo n.º 6
0
 public function indexAction()
 {
     $this->view->content = Cosmos_Api::get()->content->read();
 }
Ejemplo n.º 7
0
 public function updateContentAction()
 {
     Cosmos_Api::get()->content->write($_POST['content']);
     return $this->_helper->redirector('index', 'sample-content', 'backend');
 }