[Agavi-Commits] r4913 - in trunk: . src/config/defaults src/controller src/exception src/filter

3 views
Skip to first unread message

com...@lists.agavi.org

unread,
Dec 26, 2011, 1:17:32 PM12/26/11
to com...@lists.agavi.org
Author: david
Date: 2011-12-26 19:17:29 +0100 (Mon, 26 Dec 2011)
New Revision: 4913

Added:
trunk/src/exception/AgaviClassNotFoundException.class.php
trunk/src/exception/AgaviFileNotFoundException.class.php
Modified:
trunk/
trunk/CHANGELOG
trunk/src/config/defaults/autoload.xml
trunk/src/controller/AgaviController.class.php
trunk/src/controller/AgaviExecutionContainer.class.php
trunk/src/filter/AgaviExecutionFilter.class.php
Log:
Reintegrate [4759:4912/branches/david-httpcaching] with changes to refactor instantiation of Actions and Views, closes #1398


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/1.0:2658-4906
/branches/config-1.1:4687-4733
/branches/david-azure:4475-4478
/branches/david-numbers:4397-4455
+ /branches/1.0:2658-4906
/branches/config-1.1:4687-4733
/branches/david-azure:4475-4478
/branches/david-httpcaching:4759-4912
/branches/david-numbers:4397-4455

