Skip to content

Commit

Permalink
Removed Artax\App functionality made obsolete by the addition of th…
Browse files Browse the repository at this point in the history
…e `app.setUp` event

Prior to the addition of the built-in `app.setUp` event, the `Artax\App` boot class
included protected methods to optionally load HTTP libs based on a configuration
directive, automatically register namespaced class autoloaders and auto-require
an array of user-specified files from config.

Giving apps the ability to specify their own listeners for basic setUp obviates the
need for this functionality to be hard-wired into the framework boot class. This
also opens up the door for users to specify custom class autoloaders (if they want to)
instead of forcing the framework autoloader on them. The packaged autoloader is still
used during the boot process to register autoloading for libs in the Artax namespace.

Before: an application's config file would specify namespaces/path combinations
in key-value array pairs and have the autoloaders automatically registered.

After: the application should specify it's own event listener to register any desired
autoloaders and attach it to the `app.setUp` event.

The `Artax\Config` class and its associated test file were also updated to remove the
unnecessary references to the removed functionality.

I'm still getting used to the infinite possibilities of an event-driven approach to
application design, so we may still need to eliminate some of these sorts of things.
  • Loading branch information
rdlowrey committed Mar 7, 2012
1 parent 57803e3 commit c889c26
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 79 deletions.
6 changes: 4 additions & 2 deletions artax.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@
*/


$artax = (new artax\App(
$artax = new artax\App(
(new artax\ConfigLoader)->setConfigFile(AX_CONFIG_FILE),
new artax\Config,
new artax\handlers\ErrorHandler,
new artax\handlers\FatalHandler,
new artax\ClassLoaderFactory,
new artax\DepProvider(new artax\DotNotation),
new artax\events\Mediator
))->boot();
);
$artax->boot();
$artax->notify('app.ready');
67 changes: 11 additions & 56 deletions src/artax/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public function __construct(
$this->bootSteps = [
'registerHandlers',
'initConfig',
'loadBundles',
'loadAutoRequires',
'initClassAutoloaders',
'initClassAutoloader',
'initDepProvider',
'initEvents'
];
Expand All @@ -116,6 +114,9 @@ public function __construct(
/**
* Boot the application
*
* Once all boot steps are completed, the `app.setup` event fires to notify
* any user-specified "setup" listeners.
*
* @return void
* @notifies app.ready|\artax\App
*/
Expand All @@ -124,7 +125,7 @@ public function boot()
while ($step = array_shift($this->bootSteps)) {
$this->$step();
}
$this->notify('app.ready');
$this->notify('app.setUp');
return $this;
}

Expand Down Expand Up @@ -159,63 +160,16 @@ protected function initConfig()
$this->fatalHandler->setDebug($this->config['debug']);
}

/**
* Load optional lib bundles
*
* @return void
*/
protected function loadBundles()
{
if ( ! empty($this->config['httpBundle'])) {
require AX_SYSTEM_DIR . '/src/artax/views/ViewInterface.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpMatcher.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpRequestInterface.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpRequest.php';
require AX_SYSTEM_DIR . '/src/artax/http/BucketInterface.php';
require AX_SYSTEM_DIR . '/src/artax/http/BucketAbstract.php';
require AX_SYSTEM_DIR . '/src/artax/http/ServerBucket.php';
require AX_SYSTEM_DIR . '/src/artax/http/HeaderBucket.php';
require AX_SYSTEM_DIR . '/src/artax/http/ParamBucket.php';
require AX_SYSTEM_DIR . '/src/artax/http/CookieBucket.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpControllerAbstract.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpResponseInterface.php';
require AX_SYSTEM_DIR . '/src/artax/http/HttpResponse.php';
}
}

/**
* Registers Artax class loader and any other specified namespace loaders
*
* @return void
*/
protected function initClassAutoloaders()
protected function initClassAutoloader()
{
$this->clsLoaderFactory->make($this->config['classLoader'], 'artax')
->setIncludePath(AX_SYSTEM_DIR.'/src')
->register();

$type = $this->config->get('classLoader');

if ($namespaces = $this->config->get('namespaces')) {
foreach ($namespaces as $ns => $path) {
$ns = $ns ?: NULL;
$this->clsLoaderFactory->make($type, $ns)->setIncludePath($path)->register();
}
}
}

/**
* Require a user-specified list of includes
*
* @return void
*/
protected function loadAutoRequires()
{
if ($autoRequires = $this->config->get('autoRequire')) {
foreach ($autoRequires as $file) {
require $file;
}
}
}

/**
Expand Down Expand Up @@ -249,14 +203,15 @@ protected function initDepProvider()
* Mediator to allow handling exceptions and shutdowns with chainable event
* listeners.
*
* Once all config listeners are loaded, a listener is attached to the end
* of the `app.setUp` queue to fire the `app.ready` event.
*
* @return void
*/
protected function initEvents()
{
$this->mediator->setRebinder(function($lambda){
return \Closure::bind($lambda, $this);
});

$this->mediator->setRebindObj($this);

if ($listeners = $this->config->get('listeners')) {
foreach ($listeners as $listener) {
$this->mediator->push($listener[0], $listener[1]);
Expand Down
15 changes: 0 additions & 15 deletions src/artax/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public function __construct()
{
$this->defaults = [
'debug' => FALSE,
'httpBundle' => FALSE,
'classLoader' => 'standard',
'namespaces' => [],
'autoRequire' => [],
'deps' => [],
'listeners' => [],
'routes' => []
Expand Down Expand Up @@ -73,17 +70,5 @@ protected function setDebug($val)
{
$this->params['debug'] = $this->filterBool($val);
}

/**
* Setter function for httpBundle directive
*
* @param bool $val Flag specifying if HTTP libs should load on boot
*
* @return void
*/
protected function setHttpBundle($val)
{
$this->params['httpBundle'] = $this->filterBool($val);
}
}
}
7 changes: 1 addition & 6 deletions test/src/artax/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public function testBeginsEmpty()
$c = new ConfigTestCoverageImplementation;
$defaults = [
'debug' => FALSE,
'httpBundle' => FALSE,
'classLoader' => 'standard',
'namespaces' => [],
'autoRequire' => [],
'deps' => [],
'listeners' => [],
'routes' => []
Expand All @@ -29,14 +26,12 @@ public function testBeginsEmpty()
/**
* @covers artax\Config::filterBool
* @covers artax\Config::setDebug
* @covers artax\Config::setHttpBundle
*/
public function testFilterBoolSanitizesBoolInput()
{
$params = ['debug'=>0, 'httpBundle'=>'Off', 'cliBundle'=> 'on'];
$params = ['debug'=>0];
$c = (new ConfigTestCoverageImplementation())->load($params);
$this->assertEquals(FALSE, $c->get('debug'));
$this->assertEquals(FALSE, $c->get('httpBundle'));
}
}

Expand Down

0 comments on commit c889c26

Please sign in to comment.