Convert to singular path names and move ZF2 submodule
authorEvan Coury <me@evancoury.com>
Mon, 21 Nov 2011 20:27:58 +0000 (13:27 -0700)
committerEvan Coury <me@evancoury.com>
Mon, 21 Nov 2011 20:35:04 +0000 (13:35 -0700)
- s/configs/config
- s/vendors/vendor
- moved library/ZendFramework to vendor/ZendFramework, got rid of library/
- updated zf2 submodule
- added config/autoload path with readme explaining the purpose
- set up to glob for config/autoload/*.config.php

34 files changed:
.gitmodules
config/application.config.php [new file with mode: 0644]
config/autoload/README.md [new file with mode: 0644]
configs/application.config.php [deleted file]
library/ZendFramework [deleted submodule]
module/.gitignore [new file with mode: 0644]
module/Application/Module.php [new file with mode: 0644]
module/Application/autoload_classmap.php [new file with mode: 0644]
module/Application/autoload_function.php [new file with mode: 0644]
module/Application/autoload_register.php [new file with mode: 0644]
module/Application/configs/module.config.php [new file with mode: 0644]
module/Application/src/Application/Controller/ErrorController.php [new file with mode: 0644]
module/Application/src/Application/Controller/IndexController.php [new file with mode: 0644]
module/Application/src/Application/View/Listener.php [new file with mode: 0644]
module/Application/views/error/index.phtml [new file with mode: 0644]
module/Application/views/index/index.phtml [new file with mode: 0644]
module/Application/views/layouts/layout.phtml [new file with mode: 0644]
modules/.gitignore [deleted file]
modules/Application/Module.php [deleted file]
modules/Application/autoload_classmap.php [deleted file]
modules/Application/autoload_function.php [deleted file]
modules/Application/autoload_register.php [deleted file]
modules/Application/configs/module.config.php [deleted file]
modules/Application/src/Application/Controller/ErrorController.php [deleted file]
modules/Application/src/Application/Controller/IndexController.php [deleted file]
modules/Application/src/Application/View/Listener.php [deleted file]
modules/Application/views/error/index.phtml [deleted file]
modules/Application/views/index/index.phtml [deleted file]
modules/Application/views/layouts/layout.phtml [deleted file]
public/index.php
vendor/.gitignore [new file with mode: 0644]
vendor/README.md [new file with mode: 0644]
vendors/.gitignore [deleted file]
vendors/README.md [deleted file]

index 80fc458..8f630ff 100644 (file)
@@ -1,3 +1,3 @@
-[submodule "library/ZendFramework"]
-       path = library/ZendFramework
+[submodule "vendor/ZendFramework"]
+       path = vendor/ZendFramework
        url = git://github.com/zendframework/zf2.git
diff --git a/config/application.config.php b/config/application.config.php
new file mode 100644 (file)
index 0000000..273ebbe
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+return array(
+    'module_paths' => array(
+        realpath(dirname(__DIR__) . '/module'),
+        realpath(dirname(__DIR__) . '/vendor'),
+    ),
+    'modules' => array(
+        'Application',
+    ),
+    'module_listener_options' => array( 
+        'config_cache_enabled'    => false,
+        'cache_dir'               => realpath(dirname(__DIR__) . '/data/cache'),
+        'application_environment' => getenv('APPLICATION_ENV'),
+    ),
+);
diff --git a/config/autoload/README.md b/config/autoload/README.md
new file mode 100644 (file)
index 0000000..a42ef5b
--- /dev/null
@@ -0,0 +1,8 @@
+About this directory:
+=====================
+
+By default, this application is configured to load all configs in
+`./config/autoload/*.config.php`. Doing this provides a location for a
+developer to drop in configuration override files provided by modules, as well
+as cleanly provide individual, application-wide config files for things like
+database connections, etc.
diff --git a/configs/application.config.php b/configs/application.config.php
deleted file mode 100644 (file)
index b716191..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-return array(
-    'module_paths' => array(
-        realpath(__DIR__ . '/../modules'),
-        realpath(__DIR__ . '/../vendors'),
-    ),
-    'modules' => array(
-        'Application',
-    ),
-    'module_listener_options' => array( 
-        'config_cache_enabled'     => false,
-        'cache_dir'                => realpath(__DIR__ . '/../data/cache'),
-    ),
-);
diff --git a/library/ZendFramework b/library/ZendFramework
deleted file mode 160000 (submodule)
index 9fdf610..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 9fdf610f5e8bc3f6426753cee9a81efe5d0b5e53
diff --git a/module/.gitignore b/module/.gitignore
new file mode 100644 (file)
index 0000000..84460e1
--- /dev/null
@@ -0,0 +1,3 @@
+/*
+!Application/
+!.gitignore
diff --git a/module/Application/Module.php b/module/Application/Module.php
new file mode 100644 (file)
index 0000000..5bd9a70
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+
+namespace Application;
+
+use Zend\Module\Manager,
+    Zend\EventManager\StaticEventManager,
+    Zend\Module\Consumer\AutoloaderProvider;
+
+class Module implements AutoloaderProvider
+{
+    protected $view;
+    protected $viewListener;
+
+    public function init(Manager $moduleManager)
+    {
+        $events = StaticEventManager::getInstance();
+        $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
+    }
+
+    public function getAutoloaderConfig()
+    {
+        return array(
+            'Zend\Loader\ClassMapAutoloader' => array(
+                __DIR__ . '/autoload_classmap.php',
+            ),
+            'Zend\Loader\StandardAutoloader' => array(
+                'namespaces' => array(
+                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
+                ),
+            ),
+        );
+    }
+
+    public function getConfig($env = null)
+    {
+        return include __DIR__ . '/configs/module.config.php';
+    }
+    
+    public function initializeView($e)
+    {
+        $app          = $e->getParam('application');
+        $locator      = $app->getLocator();
+        $config       = $e->getParam('config');
+        $view         = $this->getView($app);
+        $viewListener = $this->getViewListener($view, $config);
+        $app->events()->attachAggregate($viewListener);
+        $events       = StaticEventManager::getInstance();
+        $viewListener->registerStaticListeners($events, $locator);
+    }
+
+    protected function getViewListener($view, $config)
+    {
+        if ($this->viewListener instanceof View\Listener) {
+            return $this->viewListener;
+        }
+
+        $viewListener       = new View\Listener($view, $config->layout);
+        $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
+
+        $this->viewListener = $viewListener;
+        return $viewListener;
+    }
+
+    protected function getView($app)
+    {
+        if ($this->view) {
+            return $this->view;
+        }
+
+        $di     = $app->getLocator();
+        $view   = $di->get('view');
+        $url    = $view->plugin('url');
+        $url->setRouter($app->getRouter());
+
+        $view->plugin('headTitle')->setSeparator(' - ')
+                                  ->setAutoEscape(false)
+                                  ->append('Application');
+        $this->view = $view;
+        return $view;
+    }
+}
diff --git a/module/Application/autoload_classmap.php b/module/Application/autoload_classmap.php
new file mode 100644 (file)
index 0000000..a30d090
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+return array(
+    'Application\View\Listener'              => __DIR__ . '/src/Application/View/Listener.php',
+    'Application\Controller\IndexController' => __DIR__ . '/src/Application/Controller/IndexController.php',
+    'Application\Controller\ErrorController' => __DIR__ . '/src/Application/Controller/ErrorController.php',
+    'Application\Module'                     => __DIR__ . '/Module.php',
+);
\ No newline at end of file
diff --git a/module/Application/autoload_function.php b/module/Application/autoload_function.php
new file mode 100644 (file)
index 0000000..3ea81c4
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+return function ($class) {
+    static $map;
+    if (!$map) {
+        $map = include __DIR__ . '/autoload_classmap.php';
+    }
+
+    if (!isset($map[$class])) {
+        return false;
+    }
+    return include $map[$class];
+};
diff --git a/module/Application/autoload_register.php b/module/Application/autoload_register.php
new file mode 100644 (file)
index 0000000..a8dcbb4
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+spl_autoload_register(include __DIR__ . '/autoload_function.php');
diff --git a/module/Application/configs/module.config.php b/module/Application/configs/module.config.php
new file mode 100644 (file)
index 0000000..9f266c0
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+return array(
+    'layout' => 'layouts/layout.phtml',
+    'di'     => array(
+        'instance' => array(
+            'alias' => array(
+                'index' => 'Application\Controller\IndexController',
+                'error' => 'Application\Controller\ErrorController',
+                'view'  => 'Zend\View\PhpRenderer',
+            ),
+            'Zend\View\PhpRenderer' => array(
+                'parameters' => array(
+                    'resolver' => 'Zend\View\TemplatePathStack',
+                    'options'  => array(
+                        'script_paths' => array(
+                            'application' => __DIR__ . '/../views',
+                        ),
+                    ),
+                ),
+            ),
+        ),
+    ),
+    'routes' => array(
+        'default' => array(
+            'type'    => 'Zend\Mvc\Router\Http\Segment',
+            'options' => array(
+                'route'    => '/[:controller[/:action]]',
+                'constraints' => array(
+                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
+                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
+                ),
+                'defaults' => array(
+                    'controller' => 'index',
+                    'action'     => 'index',
+                ),
+            ),
+        ),
+        'home' => array(
+            'type' => 'Zend\Mvc\Router\Http\Literal',
+            'options' => array(
+                'route'    => '/',
+                'defaults' => array(
+                    'controller' => 'index',
+                    'action'     => 'index',
+                ),
+            ),
+        ),
+    ),
+);
diff --git a/module/Application/src/Application/Controller/ErrorController.php b/module/Application/src/Application/Controller/ErrorController.php
new file mode 100644 (file)
index 0000000..17f002e
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace Application\Controller;
+
+use Zend\Mvc\Controller\ActionController;
+
+class ErrorController extends ActionController
+{
+    const ERROR_NO_ROUTE = 404;
+    const ERROR_NO_CONTROLLER = 404;
+
+    public function indexAction()
+    {
+        $error = $this->request->getMetadata('error', false);
+        if (!$error) {
+            $error = array(
+                'type'    => 404,
+                'message' => 'Page not found',
+            );
+        }
+        
+        switch ($error['type']) {
+            case self::ERROR_NO_ROUTE:
+            case self::ERROR_NO_CONTROLLER:
+            default:
+                // 404 error -- controller or action not found
+                $this->response->setStatusCode(404);
+                break;
+        }
+        
+        return array('message' => $error['message']);
+    }
+}
diff --git a/module/Application/src/Application/Controller/IndexController.php b/module/Application/src/Application/Controller/IndexController.php
new file mode 100644 (file)
index 0000000..8c1f5e1
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace Application\Controller;
+
+use Zend\Mvc\Controller\ActionController;
+
+class IndexController extends ActionController
+{
+    public function indexAction()
+    {
+        return array();
+    }
+}
diff --git a/module/Application/src/Application/View/Listener.php b/module/Application/src/Application/View/Listener.php
new file mode 100644 (file)
index 0000000..275736d
--- /dev/null
@@ -0,0 +1,224 @@
+<?php
+
+namespace Application\View;
+
+use ArrayAccess,
+    Zend\Di\Locator,
+    Zend\EventManager\EventCollection,
+    Zend\EventManager\ListenerAggregate,
+    Zend\EventManager\StaticEventCollection,
+    Zend\Http\PhpEnvironment\Response,
+    Zend\Mvc\Application,
+    Zend\Mvc\MvcEvent,
+    Zend\View\Renderer;
+
+class Listener implements ListenerAggregate
+{
+    protected $layout;
+    protected $listeners = array();
+    protected $staticListeners = array();
+    protected $view;
+    protected $displayExceptions = false;
+
+    public function __construct(Renderer $renderer, $layout = 'layout.phtml')
+    {
+        $this->view   = $renderer;
+        $this->layout = $layout;
+    }
+
+    public function setDisplayExceptionsFlag($flag)
+    {
+        $this->displayExceptions = (bool) $flag;
+        return $this;
+    }
+
+    public function displayExceptions()
+    {
+        return $this->displayExceptions;
+    }
+
+    public function attach(EventCollection $events)
+    {
+        $this->listeners[] = $events->attach('dispatch.error', array($this, 'renderError'));
+        $this->listeners[] = $events->attach('dispatch', array($this, 'render404'), -80);
+        $this->listeners[] = $events->attach('dispatch', array($this, 'renderLayout'), -1000);
+    }
+
+    public function detach(EventCollection $events)
+    {
+        foreach ($this->listeners as $key => $listener) {
+            $events->detach($listener);
+            unset($this->listeners[$key]);
+            unset($listener);
+        }
+    }
+
+    public function registerStaticListeners(StaticEventCollection $events, $locator)
+    {
+        $ident   = 'Application\Controller\PageController';
+        $handler = $events->attach($ident, 'dispatch', array($this, 'renderPageController'), -50);
+        $this->staticListeners[] = array($ident, $handler);
+
+        $ident   = 'Zend\Mvc\Controller\ActionController';
+        $handler = $events->attach($ident, 'dispatch', array($this, 'renderView'), -50);
+        $this->staticListeners[] = array($ident, $handler);
+    }
+
+    public function detachStaticListeners(StaticEventCollection $events)
+    {
+        foreach ($this->staticListeners as $i => $info) {
+            list($id, $handler) = $info;
+            $events->detach($id, $handler);
+            unset($this->staticListeners[$i]);
+        }
+    }
+
+    public function renderPageController(MvcEvent $e)
+    {
+        $page = $e->getResult();
+        if ($page instanceof Response) {
+            return;
+        }
+
+        $response = $e->getResponse();
+        if ($response->isNotFound()) {
+            return;
+        } 
+
+        $routeMatch = $e->getRouteMatch();
+
+        if (!$routeMatch) {
+            $page = '404';
+        } else {
+            $page = $routeMatch->getParam('action', '404');
+        }
+
+        if ($page == '404') {
+            $response->setStatusCode(404);
+        }
+
+        $script     = 'pages/' . $page . '.phtml';
+
+        // Action content
+        $content    = $this->view->render($script);
+        $e->setResult($content);
+
+        return $this->renderLayout($e);
+    }
+
+    public function renderView(MvcEvent $e)
+    {
+        $response = $e->getResponse();
+        if (!$response->isSuccess()) {
+            return;
+        }
+
+        $routeMatch = $e->getRouteMatch();
+        $controller = $routeMatch->getParam('controller', 'index');
+        $action     = $routeMatch->getParam('action', 'index');
+        $script     = $controller . '/' . $action . '.phtml';
+
+        $vars       = $e->getResult();
+        if (is_scalar($vars)) {
+            $vars = array('content' => $vars);
+        } elseif (is_object($vars) && !$vars instanceof ArrayAccess) {
+            $vars = (array) $vars;
+        }
+
+        $content    = $this->view->render($script, $vars);
+
+        $e->setResult($content);
+        return $content;
+    }
+
+    public function renderLayout(MvcEvent $e)
+    {
+        $response = $e->getResponse();
+        if (!$response) {
+            $response = new Response();
+            $e->setResponse($response);
+        }
+        if ($response->isRedirect()) {
+            return $response;
+        }
+
+        $footer   = $e->getParam('footer', false);
+        $vars     = array('footer' => $footer);
+
+        if (false !== ($contentParam = $e->getParam('content', false))) {
+            $vars['content'] = $contentParam;
+        } else {
+            $vars['content'] = $e->getResult();
+        }
+
+        $layout   = $this->view->render($this->layout, $vars);
+        $response->setContent($layout);
+        return $response;
+    }
+
+    public function render404(MvcEvent $e)
+    {
+        $vars = $e->getResult();
+        if ($vars instanceof Response) {
+            return;
+        }
+
+        $response = $e->getResponse();
+        if ($response->getStatusCode() != 404) {
+            // Only handle 404's
+            return;
+        }
+
+        $vars = array(
+            'message'            => 'Page not found.',
+            'exception'          => $e->getParam('exception'),
+            'display_exceptions' => $this->displayExceptions(),
+        );
+
+        $content = $this->view->render('pages/404.phtml', $vars);
+
+        $e->setResult($content);
+
+        return $this->renderLayout($e);
+    }
+
+    public function renderError(MvcEvent $e)
+    {
+        $error    = $e->getError();
+        $app      = $e->getTarget();
+        $response = $e->getResponse();
+        if (!$response) {
+            $response = new Response();
+            $e->setResponse($response);
+        }
+
+        switch ($error) {
+            case Application::ERROR_CONTROLLER_NOT_FOUND:
+            case Application::ERROR_CONTROLLER_INVALID:
+                $vars = array(
+                    'message'            => 'Page not found.',
+                    'exception'          => $e->getParam('exception'),
+                    'display_exceptions' => $this->displayExceptions(),
+                );
+                $response->setStatusCode(404);
+                break;
+
+            case Application::ERROR_EXCEPTION:
+            default:
+                $exception = $e->getParam('exception');
+                $vars = array(
+                    'message'            => 'An error occurred during execution; please try again later.',
+                    'exception'          => $e->getParam('exception'),
+                    'display_exceptions' => $this->displayExceptions(),
+                );
+                $response->setStatusCode(500);
+                break;
+        }
+
+        $content = $this->view->render('error/index.phtml', $vars);
+
+        $e->setResult($content);
+
+        return $this->renderLayout($e);
+    }
+}
diff --git a/module/Application/views/error/index.phtml b/module/Application/views/error/index.phtml
new file mode 100644 (file)
index 0000000..454b615
--- /dev/null
@@ -0,0 +1,14 @@
+<h1>An error occurred</h1>
+<h2><?php echo $this->message ?></h2>
+
+<?php if (isset($this->exception)): ?>
+
+<h3>Exception information:</h3>
+<p>
+    <b>Message:</b> <?php echo $this->exception->getMessage() ?>
+</p>
+
+<h3>Stack trace:</h3>
+<pre><?php echo $this->exception->getTraceAsString() ?></pre>
+
+<?php endif ?>
diff --git a/module/Application/views/index/index.phtml b/module/Application/views/index/index.phtml
new file mode 100644 (file)
index 0000000..e89aa33
--- /dev/null
@@ -0,0 +1,3 @@
+<strong>Module:</strong>        Application &raquo; 
+<strong>Controller:</strong>    Index &raquo; 
+<strong>Action:</strong>        index
diff --git a/module/Application/views/layouts/layout.phtml b/module/Application/views/layouts/layout.phtml
new file mode 100644 (file)
index 0000000..5a1e9ea
--- /dev/null
@@ -0,0 +1,15 @@
+<?php echo $this->doctype() ?>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <?php echo $this->headTitle() ?>
+    <?php echo $this->headMeta() ?>
+    <?php echo $this->headLink() ?>
+    <?php echo $this->headScript() ?>
+
+</head>
+<body>
+<?php echo $this->raw('content'); ?>
+</body>
+</html>
diff --git a/modules/.gitignore b/modules/.gitignore
deleted file mode 100644 (file)
index 84460e1..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/*
-!Application/
-!.gitignore
diff --git a/modules/Application/Module.php b/modules/Application/Module.php
deleted file mode 100644 (file)
index 5bd9a70..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-
-namespace Application;
-
-use Zend\Module\Manager,
-    Zend\EventManager\StaticEventManager,
-    Zend\Module\Consumer\AutoloaderProvider;
-
-class Module implements AutoloaderProvider
-{
-    protected $view;
-    protected $viewListener;
-
-    public function init(Manager $moduleManager)
-    {
-        $events = StaticEventManager::getInstance();
-        $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
-    }
-
-    public function getAutoloaderConfig()
-    {
-        return array(
-            'Zend\Loader\ClassMapAutoloader' => array(
-                __DIR__ . '/autoload_classmap.php',
-            ),
-            'Zend\Loader\StandardAutoloader' => array(
-                'namespaces' => array(
-                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
-                ),
-            ),
-        );
-    }
-
-    public function getConfig($env = null)
-    {
-        return include __DIR__ . '/configs/module.config.php';
-    }
-    
-    public function initializeView($e)
-    {
-        $app          = $e->getParam('application');
-        $locator      = $app->getLocator();
-        $config       = $e->getParam('config');
-        $view         = $this->getView($app);
-        $viewListener = $this->getViewListener($view, $config);
-        $app->events()->attachAggregate($viewListener);
-        $events       = StaticEventManager::getInstance();
-        $viewListener->registerStaticListeners($events, $locator);
-    }
-
-    protected function getViewListener($view, $config)
-    {
-        if ($this->viewListener instanceof View\Listener) {
-            return $this->viewListener;
-        }
-
-        $viewListener       = new View\Listener($view, $config->layout);
-        $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
-
-        $this->viewListener = $viewListener;
-        return $viewListener;
-    }
-
-    protected function getView($app)
-    {
-        if ($this->view) {
-            return $this->view;
-        }
-
-        $di     = $app->getLocator();
-        $view   = $di->get('view');
-        $url    = $view->plugin('url');
-        $url->setRouter($app->getRouter());
-
-        $view->plugin('headTitle')->setSeparator(' - ')
-                                  ->setAutoEscape(false)
-                                  ->append('Application');
-        $this->view = $view;
-        return $view;
-    }
-}
diff --git a/modules/Application/autoload_classmap.php b/modules/Application/autoload_classmap.php
deleted file mode 100644 (file)
index a30d090..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-return array(
-    'Application\View\Listener'              => __DIR__ . '/src/Application/View/Listener.php',
-    'Application\Controller\IndexController' => __DIR__ . '/src/Application/Controller/IndexController.php',
-    'Application\Controller\ErrorController' => __DIR__ . '/src/Application/Controller/ErrorController.php',
-    'Application\Module'                     => __DIR__ . '/Module.php',
-);
\ No newline at end of file
diff --git a/modules/Application/autoload_function.php b/modules/Application/autoload_function.php
deleted file mode 100644 (file)
index 3ea81c4..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-return function ($class) {
-    static $map;
-    if (!$map) {
-        $map = include __DIR__ . '/autoload_classmap.php';
-    }
-
-    if (!isset($map[$class])) {
-        return false;
-    }
-    return include $map[$class];
-};
diff --git a/modules/Application/autoload_register.php b/modules/Application/autoload_register.php
deleted file mode 100644 (file)
index a8dcbb4..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php
-spl_autoload_register(include __DIR__ . '/autoload_function.php');
diff --git a/modules/Application/configs/module.config.php b/modules/Application/configs/module.config.php
deleted file mode 100644 (file)
index 9f266c0..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-return array(
-    'layout' => 'layouts/layout.phtml',
-    'di'     => array(
-        'instance' => array(
-            'alias' => array(
-                'index' => 'Application\Controller\IndexController',
-                'error' => 'Application\Controller\ErrorController',
-                'view'  => 'Zend\View\PhpRenderer',
-            ),
-            'Zend\View\PhpRenderer' => array(
-                'parameters' => array(
-                    'resolver' => 'Zend\View\TemplatePathStack',
-                    'options'  => array(
-                        'script_paths' => array(
-                            'application' => __DIR__ . '/../views',
-                        ),
-                    ),
-                ),
-            ),
-        ),
-    ),
-    'routes' => array(
-        'default' => array(
-            'type'    => 'Zend\Mvc\Router\Http\Segment',
-            'options' => array(
-                'route'    => '/[:controller[/:action]]',
-                'constraints' => array(
-                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
-                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
-                ),
-                'defaults' => array(
-                    'controller' => 'index',
-                    'action'     => 'index',
-                ),
-            ),
-        ),
-        'home' => array(
-            'type' => 'Zend\Mvc\Router\Http\Literal',
-            'options' => array(
-                'route'    => '/',
-                'defaults' => array(
-                    'controller' => 'index',
-                    'action'     => 'index',
-                ),
-            ),
-        ),
-    ),
-);
diff --git a/modules/Application/src/Application/Controller/ErrorController.php b/modules/Application/src/Application/Controller/ErrorController.php
deleted file mode 100644 (file)
index 17f002e..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-namespace Application\Controller;
-
-use Zend\Mvc\Controller\ActionController;
-
-class ErrorController extends ActionController
-{
-    const ERROR_NO_ROUTE = 404;
-    const ERROR_NO_CONTROLLER = 404;
-
-    public function indexAction()
-    {
-        $error = $this->request->getMetadata('error', false);
-        if (!$error) {
-            $error = array(
-                'type'    => 404,
-                'message' => 'Page not found',
-            );
-        }
-        
-        switch ($error['type']) {
-            case self::ERROR_NO_ROUTE:
-            case self::ERROR_NO_CONTROLLER:
-            default:
-                // 404 error -- controller or action not found
-                $this->response->setStatusCode(404);
-                break;
-        }
-        
-        return array('message' => $error['message']);
-    }
-}
diff --git a/modules/Application/src/Application/Controller/IndexController.php b/modules/Application/src/Application/Controller/IndexController.php
deleted file mode 100644 (file)
index 8c1f5e1..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-namespace Application\Controller;
-
-use Zend\Mvc\Controller\ActionController;
-
-class IndexController extends ActionController
-{
-    public function indexAction()
-    {
-        return array();
-    }
-}
diff --git a/modules/Application/src/Application/View/Listener.php b/modules/Application/src/Application/View/Listener.php
deleted file mode 100644 (file)
index 275736d..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-<?php
-
-namespace Application\View;
-
-use ArrayAccess,
-    Zend\Di\Locator,
-    Zend\EventManager\EventCollection,
-    Zend\EventManager\ListenerAggregate,
-    Zend\EventManager\StaticEventCollection,
-    Zend\Http\PhpEnvironment\Response,
-    Zend\Mvc\Application,
-    Zend\Mvc\MvcEvent,
-    Zend\View\Renderer;
-
-class Listener implements ListenerAggregate
-{
-    protected $layout;
-    protected $listeners = array();
-    protected $staticListeners = array();
-    protected $view;
-    protected $displayExceptions = false;
-
-    public function __construct(Renderer $renderer, $layout = 'layout.phtml')
-    {
-        $this->view   = $renderer;
-        $this->layout = $layout;
-    }
-
-    public function setDisplayExceptionsFlag($flag)
-    {
-        $this->displayExceptions = (bool) $flag;
-        return $this;
-    }
-
-    public function displayExceptions()
-    {
-        return $this->displayExceptions;
-    }
-
-    public function attach(EventCollection $events)
-    {
-        $this->listeners[] = $events->attach('dispatch.error', array($this, 'renderError'));
-        $this->listeners[] = $events->attach('dispatch', array($this, 'render404'), -80);
-        $this->listeners[] = $events->attach('dispatch', array($this, 'renderLayout'), -1000);
-    }
-
-    public function detach(EventCollection $events)
-    {
-        foreach ($this->listeners as $key => $listener) {
-            $events->detach($listener);
-            unset($this->listeners[$key]);
-            unset($listener);
-        }
-    }
-
-    public function registerStaticListeners(StaticEventCollection $events, $locator)
-    {
-        $ident   = 'Application\Controller\PageController';
-        $handler = $events->attach($ident, 'dispatch', array($this, 'renderPageController'), -50);
-        $this->staticListeners[] = array($ident, $handler);
-
-        $ident   = 'Zend\Mvc\Controller\ActionController';
-        $handler = $events->attach($ident, 'dispatch', array($this, 'renderView'), -50);
-        $this->staticListeners[] = array($ident, $handler);
-    }
-
-    public function detachStaticListeners(StaticEventCollection $events)
-    {
-        foreach ($this->staticListeners as $i => $info) {
-            list($id, $handler) = $info;
-            $events->detach($id, $handler);
-            unset($this->staticListeners[$i]);
-        }
-    }
-
-    public function renderPageController(MvcEvent $e)
-    {
-        $page = $e->getResult();
-        if ($page instanceof Response) {
-            return;
-        }
-
-        $response = $e->getResponse();
-        if ($response->isNotFound()) {
-            return;
-        } 
-
-        $routeMatch = $e->getRouteMatch();
-
-        if (!$routeMatch) {
-            $page = '404';
-        } else {
-            $page = $routeMatch->getParam('action', '404');
-        }
-
-        if ($page == '404') {
-            $response->setStatusCode(404);
-        }
-
-        $script     = 'pages/' . $page . '.phtml';
-
-        // Action content
-        $content    = $this->view->render($script);
-        $e->setResult($content);
-
-        return $this->renderLayout($e);
-    }
-
-    public function renderView(MvcEvent $e)
-    {
-        $response = $e->getResponse();
-        if (!$response->isSuccess()) {
-            return;
-        }
-
-        $routeMatch = $e->getRouteMatch();
-        $controller = $routeMatch->getParam('controller', 'index');
-        $action     = $routeMatch->getParam('action', 'index');
-        $script     = $controller . '/' . $action . '.phtml';
-
-        $vars       = $e->getResult();
-        if (is_scalar($vars)) {
-            $vars = array('content' => $vars);
-        } elseif (is_object($vars) && !$vars instanceof ArrayAccess) {
-            $vars = (array) $vars;
-        }
-
-        $content    = $this->view->render($script, $vars);
-
-        $e->setResult($content);
-        return $content;
-    }
-
-    public function renderLayout(MvcEvent $e)
-    {
-        $response = $e->getResponse();
-        if (!$response) {
-            $response = new Response();
-            $e->setResponse($response);
-        }
-        if ($response->isRedirect()) {
-            return $response;
-        }
-
-        $footer   = $e->getParam('footer', false);
-        $vars     = array('footer' => $footer);
-
-        if (false !== ($contentParam = $e->getParam('content', false))) {
-            $vars['content'] = $contentParam;
-        } else {
-            $vars['content'] = $e->getResult();
-        }
-
-        $layout   = $this->view->render($this->layout, $vars);
-        $response->setContent($layout);
-        return $response;
-    }
-
-    public function render404(MvcEvent $e)
-    {
-        $vars = $e->getResult();
-        if ($vars instanceof Response) {
-            return;
-        }
-
-        $response = $e->getResponse();
-        if ($response->getStatusCode() != 404) {
-            // Only handle 404's
-            return;
-        }
-
-        $vars = array(
-            'message'            => 'Page not found.',
-            'exception'          => $e->getParam('exception'),
-            'display_exceptions' => $this->displayExceptions(),
-        );
-
-        $content = $this->view->render('pages/404.phtml', $vars);
-
-        $e->setResult($content);
-
-        return $this->renderLayout($e);
-    }
-
-    public function renderError(MvcEvent $e)
-    {
-        $error    = $e->getError();
-        $app      = $e->getTarget();
-        $response = $e->getResponse();
-        if (!$response) {
-            $response = new Response();
-            $e->setResponse($response);
-        }
-
-        switch ($error) {
-            case Application::ERROR_CONTROLLER_NOT_FOUND:
-            case Application::ERROR_CONTROLLER_INVALID:
-                $vars = array(
-                    'message'            => 'Page not found.',
-                    'exception'          => $e->getParam('exception'),
-                    'display_exceptions' => $this->displayExceptions(),
-                );
-                $response->setStatusCode(404);
-                break;
-
-            case Application::ERROR_EXCEPTION:
-            default:
-                $exception = $e->getParam('exception');
-                $vars = array(
-                    'message'            => 'An error occurred during execution; please try again later.',
-                    'exception'          => $e->getParam('exception'),
-                    'display_exceptions' => $this->displayExceptions(),
-                );
-                $response->setStatusCode(500);
-                break;
-        }
-
-        $content = $this->view->render('error/index.phtml', $vars);
-
-        $e->setResult($content);
-
-        return $this->renderLayout($e);
-    }
-}
diff --git a/modules/Application/views/error/index.phtml b/modules/Application/views/error/index.phtml
deleted file mode 100644 (file)
index 454b615..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<h1>An error occurred</h1>
-<h2><?php echo $this->message ?></h2>
-
-<?php if (isset($this->exception)): ?>
-
-<h3>Exception information:</h3>
-<p>
-    <b>Message:</b> <?php echo $this->exception->getMessage() ?>
-</p>
-
-<h3>Stack trace:</h3>
-<pre><?php echo $this->exception->getTraceAsString() ?></pre>
-
-<?php endif ?>
diff --git a/modules/Application/views/index/index.phtml b/modules/Application/views/index/index.phtml
deleted file mode 100644 (file)
index e89aa33..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<strong>Module:</strong>        Application &raquo; 
-<strong>Controller:</strong>    Index &raquo; 
-<strong>Action:</strong>        index
diff --git a/modules/Application/views/layouts/layout.phtml b/modules/Application/views/layouts/layout.phtml
deleted file mode 100644 (file)
index 5a1e9ea..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php echo $this->doctype() ?>
-
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-    <?php echo $this->headTitle() ?>
-    <?php echo $this->headMeta() ?>
-    <?php echo $this->headLink() ?>
-    <?php echo $this->headScript() ?>
-
-</head>
-<body>
-<?php echo $this->raw('content'); ?>
-</body>
-</html>
index 9c388be..767893c 100644 (file)
@@ -1,19 +1,8 @@
 <?php
-// Define application environment
-defined('APPLICATION_ENV')
-    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
-
-// Ensure ZF is on the include path
-set_include_path(implode(PATH_SEPARATOR, array(
-    realpath(__DIR__ . '/../library'),
-    realpath(__DIR__ . '/../library/ZendFramework/library'),
-    get_include_path(),
-)));
-
-require_once 'Zend/Loader/AutoloaderFactory.php';
+require_once dirname(__DIR__) . '/vendor/ZendFramework/library/Zend/Loader/AutoloaderFactory.php';
 Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => array()));
 
-$appConfig = include __DIR__ . '/../configs/application.config.php';
+$appConfig = include dirname(__DIR__) . '/config/application.config.php';
 
 $moduleLoader = new Zend\Loader\ModuleAutoloader($appConfig['module_paths']);
 $moduleLoader->register();
@@ -21,10 +10,11 @@ $moduleLoader->register();
 $moduleManager = new Zend\Module\Manager($appConfig['modules']);
 $listenerOptions = new Zend\Module\Listener\ListenerOptions($appConfig['module_listener_options']);
 $moduleManager->setDefaultListenerOptions($listenerOptions);
+$moduleManager->getConfigListener()->addConfigGlobPath(dirname(__DIR__) . '/config/autoload/*.config.php');
 $moduleManager->loadModules();
 
 // Create application, bootstrap, and run
-$bootstrap      = new Zend\Mvc\Bootstrap($moduleManager->getMergedConfig());
-$application    = new Zend\Mvc\Application;
+$bootstrap   = new Zend\Mvc\Bootstrap($moduleManager->getMergedConfig());
+$application = new Zend\Mvc\Application;
 $bootstrap->bootstrap($application);
 $application->run()->send();
diff --git a/vendor/.gitignore b/vendor/.gitignore
new file mode 100644 (file)
index 0000000..e082ac7
--- /dev/null
@@ -0,0 +1,3 @@
+/*
+!README.md
+!.gitignore
diff --git a/vendor/README.md b/vendor/README.md
new file mode 100644 (file)
index 0000000..29381b6
--- /dev/null
@@ -0,0 +1 @@
+This `vendors/` directory is where third-party modules should be installed.
diff --git a/vendors/.gitignore b/vendors/.gitignore
deleted file mode 100644 (file)
index e082ac7..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-/*
-!README.md
-!.gitignore
diff --git a/vendors/README.md b/vendors/README.md
deleted file mode 100644 (file)
index 29381b6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-This `vendors/` directory is where third-party modules should be installed.