Modified: trunk/CHANGELOG
===================================================================
--- trunk/CHANGELOG 2011-12-26 18:10:57 UTC (rev 4912)
+++ trunk/CHANGELOG 2011-12-26 18:17:29 UTC (rev 4913)
@@ -22,6 +22,7 @@
ADD: Add support for custom filesystem layouts for modules to the project configuration system (#874) (Noah)
ADD: Response attributes (#1062) (David, TANAKA Koichi)

+CHG: Refactor instantiation of Actions and Views (#1398) (David)
CHG: Remove unlinking of temporary files in AgaviUploadedFile destructor (#1452) (David)
CHG: Overhaul default values in AgaviUploadedFile constructor (#1451) (David)
CHG: Move cleanup and wrapping of uploaded files from AgaviWebRequestDataHolder to AgaviWebRequest (#1450) (David)

Modified: trunk/src/config/defaults/autoload.xml
===================================================================
--- trunk/src/config/defaults/autoload.xml 2011-12-26 18:10:57 UTC (rev 4912)
+++ trunk/src/config/defaults/autoload.xml 2011-12-26 18:17:29 UTC (rev 4913)
@@ -92,12 +92,14 @@
<!-- agavi/exception -->
<autoload class="AgaviAutoloadException">%core.agavi_dir%/exception/AgaviAutoloadException.class.php</autoload>
<autoload class="AgaviCacheException">%core.agavi_dir%/exception/AgaviCacheException.class.php</autoload>
+ <autoload class="AgaviClassNotFoundException">%core.agavi_dir%/exception/AgaviClassNotFoundException.class.php</autoload>
<autoload class="AgaviConfigurationException">%core.agavi_dir%/exception/AgaviConfigurationException.class.php</autoload>
<autoload class="AgaviControllerException">%core.agavi_dir%/exception/AgaviControllerException.class.php</autoload>
<autoload class="AgaviDatabaseException">%core.agavi_dir%/exception/AgaviDatabaseException.class.php</autoload>
<autoload class="AgaviException">%core.agavi_dir%/exception/AgaviException.class.php</autoload>
<autoload class="AgaviFactoryException">%core.agavi_dir%/exception/AgaviFactoryException.class.php</autoload>
<autoload class="AgaviFileException">%core.agavi_dir%/exception/AgaviFileException.class.php</autoload>
+ <autoload class="AgaviFileNotFoundException">%core.agavi_dir%/exception/AgaviFileNotFoundException.class.php</autoload>
<autoload class="AgaviFilterException">%core.agavi_dir%/exception/AgaviFilterException.class.php</autoload>
<autoload class="AgaviInitializationException">%core.agavi_dir%/exception/AgaviInitializationException.class.php</autoload>
<autoload class="AgaviDisabledModuleException">%core.agavi_dir%/exception/AgaviDisabledModuleException.class.php</autoload>

Modified: trunk/src/controller/AgaviController.class.php
===================================================================
--- trunk/src/controller/AgaviController.class.php 2011-12-26 18:10:57 UTC (rev 4912)
+++ trunk/src/controller/AgaviController.class.php 2011-12-26 18:17:29 UTC (rev 4913)
@@ -358,11 +358,11 @@
if(false !== ($file = $this->checkActionFile($moduleName, $actionName))) {
require($file);
} else {
- throw new AgaviException('Could not find file for Action "' . $actionName . '" in module "' . $moduleName . '"');
+ throw new AgaviFileNotFoundException(sprintf('Could not find file for Action "%s" in Module "%s".', $actionName, $moduleName));
}

if(!class_exists($class, false)) {
- throw new AgaviException('Could not find Action "' . $longActionName . '" for module "' . $moduleName . '"');
+ throw new AgaviClassNotFoundException(sprintf('Failed to instantiate Action "%s" in Module "%s" because file "%s" does not contain class "%s".', $actionName, $moduleName, $file, $class));
}
}

@@ -454,11 +454,11 @@
if(false !== ($file = $this->checkViewFile($moduleName, $viewName))) {
require($file);
} else {
- throw new AgaviException('Could not find file for View "' . $viewName . '" in module "' . $moduleName . '"');
+ throw new AgaviFileNotFoundException(sprintf('Could not find file for View "%s" in Module "%s".', $viewName, $moduleName));
}

if(!class_exists($class, false)) {
- throw new AgaviException('Could not find View "' . $longViewName . '" for module "' . $moduleName . '"');
+ throw new AgaviClassNotFoundException(sprintf('Failed to instantiate View "%s" in Module "%s" because file "%s" does not contain class "%s".', $viewName, $moduleName, $file, $class));
}
}

Modified: trunk/src/controller/AgaviExecutionContainer.class.php
===================================================================
--- trunk/src/controller/AgaviExecutionContainer.class.php 2011-12-26 18:10:57 UTC (rev 4912)
+++ trunk/src/controller/AgaviExecutionContainer.class.php 2011-12-26 18:17:29 UTC (rev 4913)
@@ -257,31 +257,23 @@
$controller->countExecution();

$moduleName = $this->getModuleName();
- $actionName = $this->getActionName();
-
+
try {
- // TODO: cleanup and merge with createActionInstance once Exceptions have been cleaned up and specced properly so that the two error conditions can be told apart
- if(false === $controller->checkActionFile($moduleName, $actionName)) {
- $this->setNext($this->createSystemActionForwardContainer('error_404'));
- return $this->proceed();
- }
-
- $this->actionInstance = $controller->createActionInstance($moduleName, $actionName);
+ $actionInstance = $this->getActionInstance();
} catch(AgaviDisabledModuleException $e) {
$this->setNext($this->createSystemActionForwardContainer('module_disabled'));
return $this->proceed();
- }
+ } catch(AgaviFileNotFoundException $e) {
+ $this->setNext($this->createSystemActionForwardContainer('error_404'));
+ return $this->proceed();
+ } // do not catch AgaviClassNotFoundException, we want that to bubble up since it means the class in the action file is named incorrectly

-
- // initialize the action
- $this->actionInstance->initialize($this);
-
// copy and merge request data as required
$this->initRequestData();

$filterChain = $this->getFilterChain();

- if(!$this->actionInstance->isSimple()) {
+ if(!$actionInstance->isSimple()) {
// simple actions have no filters

if(AgaviConfig::get('core.available', false)) {
@@ -317,7 +309,7 @@
*/
protected function initRequestData()
{
- if($this->actionInstance->isSimple()) {
+ if($this->getActionInstance()->isSimple()) {
if($this->arguments !== null) {
// clone it so mutating it has no effect on the "outside world"
$this->requestData = clone $this->arguments;
@@ -803,6 +795,18 @@
*/
public function getActionInstance()
{
+ if($this->actionInstance === null) {
+ $controller = $this->context->getController();
+
+ $moduleName = $this->getModuleName();
+ $actionName = $this->getActionName();
+
+ $this->actionInstance = $controller->createActionInstance($moduleName, $actionName);
+
+ // initialize the action
+ $this->actionInstance->initialize($this);
+ }
+
return $this->actionInstance;
}

@@ -816,6 +820,13 @@
*/
public function getViewInstance()
{
+ if($this->viewInstance === null) {
+ // get the view instance
+ $this->viewInstance = $this->getContext()->getController()->createViewInstance($this->getViewModuleName(), $this->getViewName());
+ // initialize the view
+ $this->viewInstance->initialize($this);
+ }
+
return $this->viewInstance;
}

Copied: trunk/src/exception/AgaviClassNotFoundException.class.php (from rev 4912, branches/david-httpcaching/src/exception/AgaviClassNotFoundException.class.php)
===================================================================
--- trunk/src/exception/AgaviClassNotFoundException.class.php (rev 0)
+++ trunk/src/exception/AgaviClassNotFoundException.class.php 2011-12-26 18:17:29 UTC (rev 4913)
@@ -0,0 +1,34 @@
+<?php
+
+// +---------------------------------------------------------------------------+
+// | This file is part of the Agavi package. |
+// | Copyright (c) 2005-2011 the Agavi Project. |
+// | |
+// | For the full copyright and license information, please view the LICENSE |
+// | file that was distributed with this source code. You can also view the |
+// | LICENSE file online at http://www.agavi.org/LICENSE.txt |
+// | vi: set noexpandtab: |
+// | Local Variables: |
+// | indent-tabs-mode: t |
+// | End: |
+// +---------------------------------------------------------------------------+
+
+/**
+ * AgaviClassNotFoundException is thrown when a class could not be found.
+ *
+ * @package agavi
+ * @subpackage exception
+ *
+ * @author David Zülke <david....@bitextender.com>
+ * @copyright Authors
+ * @copyright The Agavi Project
+ *
+ * @since 1.1.0
+ *
+ * @version $Id$
+ */
+class AgaviClassNotFoundException extends AgaviException
+{
+}
+
+?>

Copied: trunk/src/exception/AgaviFileNotFoundException.class.php (from rev 4912, branches/david-httpcaching/src/exception/AgaviFileNotFoundException.class.php)
===================================================================
--- trunk/src/exception/AgaviFileNotFoundException.class.php (rev 0)
+++ trunk/src/exception/AgaviFileNotFoundException.class.php 2011-12-26 18:17:29 UTC (rev 4913)
@@ -0,0 +1,34 @@
+<?php
+
+// +---------------------------------------------------------------------------+
+// | This file is part of the Agavi package. |
+// | Copyright (c) 2005-2011 the Agavi Project. |
+// | |
+// | For the full copyright and license information, please view the LICENSE |
+// | file that was distributed with this source code. You can also view the |
+// | LICENSE file online at http://www.agavi.org/LICENSE.txt |
+// | vi: set noexpandtab: |
+// | Local Variables: |
+// | indent-tabs-mode: t |
+// | End: |
+// +---------------------------------------------------------------------------+
+
+/**
+ * AgaviFileNotFoundException is thrown when a file could not be found.
+ *
+ * @package agavi
+ * @subpackage exception
+ *
+ * @author David Zülke <david....@bitextender.com>
+ * @copyright Authors
+ * @copyright The Agavi Project
+ *
+ * @since 1.1.0
+ *
+ * @version $Id$
+ */
+class AgaviFileNotFoundException extends AgaviException
+{
+}
+
+?>

Modified: trunk/src/filter/AgaviExecutionFilter.class.php
===================================================================
--- trunk/src/filter/AgaviExecutionFilter.class.php 2011-12-26 18:10:57 UTC (rev 4912)
+++ trunk/src/filter/AgaviExecutionFilter.class.php 2011-12-26 18:17:29 UTC (rev 4913)
@@ -461,10 +461,7 @@

$key = $request->toggleLock();
try {
- // get the view instance
- $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['view_name']);
- // initialize the view
- $viewInstance->initialize($container);
+ $viewInstance = $container->getViewInstance();
} catch(Exception $e) {
// we caught an exception... unlock the request and rethrow!
$request->toggleLock($key);
@@ -472,9 +469,6 @@
}
$request->toggleLock($key);

- // Set the View Instance in the container
- $container->setViewInstance($viewInstance);
-
$outputType = $container->getOutputType()->getName();

if($isCacheable) {


_______________________________________________
Agavi Commits Mailing List
com...@lists.agavi.org
http://lists.agavi.org/mailman/listinfo/commits

Reply all
Reply to author
Forward
0 new messages