Example #1
0
 /**
  * Hashes a key by multi-tenant name to prevent cross-tenant cache retrieval.  Does not hash if this is not a
  * multi-tenanted application, or if the key begins with --shared--.
  *
  * @param  string $key
  * @return string
  */
 protected static function _multiTenantKey($key)
 {
     $tenant = Zrt_Application::getTenantName();
     if ($tenant && '--shared--' != substr($key, 0, 10)) {
         $key = md5($tenant . $key);
     }
     return $key;
 }
Example #2
0
 public static function isShared()
 {
     return self::$_shared;
     return !self::$_shared && Zrt_Application::getTenantName() ? false : true;
 }
Example #3
0
 /**
  * Determines what the default module should be, based on the server name.
  * If we are visiting a subsite, checks that the subsite is valid.
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $frontController = Zend_Controller_Front::getInstance();
     $server = $_SERVER['HTTP_HOST'];
     // Check that the organisational and reseller accounts exist and match.
     $subdomains = explode('.', $server);
     $tenantDomain = $subdomains[0];
     // @todo Choose the username to bind to.
     $databaseAdapterName = $this->_databaseAdapterName;
     Zend_Registry::get('config')->database->{$databaseAdapterName}->connection->username = $tenantDomain;
     // Find the tenant and check that it exists.
     // @todo Probably try-catch this as if the username isn't valid, it will throw a database exception.
     $tenantClass = $this->_tenantClass;
     $tenant = $tenantClass::findBySubdomain($tenantDomain);
     if (!$tenant) {
         // Can't use an exception because this is pre-dispatch and the error handler has not been loaded.
         $request->setParam("error_handler", Zrt_Error::EXCEPTION_NOT_FOUND);
         $request->setActionName('error')->setControllerName('error');
         return;
     }
     // If this is a white-labeled application, find the reseller and test that it exists.
     if (null !== $this->_resellerClass) {
         $resellerDomain = implode('.', array_slice($subdomains, 1));
         $resellerClass = $this->_resellerClass;
         $reseller = $resellerClass::findByDomain($resellerDomain);
         if (!$reseller) {
             // Can't use an exception because this is pre-dispatch and the error handler has not been loaded.
             $request->setParam("error_handler", Zrt_Error::EXCEPTION_NOT_FOUND);
             $request->setActionName('error')->setControllerName('error');
         }
         // Store reseller information.
         Zend_Registry::set('reseller', $reseller);
     }
     // Store tenant information.
     Zrt_Application::setTenantName($tenantDomain);
     Zend_Registry::set('tenant', $tenant);
 }