/**
  * Invokes the plugin specific code.
  *
  * @return boolean
  * @throws Piece_Unity_Exception
  */
 public function intercept()
 {
     $this->_prepareAuthenticationState();
     $uri = $this->getConfiguration('uri');
     if (!$uri) {
         throw new Piece_Unity_Exception("The value of the configuration point [ uri ] on the plug-in [ {$this->_name} ] is required");
     }
     if ($this->_isAuthenticationURI($uri)) {
         return true;
     }
     $excludes = $this->getConfiguration('excludes');
     if ($excludes) {
         if (!is_array($excludes)) {
             throw new Piece_Unity_Exception("The value of the configuration point [ excludes ] on the plug-in [ {$this->_name} ] should be an array");
         }
         foreach ($excludes as $exclude) {
             if (preg_match("!{$exclude}!", $this->_scriptName)) {
                 return true;
             }
         }
     }
     $isProtectedResource = false;
     $includes = $this->getConfiguration('includes');
     if ($includes) {
         if (!is_array($includes)) {
             throw new Piece_Unity_Exception("The value of the configuration point [ includes ] on the plug-in [ {$this->_name} ] should be an array");
         }
         foreach ($includes as $include) {
             if (preg_match("!{$include}!", $this->_scriptName)) {
                 $isProtectedResource = true;
                 break;
             }
         }
     }
     $session = $this->context->getSession();
     $session->setPreloadCallback('_Interceptor_Authentication_StateLoader', array(__CLASS__, 'loadAuthenticationState'));
     $session->addPreloadClass('_Interceptor_Authentication_StateLoader', 'Piece_Unity_Service_Autentication_State');
     if (!$isProtectedResource) {
         return true;
     }
     $realm = $this->getConfiguration('realm');
     if ($this->_authenticationState->isAuthenticated($realm)) {
         if ($this->_authenticationState->hasCallbackURI($realm)) {
             $this->_authenticationState->removeCallbackURI($realm);
         }
         return true;
     } else {
         $this->_authenticationState->setCallbackURI($realm, Stagehand_HTTP_ServerEnv::getAbsoluteURI());
         $this->context->setView($uri);
         return false;
     }
 }
 /**
  * @test
  * @dataProvider provideDataForBaseURI
  * @param array $variables
  */
 public function getsTheBaseUri(array $variables)
 {
     foreach ($variables as $key => $value) {
         $_SERVER[$key] = $value;
     }
     $this->assertEquals('http://www.example.com', Stagehand_HTTP_ServerEnv::getBaseURI());
 }
示例#3
0
 /**
  * Imports PATH_INFO string as parameters.
  *
  * @param boolean $importPathInfo
  * @since Method available since Release 0.4.0
  */
 public function importPathInfo()
 {
     $pathInfo = Stagehand_HTTP_ServerEnv::getPathInfo();
     if (is_null($pathInfo)) {
         return;
     }
     $pathInfoParameters = explode('/', trim($pathInfo, '/'));
     for ($i = 0, $count = count($pathInfoParameters); $i < $count; $i += 2) {
         $this->_parameters[$pathInfoParameters[$i]] = @$pathInfoParameters[$i + 1];
     }
 }
示例#4
0
 /**
  * Configures the runtime.
  */
 public function configure()
 {
     $this->context->setProxyPath($this->proxyPath);
     if (!Stagehand_HTTP_ServerEnv::usingProxy()) {
         return;
     }
     if (!is_null($this->proxyPath)) {
         $this->context->setBasePath($this->proxyPath . $this->context->getBasePath());
         $this->context->setScriptName($this->proxyPath . $this->context->getScriptName());
         $this->context->setAppRootPath($this->proxyPath . $this->context->getAppRootPath());
         if ($this->adjustSessionCookiePath) {
             ini_set('session.cookie_path', $this->proxyPath . str_replace('//', '/', ini_get('session.cookie_path')));
         }
     }
 }
示例#5
0
 /**
  * Creates a Piece_Unity_Request object and sets an event to the context.
  */
 public function __construct()
 {
     $this->_session = new Piece_Unity_Session();
     $this->_scriptName = $this->_originalScriptName = Stagehand_HTTP_ServerEnv::getScriptName();
     $this->_basePath = $this->_getBasePath();
 }
 /**
  * Gets the base URI requested by a client.
  *
  * @return string
  */
 public static function getBaseURI()
 {
     if (Stagehand_HTTP_ServerEnv::isSecure()) {
         $scheme = 'https';
     } else {
         $scheme = 'http';
     }
     if (Stagehand_HTTP_ServerEnv::isRunningOnStandardPort()) {
         $port = '';
     } else {
         $port = ':' . $_SERVER['SERVER_PORT'];
     }
     return $scheme . '://' . $_SERVER['SERVER_NAME'] . $port;
 }
示例#7
0
文件: URI.php 项目: piece/piece-unity
 /**
  * Creates a Net_URL object with the given path, and replaces some pieces of
  * a URI when the URI is not external.
  *
  * @throws Piece_Unity_URI_PathNotSpecifiedException
  */
 private function initialize()
 {
     if (is_null($this->path)) {
         throw new Piece_Unity_URI_PathNotSpecifiedException('The path must be specified');
     }
     $path = $this->path;
     if (!$this->_isExternal && !preg_match('/^https?/', $this->path) && !Stagehand_HTTP_ServerEnv::usingProxy()) {
         $path = $this->context->getAppRootPath() . $path;
     }
     $this->_url = new Net_URL2($path);
 }