Skip to content

Commit

Permalink
Implemented a "cascading filesystem" to enable easy class overloading
Browse files Browse the repository at this point in the history
This commit sees quite a bit of reorganization. The entire framework has
now been moved into a namespace called \Proem\Api, however, internally
the framework still calls objects from \Proem. This means that a user
can easily override a class of the framework by defining it within the
\Proem namespace, and extending it's conterpart within \Proem\Api.

I will cover more on the subject within some documentation.

I also moved the Autoloader out of it's containing Loader namespace
which was no longer required.

Fixes #7
  • Loading branch information
trq committed Jan 3, 2012
1 parent f3d8f10 commit 936513e
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 12 deletions.
20 changes: 14 additions & 6 deletions lib/Proem/Loader/Autoloader.php → lib/Proem/Api/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @namespace Proem\Loader
*/
namespace Proem\Loader;
namespace Proem\Api;

/**
* Proem\Autoloader
Expand Down Expand Up @@ -107,8 +107,20 @@ public function register()
*/
public function load($class)
{
if ($class[0] == '\\') {
$class = substr($class, 1);
}

if ($file = $this->locate($class)) {
include $file;
include_once $file;
} else {
if (substr($class, 0, 5) == 'Proem') {
$api_class = str_replace('Proem\\', 'Proem\\Api\\', $class);
if ($file = $this->locate($api_class)) {
include_once $file;
class_alias($api_class, $class);
}
}
}
return $this;
}
Expand All @@ -122,10 +134,6 @@ public function load($class)
*/
private function locate($class)
{
if ($class[0] == '\\') {
$class = substr($class, 1);
}

if (false !== $pos = strrpos($class, '\\')) {
$namespace = substr($class, 0, $pos);
$className = substr($class, $pos + 1);
Expand Down
2 changes: 1 addition & 1 deletion lib/Proem/Proem.php → lib/Proem/Api/Proem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* @namespace Proem
*/
namespace Proem;
namespace Proem\Api;

/**
* Proem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @namespace Proem\
*/
namespace Proem\Util;
namespace Proem\Api\Util;

/**
* Proem\Util\Callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @namespace Proem\Util\Opt
*/
namespace Proem\Util\Opt;
namespace Proem\Api\Util\Opt;

use Proem\Util\Callback;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @namespace Proem\Util\Opt
*/
namespace Proem\Util\Opt;
namespace Proem\Api\Util\Opt;

/**
* Proem\Util\Opt\Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* THE SOFTWARE.
*/

namespace Proem\Tests\Proem\Loader;
namespace Proem\Tests;

use Proem\Loader\Autoloader;
use Proem\Autoloader;
use Namespaced;

class AutoloaderTest extends \PHPUnit_Framework_TestCase
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions tests/lib/Proem/Tests/Fixtures/Proem/Proem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Proem;

class Proem extends Api\Proem
{
public function somethingNew()
{
return true;
}
}
6 changes: 6 additions & 0 deletions tests/lib/Proem/Tests/ProemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ public function testCanInstantiate()
{
$this->assertInstanceOf('Proem\Proem', new Proem);
}

public function testCascadingFilesystem()
{
$proem = new Proem;
$this->assertTrue($proem->somethingNew());
}
}

0 comments on commit 936513e

Please sign in to comment.