Permalink
Browse files

Deprecated directive "core.use_routing" in favor of a routing config …

…parameter ("enabled"), closes #683
  • Loading branch information...
dzuelke committed Jan 19, 2008
1 parent 2d48401 commit 1ed97bad8ac6097eed90be27ced11d61a8bba91b
View
@@ -1206,9 +1206,7 @@ if(curl_errno($ch)) {
information for them, such as the parameters. Think of it as replacing
mod_rewrite for Apache or ISAPI_Rewrite for Microsoft IIS but with a
lot more power and features. Routes are defined in the file
<filename>%core.app_dir%/config/routing.xml</filename>, and to enable
routing you must set the "use_routing" option to true in
<filename>settings.xml</filename>.</para>
<filename>%core.app_dir%/config/routing.xml</filename></para>
<para>Let's look at an example route:<programlisting>&lt;route name="viewproduct" pattern="^/products/(id:\d+)$" module="Shop" action="ViewProduct" /&gt;</programlisting></para>
@@ -19,7 +19,9 @@
<response class="AgaviWebResponse" />
<routing class="AgaviWebserviceRouting" />
<routing class="AgaviWebserviceRouting">
<parameter name="enabled">false</parameter>
</routing>
<security_filter class="AgaviSecurityFilter" />
@@ -9,7 +9,6 @@
<setting name="use_database">false</setting>
<setting name="use_logging">false</setting>
<setting name="use_routing">false</setting>
<setting name="use_security">false</setting>
<setting name="use_translation">true</setting>
</settings>
@@ -45,7 +45,6 @@
<setting name="use_database">false</setting>
<setting name="use_logging">false</setting>
<setting name="use_routing">true</setting>
<setting name="use_security">true</setting>
<setting name="use_translation">true</setting>
</settings>
@@ -45,7 +45,6 @@
<setting name="use_database">false</setting>
<setting name="use_logging">false</setting>
<setting name="use_routing">true</setting>
<setting name="use_security">true</setting>
<setting name="use_translation">false</setting>
</settings>
@@ -71,24 +71,6 @@ public function getSoapServer()
return $this->soapServer;
}
/**
* Initialize this controller.
*
* @param AgaviContext An AgaviContext instance.
* @param array An array of initialization parameters.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.9.0
*/
public function initialize(AgaviContext $context, array $parameters = array())
{
if(!AgaviConfig::get('core.use_routing')) {
throw new AgaviInitializationException('Agavi SOAP support requires the Routing to be on, please enable "core.use_routing" in settings.xml.');
}
parent::initialize($context, $parameters);
}
/**
* Do any necessary startup work after initialization.
*
@@ -35,6 +35,11 @@
const ANCHOR_START = 1;
const ANCHOR_END = 2;
/**
* @var bool Whether or not routing is enabled.
*/
protected $enabled = true;
/**
* @var array An array of route information
*/
@@ -78,6 +83,10 @@
*/
public function __construct()
{
// for now, we still use this setting as default.
// will be removed in 1.1
$this->enabled = AgaviConfig::get('core.use_routing', $this->enabled);
$this->defaultGenOptions = array_merge($this->defaultGenOptions, array(
'relative' => true,
'refill_all_parameters' => false,
@@ -101,13 +110,17 @@ public function initialize(AgaviContext $context, array $parameters = array())
$this->setParameters($parameters);
if(isset($parameters['default_gen_options'])) {
$this->defaultGenOptions = array_merge($this->defaultGenOptions, $parameters['default_gen_options']);
}
$this->enabled = $this->getParameter('enabled', $this->enabled);
if(isset($parameters['gen_options_presets']) && is_array($parameters['gen_options_presets'])) {
$this->genOptionsPresets = $parameters['gen_options_presets'];
}
$this->defaultGenOptions = array_merge(
$this->defaultGenOptions,
$this->getParameter('default_gen_options', array())
);
$this->genOptionsPresets = array_merge(
$this->genOptionsPresets,
$this->getParameter('gen_options_presets', array())
);
// and load the config.
$this->loadConfig();
@@ -123,7 +136,7 @@ protected function loadConfig()
{
$cfg = AgaviConfig::get("core.config_dir") . "/routing.xml";
// allow missing routing.xml when routing is not enabled
if(AgaviConfig::get("core.use_routing", false) || is_readable($cfg)) {
if($this->enabled || is_readable($cfg)) {
include(AgaviConfigCache::checkConfig($cfg, $this->context->getName()));
}
}
@@ -157,6 +170,19 @@ public function shutdown()
{
}
/**
* Check if this routing instance is enabled.
*
* @return bool Whether or not routing is enabled.
*
* @author David Zülke <dz@bitxtender.com>
* @since 1.0.0
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* Retrieve the current application context.
*
@@ -700,7 +726,7 @@ public function execute()
$container = $this->context->getController()->createExecutionContainer();
if(!AgaviConfig::get('core.use_routing', false) || count($this->routes) == 0) {
if(!$this->enabled || count($this->routes) == 0) {
// routing disabled, determine module and action manually and bail out
$container->setModuleName($reqData->getParameter($req->getParameter('module_accessor')));
$container->setActionName($reqData->getParameter($req->getParameter('action_accessor')));
@@ -29,6 +29,23 @@
*/
class AgaviSoapRouting extends AgaviWebserviceRouting
{
/**
* Initialize the routing instance.
*
* @param AgaviContext A Context instance.
* @param array An array of initialization parameters.
*
* @author David Zülke <dz@bitxtender.com>
* @since 0.11.0
*/
public function initialize(AgaviContext $context, array $parameters = array())
{
// must always be on
unset($parameters['enabled']);
parent::initialize($context, $parameters);
}
/**
* Returns the local filesystem path to the WSDL file built from routing.xml.
*
@@ -110,7 +110,7 @@ public function initialize(AgaviContext $context, array $parameters = array())
// when rewriting, apache strips one (not all) trailing ampersand from the end of QUERY_STRING... normalize:
$rewritten = (preg_replace('/&+$/D', '', $qs) !== preg_replace('/&+$/D', '', $ru['query']));
if(AgaviConfig::get("core.use_routing", false) && $rewritten) {
if($this->enabled && $rewritten) {
// strip the one trailing ampersand, see above
$queryWasEmptied = false;
if($ru['query'] !== '' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) {
@@ -271,7 +271,7 @@ public function gen($route, array $params = array(), $options = array())
}
if($route === null) {
if(AgaviConfig::get('core.use_routing')) {
if($this->enabled) {
$routes = array_reverse($req->getAttribute('matched_routes', 'org.agavi.routing'));
$route = join('+', $routes);
$routeMatches = array();
@@ -287,7 +287,7 @@ public function gen($route, array $params = array(), $options = array())
$routes = $this->getAffectedRoutes($route);
if(count($routes)) {
if(AgaviConfig::get('core.use_routing')) {
if($this->enabled) {
// the route exists and routing is enabled, the parent method handles it
$append = '';
@@ -42,7 +42,7 @@ public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
if(!AgaviConfig::get("core.use_routing", false)) {
if(!$this->enabled) {
return;
}
@@ -21,7 +21,7 @@ public function setUp()
{
$this->_r = new SampleRouting();
$this->_r->initialize(AgaviContext::getInstance('test'));
AgaviConfig::set('core.use_routing', true);
// AgaviConfig::set('core.use_routing', true);
}
@@ -20,7 +20,7 @@ public function setUp()
$this->_SERVER = $_SERVER;
$this->_ENV = $_ENV;
$this->_GET = $_GET;
AgaviConfig::set('core.use_routing', true);
// AgaviConfig::set('core.use_routing', true);
}
protected function runTest()
@@ -10,7 +10,9 @@
<logger_manager class="AgaviLoggerManager" />
<request class="AgaviWebRequest" />
<response class="TestResponse" />
<routing class="TestRouting" />
<routing class="TestRouting">
<parameter name="enabled">false</parameter>
</routing>
<security_filter class="AgaviSecurityFilter" />
<storage class="AgaviNullStorage" />
<translation_manager class="AgaviTranslationManager" />
@@ -45,7 +45,6 @@
<setting name="use_database">false</setting>
<setting name="use_logging">true</setting>
<setting name="use_routing">false</setting>
<setting name="use_security">false</setting>
<setting name="use_translation">true</setting>

0 comments on commit 1ed97ba

Please sign in to comment.