Exemplo n.º 1
0
 /**
  * Configures the runtime.
  *
  * @throws Piece_Unity_Exception
  */
 public function configure()
 {
     if (!is_null($this->proxyPath)) {
         $this->context->setProxyPath($this->proxyPath);
     }
     foreach ($this->envHandlers as $extension) {
         $extension->setIsProduction(Piece_Unity_Env::isProduction());
     }
 }
Exemplo n.º 2
0
 /**
  * Gets a Piece_Unity_Config object from a configuration file or a cache.
  *
  * @param string $masterFile
  * @param string $cacheDirectory
  * @return Piece_Unity_Config
  */
 function &_getConfiguration($masterFile, $cacheDirectory)
 {
     $masterFile = realpath($masterFile);
     $cache =& new Cache_Lite_File(array('cacheDir' => "{$cacheDirectory}/", 'masterFile' => $masterFile, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true));
     if (!Piece_Unity_Env::isProduction()) {
         $cache->remove($masterFile);
     }
     /*
      * The Cache_Lite class always specifies PEAR_ERROR_RETURN when
      * calling PEAR::raiseError in default.
      */
     $config = $cache->get($masterFile);
     if (PEAR::isError($config)) {
         trigger_error("Cannot read the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING);
         return Piece_Unity_Config_Factory::_getConfigurationFromFile($masterFile);
     }
     if (!$config) {
         $config =& Piece_Unity_Config_Factory::_getConfigurationFromFile($masterFile);
         $result = $cache->save($config);
         if (PEAR::isError($result)) {
             trigger_error("Cannot write the Piece_Unity_Config object to the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING);
         }
     }
     return $config;
 }
Exemplo n.º 3
0
 /**
  * Invokes the plugin specific code.
  *
  * @throws PIECE_UNITY_ERROR_INVALID_CONFIGURATION
  */
 function invoke()
 {
     $proxyPath = $this->_getConfiguration('proxyPath');
     if (!is_null($proxyPath)) {
         $this->_context->setProxyPath($proxyPath);
     }
     $this->_setNonSSLableServers();
     $envHandlers =& $this->_getExtension('envHandlers');
     if (!is_array($envHandlers)) {
         Piece_Unity_Error::push(PIECE_UNITY_ERROR_INVALID_CONFIGURATION, "The value of the extension point [ envHandlers ] on the plug-in [ {$this->_name} ] should be an array.");
         return;
     }
     foreach (array_merge($this->_requiredEnvHandlers, $envHandlers) as $extension) {
         $envHandler =& Piece_Unity_Plugin_Factory::factory($extension);
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
         $envHandler->invoke(Piece_Unity_Env::isProduction());
         if (Piece_Unity_Error::hasErrors()) {
             return;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Sets whether the current environment is production or not.
  *
  * @param boolean $isProduction
  */
 public static function setIsProduction($isProduction)
 {
     self::$_isProduction = $isProduction;
 }