Skip to content

Commit

Permalink
Refactoring. Moving all recess\core to recess\lang.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Sep 13, 2009
1 parent fff5143 commit f95e978
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 41 deletions.
42 changes: 40 additions & 2 deletions recess/recess.php
@@ -1,8 +1,46 @@
<?php
set_include_path(__DIR__ . PATH_SEPARATOR . get_include_path());

function callable($callback) {
if(!is_callable($callback)) {
throw new Exception('First parameter $callable must be a valid is_callable value.');
}

if(!is_array($callback)) {
return $callback;
}

if(is_string($callback[0])) {
return function() use ($callback) {
$args = func_get_args();
switch(count($args)) {
case 0: return $callback[0]::$callback[1]();
case 1: return $callback[0]::$callback[1]($args[0]);
case 2: return $callback[0]::$callback[1]($args[0],$args[1]);
case 3: return $callback[0]::$callback[1]($args[0],$args[1],$args[2]);
case 4: return $callback[0]::$callback[1]($args[0],$args[1],$args[2],$args[3]);
case 5: return $callback[0]::$callback[1]($args[0],$args[1],$args[2],$args[3],$args[4]);
default: return call_user_func_array($callback,$args);
}
};
} else {
return function() use ($callback) {
$args = func_get_args();
switch(count($args)) {
case 0: return $callback[0]->$callback[1]();
case 1: return $callback[0]->$callback[1]($args[0]);
case 2: return $callback[0]->$callback[1]($args[0],$args[1]);
case 3: return $callback[0]->$callback[1]($args[0],$args[1],$args[2]);
case 4: return $callback[0]->$callback[1]($args[0],$args[1],$args[2],$args[3]);
case 5: return $callback[0]->$callback[1]($args[0],$args[1],$args[2],$args[3],$args[4]);
default: return call_user_func_array($callback,$args);
}
};
}
}

// Include the Autoloader
include 'recess/core/ClassLoader.class.php';
include 'recess/lang/ClassLoader.class.php';

// Register Autoload Function
spl_autoload_register('recess\core\ClassLoader::load');
spl_autoload_register('recess\lang\ClassLoader::load');
@@ -1,5 +1,5 @@
<?php
namespace recess\core;
namespace recess\lang;
/**
* Turn callables into delicious Candy.
* Candied callables that can be wrapped in the all the decorators you desire.
Expand Down
@@ -1,5 +1,5 @@
<?php
namespace recess\core;
namespace recess\lang;

require __DIR__.'/Event.class.php';
require __DIR__.'/Candy.class.php';
Expand Down
@@ -1,5 +1,5 @@
<?php
namespace recess\core;
namespace recess\lang;
/**
* When something important happens, let others know with an Event.
*
Expand Down
4 changes: 1 addition & 3 deletions recess/test/recess/RecessAllTests.php
@@ -1,15 +1,13 @@
<?php
require_once 'PHPUnit/Framework.php';
require_once 'recess/core/RecessCoreAllTests.php';
require_once 'recess/lang/RecessLangAllTests.php';

class RecessAllTests
{
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('recess\lang');
$suite = new PHPUnit_Framework_TestSuite('recess');

$suite->addTestSuite(RecessCoreAllTests::suite());
$suite->addTestSuite(RecessLangAllTests::suite());

return $suite;
Expand Down
19 changes: 0 additions & 19 deletions recess/test/recess/core/RecessCoreAllTests.php

This file was deleted.

@@ -1,8 +1,8 @@
<?php
require_once 'PHPUnit/Framework.php';

include_once __DIR__ . '/../../../recess/core/Candy.class.php';
use recess\core\Candy;
include_once __DIR__ . '/../../../recess/lang/Candy.class.php';
use recess\lang\Candy;

class CandyTest extends PHPUnit_Framework_TestCase {

Expand Down
@@ -1,22 +1,22 @@
<?php
require_once 'PHPUnit/Framework.php';

include_once __DIR__ . '/../../../recess/core/ClassLoader.class.php';
use recess\core\ClassLoader;
include_once __DIR__ . '/../../../recess/lang/ClassLoader.class.php';
use recess\lang\ClassLoader;

set_include_path(__DIR__.'/../../'.PATH_SEPARATOR.get_include_path());

class ClassLoaderTest extends PHPUnit_Framework_TestCase {

function testOnLoad() {
$onLoad = ClassLoader::onLoad();
$this->assertType('recess\core\Event',$onLoad);
$this->assertType('recess\lang\Event',$onLoad);
$onLoad2 = ClassLoader::onLoad();
$this->assertTrue($onLoad === $onLoad2);
$theClass = '';
ClassLoader::onLoad()->call(function($class) use (&$theClass) { $theClass = $class; });
ClassLoader::load('recess\core\Dummy');
$this->assertEquals('recess\core\Dummy',$theClass);
ClassLoader::load('recess\lang\Dummy');
$this->assertEquals('recess\lang\Dummy',$theClass);
}

function testWrapLoad() {
Expand All @@ -36,14 +36,14 @@ function($load,$class) use (&$loadedCount) {
}

function testLoadDummy() {
ClassLoader::load('recess\core\Dummy');
$dummy = new recess\core\Dummy;
$this->assertType('recess\core\Dummy',$dummy);
ClassLoader::load('recess\lang\Dummy');
$dummy = new recess\lang\Dummy;
$this->assertType('recess\lang\Dummy',$dummy);
$this->assertEquals('hello world',$dummy->helloWorld());
}

function testWrapAfterLoadDummy() {
ClassLoader::load('recess\core\Dummy');
ClassLoader::load('recess\lang\Dummy');
$loadedCount = 0;
ClassLoader::wrapLoad(
function($load,$class) use (&$loadedCount) {
Expand Down
@@ -1,5 +1,5 @@
<?php
namespace recess\core;
namespace recess\lang;

class Dummy {
function helloWorld() { return 'hello world'; }
Expand Down
@@ -1,8 +1,8 @@
<?php
require_once 'PHPUnit/Framework.php';

include_once __DIR__ . '/../../../recess/core/Event.class.php';
use recess\core\Event;
include_once __DIR__ . '/../../../recess/lang/Event.class.php';
use recess\lang\Event;

class EventTest extends PHPUnit_Framework_TestCase {

Expand Down
7 changes: 7 additions & 0 deletions recess/test/recess/lang/RecessLangAllTests.php
@@ -1,5 +1,8 @@
<?php
require_once 'PHPUnit/Framework.php';
require_once 'recess/lang/CandyTest.php';
require_once 'recess/lang/EventTest.php';
require_once 'recess/lang/ClassLoaderTest.php';
require_once 'recess/lang/AnnotationTest.php';
require_once 'recess/lang/AttachedMethodTest.php';
require_once 'recess/lang/ReflectionMethodTest.php';
Expand All @@ -12,6 +15,10 @@ public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('recess\lang');

$suite->addTestSuite('EventTest');
$suite->addTestSuite('CandyTest');
$suite->addTestSuite('ClassLoaderTest');

$suite->addTestSuite('AnnotationTest');
$suite->addTestSuite('AttachedMethodTest');
$suite->addTestSuite('ReflectionClassTest');
Expand Down

0 comments on commit f95e978

Please sign in to comment.