Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 7 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
16 examples/misc/bootstrap.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once(__DIR__.'/../../misc/bootstrap.php');
+
+$eol = php_sapi_name() == 'cli' ? "\n" : "<br>";
+define('EOL', $eol);
+
+function convert($size)
+ {
+ $unit=array('b','kb','mb','gb','tb','pb');
+ return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
+ }
+
+ function memory_usage($realUsage = false){
+ return convert(memory_get_usage($realUsage));
+ }
View
114 src/Autoload/Autoload.php
@@ -11,10 +11,8 @@
*/
/**
- * \PEIP\Autoload\SimpleAutoload
- * Extended Autoloading class. Loads class-paths from
- * AutoloadPaths::$paths on startup.
- * Can (re)generate AutoloadPaths::$paths through method 'make'.
+ * \PEIP\Autoload\SimpleAutoload
+ * Autolad class
*
* @author Timo Michna <timomichna/yahoo.de>
* @package PEIP
@@ -23,9 +21,13 @@
*/
-require_once(dirname(__FILE__).'/SimpleAutoload.php');
+class Autoload {
-class Autoload extends SimpleAutoload {
+ protected
+ $baseDir;
+
+ static protected
+ $instance;
/**
* Constructor.
@@ -35,100 +37,70 @@ class Autoload extends SimpleAutoload {
*/
protected function __construct(){
$this->init();
- require_once(dirname(__FILE__).'/AutoloadPaths.php');
- $this->setClassPaths(AutoloadPaths::$paths);
}
/**
- * Retrieves Singleton instance
- *
+ * Retrieves Singleton instance
+ *
* @access public
* @static
* @return Autoload
- */
- static public function getInstance(){
- if (!isset(self::$instance)){
+ */
+ static public function getInstance($new = false){
+ if (!isset(self::$instance) || $new){
self::$instance = new Autoload();
}
return self::$instance;
}
-
/**
+ * Initialization method.
+ * Registers autoload with this class.
+ *
* @access protected
- * @return Autoload
*/
- protected static function doGetInstance(){
- return self::$instance = new Autoload();
- }
-
- /**
- * Scans a directory recursively for php-files and adds them to autoload
- *
- * @access public
- * @param string directoy to scan
- * @return void
- */
- public function scanDirectory($dir){
- if(is_dir($dir)){
- $this->addClassPaths($this->findPaths(NULL, new RecursiveDirectoryIterator($dir)));
+ protected function init(){
+ $this->baseDir = self::getBaseDirectory();
+ ini_set('unserialize_callback_func', 'spl_autoload_call');
+ if (false === spl_autoload_register(array($this, 'autoload'))){
+ // @codeCoverageIgnoreStart
+ throw new \RuntimeException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class($this)));
+ // @codeCoverageIgnoreEnd
}
- }
-
- /**
- * Regenerates the class/files associations and replaces them in AutoloadPaths
- *
- * @access public
- * @static
- * @return void
- */
- public static function make(){
- $baseDir = self::getBaseDirectory();
- $iterator = new RecursiveDirectoryIterator($baseDir);
- $paths = self::findPaths($baseDir, $iterator);
- $pathsFile = dirname(__FILE__).'/AutoloadPaths.php';
- $content = file_get_contents($pathsFile);
- $content = preg_replace('/public static \$paths = array *\(.*?\);/s', sprintf("public static \$paths = %s;", var_export($paths, true)), $content);
- file_put_contents($pathsFile, $content);
}
/**
- * Traverses a directory to find class-files
- *
+ * returns the autoload base directory.
+ * Registers autoload with this class.
+ *
* @access protected
- * @static
- * @param string $baseDir the directory under which to look for classes.
- * @param RecursiveDirectoryIterator $iterator A RecursiveDirectoryIterator instance for the directory
- * @param array $paths the array to store the class/path associations in.
- * @return Autoload
- */
- protected static function findPaths($baseDir, RecursiveDirectoryIterator $iterator, array $paths = array()){
- $iterator->rewind();
- while($iterator->valid()){
- if($iterator->isDir() && !$iterator->isDot()){
- $paths = self::findPaths($baseDir, $iterator->getChildren(), $paths);
- }elseif($iterator->isFile() && strrchr($iterator->getFilename(), '.') == '.php'){
- $class = $iterator->getBasename('.php');
- $paths[$class] = str_replace($baseDir, '', $iterator->getPathName());
- }
- $iterator->next();
- }
- return $paths;
+ * @return string the base directory
+ */
+ protected static function getBaseDirectory(){
+ return str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'));
}
/**
* handles the autoloading of classes
- * scans for files in extensions dir, if no class-path set
*
* @access public
* @param string $class the class to load
* @return path to the class-file
*/
- public function autoload($class){
- if(!$this->getClassPath($class)){
- $this->scanDirectory(realpath(dirname(__FILE__).'/../extensions'));
+ public function autoload($class){
+ $res = false;
+ if(!class_exists($class, false)){
+ $path = str_replace('PEIP\\', '', $class);
+ $path = $this->baseDir.DIRECTORY_SEPARATOR
+ .str_replace('\\', DIRECTORY_SEPARATOR, $path).'.php';
+ if (is_file($path)){
+ require $path;
+ if(class_exists($class) || interface_exists($class)){
+ $res = true;
+ }
+ }
}
- parent::autoload($class);
+ return $res;
}
}
View
260 src/Autoload/AutoloadPaths.php
@@ -1,260 +0,0 @@
-<?php
-
-namespace PEIP\Autoload;
-
-namespace PEIP\Autoload;
-
-/*
- * This file is part of the PEIP package.
- * (c) 2009-2011 Timo Michna <timomichna/yahoo.de>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * AutoloadPaths
- * Wrapper class to hold information of class-paths.
- * Value of AutoloadPaths::$paths is created by call
- * of Autoload::make().
- *
- * @author Timo Michna <timomichna/yahoo.de>
- * @package PEIP
- * @subpackage autoload
- */
-
-use PEIP\Dispatcher\EventClassDispatcher;
-use PEIP\Dispatcher\ObjectMapDispatcher;
-use PEIP\Dispatcher\ClassDispatcher;
-use PEIP\Dispatcher\ObjectEventDispatcher;
-use PEIP\Dispatcher\ClassEventDispatcher;
-use PEIP\Dispatcher\MapDispatcher;
-use PEIP\Dispatcher\Dispatcher;
-use PEIP\Dispatcher\IteratingDispatcher;
-use PEIP\Event\EventBuilder;
-use PEIP\Event\Event;
-use PEIP\Event\Observable;
-use PEIP\Channel\DirectChannel;
-use PEIP\Channel\PublishSubscribeChannel;
-use PEIP\Channel\MessageChannel;
-use PEIP\Channel\ChannelRegistry;
-use PEIP\Channel\QueueChannel;
-use PEIP\Channel\PollableChannel;
-use PEIP\Channel\PriorityChannel;
-use PEIP\Channel\ChannelAdapter;
-use PEIP\Translator\XMLArrayTranslator;
-use PEIP\Pipe\SimpleFixedEventPipe;
-use PEIP\Pipe\Pipe;
-use PEIP\Pipe\FixedEventPipe;
-use PEIP\Pipe\EventPipe;
-use PEIP\Pipe\SimpleEventPipe;
-use PEIP\Pipe\CommandPipe;
-use PEIP\Handler\CallableHandler;
-use PEIP\Command\Command;
-use PEIP\Data\ParameterHolderCollection;
-use PEIP\Data\ParameterCollection;
-use PEIP\Data\InternalStoreAbstract;
-use PEIP\Data\StoreCollection;
-use PEIP\Data\Store;
-use PEIP\Data\ArrayAccess;
-use PEIP\Data\ParameterHolder;
-use PEIP\Service\ServiceContainer;
-use PEIP\Service\SplittingServiceActivator;
-use PEIP\Service\ServiceActivator;
-use PEIP\Service\ServiceContainerBuilder;
-use PEIP\Service\HeaderServiceActivator;
-use PEIP\Service\ServiceProvider;
-use PEIP\Service\StringServiceActivator;
-use PEIP\Factory\ServiceFactory;
-use PEIP\Factory\DedicatedFactory;
-use PEIP\Gateway\SimpleMessagingGateway;
-use PEIP\Selector\ContentClassSelector;
-use PEIP\Selector\ContentTypeSelector;
-use PEIP\Util\ReflectionPool;
-use PEIP\Util\Test;
-use PEIP\Util\Reflection;
-use PEIP\Base\VisitableArray;
-use PEIP\Base\Sealer;
-use PEIP\Base\ObjectStorage;
-use PEIP\Base\DynamicAdapter;
-use PEIP\Base\GenericBuilder;
-use PEIP\Base\ReflectionClassBuilder;
-use PEIP\Base\FlyAdapter;
-use PEIP\Message\CallableMessageHandler;
-use PEIP\Message\TextMessage;
-use PEIP\Message\MessageBuilder;
-use PEIP\Message\ErrorMessage;
-use PEIP\Message\GenericMessage;
-use PEIP\Message\CommandMessage;
-use PEIP\Message\StringMessage;
-use PEIP\Context\XMLContextReader;
-use PEIP\Context\XMLContext;
-use PEIP\Plugins\BasePlugin;
-use PEIP\Listener\Wiretap;
-
-class AutoloadPaths {
-
- // please, dont�t edit these lines manually
- // use Autoload::make() instead
- public static $paths = array (
- 'PEIP\ABS\Aggregator\MessageBarrierHandler' => '/ABS/aggregator/PEIP\ABS\Aggregator\MessageBarrierHandler.php',
- 'PEIP\ABS\Router\Router' => '/ABS/router/PEIP\ABS\Router\Router.php',
- 'PEIP\ABS\Dispatcher\MapDispatcher' => '/ABS/dispatcher/PEIP\ABS\Dispatcher\MapDispatcher.php',
- 'PEIP\ABS\Dispatcher\Dispatcher' => '/ABS/dispatcher/PEIP\ABS\Dispatcher\Dispatcher.php',
- 'PEIP\ABS\Channel\SubscribableChannel' => '/ABS/channel/PEIP\ABS\Channel\SubscribableChannel.php',
- 'PEIP\ABS\Channel\PollableChannel' => '/ABS/channel/PEIP\ABS\Channel\PollableChannel.php',
- 'PEIP\ABS\Channel\Channel' => '/ABS/channel/PEIP\ABS\Channel\Channel.php',
- 'PEIP\ABS\Splitter\MessageSplitter' => '/ABS/splitter/PEIP\ABS\Splitter\MessageSplitter.php',
- 'PEIP\ABS\Pipe\EventPipe' => '/ABS/pipe/PEIP\ABS\Pipe\EventPipe.php',
- 'PEIP\ABS\Handler\MessageHandler' => '/ABS/handler/PEIP\ABS\Handler\MessageHandler.php',
- 'PEIP\ABS\Handler\ReplyProducingMessageHandler' => '/ABS/handler/PEIP\ABS\Handler\ReplyProducingMessageHandler.php',
- 'PEIP\ABS\Handler\DiscardingMessageHandler' => '/ABS/handler/PEIP\ABS\Handler\DiscardingMessageHandler.php',
- 'PEIP\ABS\Command\Command' => '/ABS/command/PEIP\ABS\Command\Command.php',
- 'PEIP\ABS\Transformer\ContentTransformer' => '/ABS/transformer/PEIP\ABS\Transformer\ContentTransformer.php',
- 'PEIP\ABS\Transformer\Transformer' => '/ABS/transformer/PEIP\ABS\Transformer\Transformer.php',
- 'PEIP\ABS\Service\ServiceActivator' => '/ABS/service/PEIP\ABS\Service\ServiceActivator.php',
- 'PEIP\ABS\Base\MutableContainer' => '/ABS/base/PEIP\ABS\Base\MutableContainer.php',
- 'PEIP\ABS\Base\Connectable' => '/ABS/base/PEIP\ABS\Base\Connectable.php',
- 'PEIP\ABS\Base\Container' => '/ABS/base/PEIP\ABS\Base\Container.php',
- 'PEIP\ABS\Request\Connection' => '/ABS/request/PEIP\ABS\Request\Connection.php',
- 'PEIP\ABS\Request\Request' => '/ABS/request/PEIP\ABS\Request\Request.php',
- 'PEIP\ABS\Context\ContextPlugin' => '/ABS/context/PEIP\ABS\Context\ContextPlugin.php',
- 'EventClassDispatcher' => '/dispatcher/EventClassDispatcher.php',
- 'ObjectMapDispatcher' => '/dispatcher/ObjectMapDispatcher.php',
- 'ClassDispatcher' => '/dispatcher/ClassDispatcher.php',
- 'ObjectEventDispatcher' => '/dispatcher/ObjectEventDispatcher.php',
- 'ClassEventDispatcher' => '/dispatcher/ClassEventDispatcher.php',
- 'MapDispatcher' => '/dispatcher/MapDispatcher.php',
- 'Dispatcher' => '/dispatcher/Dispatcher.php',
- 'IteratingDispatcher' => '/dispatcher/IteratingDispatcher.php',
- 'EventBuilder' => '/event/EventBuilder.php',
- 'Event' => '/event/Event.php',
- 'Observable' => '/event/Observable.php',
- 'DirectChannel' => '/channel/DirectChannel.php',
- 'PublishSubscribeChannel' => '/channel/PublishSubscribeChannel.php',
- 'MessageChannel' => '/channel/MessageChannel.php',
- 'ChannelRegistry' => '/channel/ChannelRegistry.php',
- 'QueueChannel' => '/channel/QueueChannel.php',
- 'PollableChannel' => '/channel/PollableChannel.php',
- 'PriorityChannel' => '/channel/PriorityChannel.php',
- 'ChannelAdapter' => '/channel/ChannelAdapter.php',
- 'XMLArrayTranslator' => '/translator/XMLArrayTranslator.php',
- 'SimpleFixedEventPipe' => '/pipe/SimpleFixedEventPipe.php',
- 'Pipe' => '/pipe/Pipe.php',
- 'FixedEventPipe' => '/pipe/FixedEventPipe.php',
- 'Event_Pipe' => '/pipe/Event_Pipe.php',
- 'SimpleEventPipe' => '/pipe/SimpleEventPipe.php',
- 'CommandPipe' => '/pipe/CommandPipe.php',
- 'CallableHandler' => '/handler/CallableHandler.php',
- 'Command' => '/command/Command.php',
- 'ParameterHolderCollection' => '/data/ParameterHolderCollection.php',
- 'ParameterCollection' => '/data/ParameterCollection.php',
- 'InternalStoreAbstract' => '/data/InternalStoreAbstract.php',
- 'StoreCollection' => '/data/StoreCollection.php',
- 'Store' => '/data/Store.php',
- 'ArrayAccess' => '/data/ArrayAccess.php',
- 'ParameterHolder' => '/data/ParameterHolder.php',
- 'ServiceContainer' => '/service/ServiceContainer.php',
- 'SplittingServiceActivator' => '/service/SplittingServiceActivator.php',
- 'ServiceActivator' => '/service/ServiceActivator.php',
- 'ServiceContainer_Builder' => '/service/ServiceContainer_Builder.php',
- 'HeaderServiceActivator' => '/service/HeaderServiceActivator.php',
- 'ServiceProvider' => '/service/ServiceProvider.php',
- 'StringServiceActivator' => '/service/StringServiceActivator.php',
- 'ServiceFactory' => '/factory/ServiceFactory.php',
- 'DedicatedFactory' => '/factory/DedicatedFactory.php',
- 'PEIP' => '/PEIP.php',
- 'SimpleMessagingGateway' => '/gateway/SimpleMessagingGateway.php',
- 'PEIP\INF\Aggregator\CompletionStrategy' => '/INF/aggregator/PEIP\INF\Aggregator\CompletionStrategy.php',
- 'PEIP\INF\Aggregator\CorrelationStrategy' => '/INF/aggregator/PEIP\INF\Aggregator\CorrelationStrategy.php',
- 'PEIP\INF\Dispatcher\BreakableDispatcher' => '/INF/dispatcher/PEIP\INF\Dispatcher\BreakableDispatcher.php',
- 'PEIP\INF\Dispatcher\ObjectMapDispatcher' => '/INF/dispatcher/PEIP\INF\Dispatcher\ObjectMapDispatcher.php',
- 'PEIP\INF\Dispatcher\MapDispatcher' => '/INF/dispatcher/PEIP\INF\Dispatcher\MapDispatcher.php',
- 'PEIP\INF\Dispatcher\ListDispatcher' => '/INF/dispatcher/PEIP\INF\Dispatcher\ListDispatcher.php',
- 'PEIP\INF\Dispatcher\Dispatcher' => '/INF/dispatcher/PEIP\INF\Dispatcher\Dispatcher.php',
- 'PEIP\INF\Event\EventHandler' => '/INF/event/PEIP\INF\Event\EventHandler.php',
- 'PEIP\INF\Event\EventDispatcher' => '/INF/event/PEIP\INF\Event\EventDispatcher.php',
- 'PEIP\INF\Event\EventPublisher' => '/INF/event/PEIP\INF\Event\EventPublisher.php',
- 'PEIP\INF\Event\Listener' => '/INF/event/PEIP\INF\Event\Listener.php',
- 'PEIP\INF\Event\Event' => '/INF/event/PEIP\INF\Event\Event.php',
- 'PEIP\INF\Event\Observable' => '/INF/event/PEIP\INF\Event\Observable.php',
- 'PEIP\INF\Event\Connectable' => '/INF/event/PEIP\INF\Event\Connectable.php',
- 'PEIP\INF\Event\Observer' => '/INF/event/PEIP\INF\Event\Observer.php',
- 'PEIP\INF\Channel\ChannelResolver' => '/INF/channel/PEIP\INF\Channel\ChannelResolver.php',
- 'PEIP\INF\Channel\PollableChannel' => '/INF/channel/PEIP\INF\Channel\PollableChannel.php',
- 'PEIP\INF\Channel\Channel' => '/INF/channel/PEIP\INF\Channel\Channel.php',
- 'PEIP\INF\Channel\SubscribableChannel' => '/INF/channel/PEIP\INF\Channel\SubscribableChannel.php',
- 'PEIP\INF\Handler\Handler' => '/INF/handler/PEIP\INF\Handler\Handler.php',
- 'PEIP\INF\Command\Command' => '/INF/command/PEIP\INF\Command\Command.php',
- 'PEIP\INF\Command\ParametricCommand' => '/INF/command/PEIP\INF\Command\ParametricCommand.php',
- 'PEIP\INF\Transformer\Transformer' => '/INF/transformer/PEIP\INF\Transformer\Transformer.php',
- 'PEIP\INF\Data\StoreCollection' => '/INF/data/PEIP\INF\Data\StoreCollection.php',
- 'PEIP\INF\Data\ParameterHolder' => '/INF/data/PEIP\INF\Data\ParameterHolder.php',
- 'PEIP\INF\Data\ParameterHolder_Collection' => '/INF/data/PEIP\INF\Data\ParameterHolder_Collection.php',
- 'PEIP\INF\Data\Store' => '/INF/data/PEIP\INF\Data\Store.php',
- 'PEIP\INF\Service\ServiceContainer' => '/INF/service/PEIP\INF\Service\ServiceContainer.php',
- 'PEIP\INF\Service\ServiceActivator' => '/INF/service/PEIP\INF\Service\ServiceActivator.php',
- 'PEIP\INF\Factory\DedicatedFactory' => '/INF/factory/PEIP\INF\Factory\DedicatedFactory.php',
- 'PEIP\INF\Gateway\MessagingGateway' => '/INF/gateway/PEIP\INF\Gateway\MessagingGateway.php',
- 'PEIP\INF\Selector\MessageSelector' => '/INF/selector/PEIP\INF\Selector\MessageSelector.php',
- 'PEIP\INF\Base\Lifecycle' => '/INF/base/PEIP\INF\Base\Lifecycle.php',
- 'PEIP\INF\Base\SingletonMap' => '/INF/base/PEIP\INF\Base\SingletonMap.php',
- 'PEIP\INF\Base\SingletonArgs' => '/INF/base/PEIP\INF\Base\SingletonArgs.php',
- 'PEIP\INF\Base\Identifier' => '/INF/base/PEIP\INF\Base\Identifier.php',
- 'PEIP\INF\Base\MutableContainer' => '/INF/base/PEIP\INF\Base\MutableContainer.php',
- 'PEIP\INF\Base\Singleton' => '/INF/base/PEIP\INF\Base\Singleton.php',
- 'PEIP\INF\Base\Visitor' => '/INF/base/PEIP\INF\Base\Visitor.php',
- 'PEIP\INF\Base\SingletonMap_Array' => '/INF/base/PEIP\INF\Base\SingletonMap_Array.php',
- 'PEIP\INF\Base\Visitable' => '/INF/base/PEIP\INF\Base\Visitable.php',
- 'PEIP\INF\Base\Plugable' => '/INF/base/PEIP\INF\Base\Plugable.php',
- 'PEIP\INF\Base\Filter' => '/INF/base/PEIP\INF\Base\Filter.php',
- 'PEIP\INF\Base\Document' => '/INF/base/PEIP\INF\Base\Document.php',
- 'PEIP\INF\Base\Container' => '/INF/base/PEIP\INF\Base\Container.php',
- 'PEIP\INF\Base\Unsealer' => '/INF/base/PEIP\INF\Base\Unsealer.php',
- 'PEIP\INF\Base\Buildable' => '/INF/base/PEIP\INF\Base\Buildable.php',
- 'PEIP\INF\Base\Sealer' => '/INF/base/PEIP\INF\Base\Sealer.php',
- 'PEIP\INF\Request\Request' => '/INF/request/PEIP\INF\Request\Request.php',
- 'PEIP\INF\Request\Connection' => '/INF/request/PEIP\INF\Request\Connection.php',
- 'PEIP\INF\Message\MessageHandler' => '/INF/message/PEIP\INF\Message\MessageHandler.php',
- 'PEIP\INF\Message\MessageChannel' => '/INF/message/PEIP\INF\Message\MessageChannel.php',
- 'PEIP\INF\Message\HeaderEnricher' => '/INF/message/PEIP\INF\Message\HeaderEnricher.php',
- 'PEIP\INF\Message\Message' => '/INF/message/PEIP\INF\Message\Message.php',
- 'PEIP\INF\Message\Message_Sender' => '/INF/message/PEIP\INF\Message\Message_Sender.php',
- 'PEIP\INF\Message\Message_Builder' => '/INF/message/PEIP\INF\Message\Message_Builder.php',
- 'PEIP\INF\Message\PollableMessageChannel' => '/INF/message/PEIP\INF\Message\PollableMessageChannel.php',
- 'PEIP\INF\Message\EnvelopeMessage' => '/INF/message/PEIP\INF\Message\EnvelopeMessage.php',
- 'PEIP\INF\Message\StringMessage' => '/INF/message/PEIP\INF\Message\StringMessage.php',
- 'PEIP\INF\Message\Message_Dispatcher' => '/INF/message/PEIP\INF\Message\Message_Dispatcher.php',
- 'PEIP\INF\Message\Message_Receiver' => '/INF/message/PEIP\INF\Message\Message_Receiver.php',
- 'PEIP\INF\Message\Message_Source' => '/INF/message/PEIP\INF\Message\Message_Source.php',
- 'PEIP\INF\Context\ContextPlugin' => '/INF/context/PEIP\INF\Context\ContextPlugin.php',
- 'PEIP\INF\Context\Context' => '/INF/context/PEIP\INF\Context\Context.php',
- 'ContentClassSelector' => '/selector/ContentClassSelector.php',
- 'ContentTypeSelector' => '/selector/ContentTypeSelector.php',
- 'ReflectionPool' => '/util/ReflectionPool.php',
- 'Test' => '/util/Test.php',
- 'Reflection' => '/util/Reflection.php',
- 'VisitableArray' => '/base/VisitableArray.php',
- 'Sealer' => '/base/Sealer.php',
- 'ObjectStorage' => '/base/ObjectStorage.php',
- 'DynamicAdapter' => '/base/DynamicAdapter.php',
- 'GenericBuilder' => '/base/GenericBuilder.php',
- 'Reflection_Class_Builder' => '/base/Reflection_Class_Builder.php',
- 'FlyAdapter' => '/base/FlyAdapter.php',
- 'CallableMessageHandler' => '/message/CallableMessageHandler.php',
- 'TextMessage' => '/message/TextMessage.php',
- 'MessageBuilder' => '/message/MessageBuilder.php',
- 'ErrorMessage' => '/message/ErrorMessage.php',
- 'GenericMessage' => '/message/GenericMessage.php',
- 'Command_Message' => '/message/Command_Message.php',
- 'StringMessage' => '/message/StringMessage.php',
- 'XMLContextReader' => '/context/XMLContextReader.php',
- 'XMLContext' => '/context/XMLContext.php',
- 'BasePlugin' => '/plugins/BasePlugin.php',
- 'SimpleAutoload' => '/autoload/SimpleAutoload.php',
- 'Autoload' => '/autoload/Autoload.php',
- 'AutoloadPaths' => '/autoload/AutoloadPaths.php',
- 'Wiretap' => '/listener/Wiretap.php',
-);
-
-}
View
164 src/Autoload/SimpleAutoload.php
@@ -1,164 +0,0 @@
-<?php
-
-namespace PEIP\Autoload;
-/*
- * This file is part of the PEIP package.
- * (c) 2009-2011 Timo Michna <timomichna/yahoo.de>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * SimpleAutoload
- * Class providing basic autoload features
- *
- * @author Timo Michna <timomichna/yahoo.de>
- * @package PEIP
- * @subpackage autoload
- */
-
-
-class SimpleAutoload {
-
- protected
- $baseDir = null,
- $classPaths = array();
-
- static protected
- $instance;
-
- /**
- * Constructor.
- *
- * @access protected
- */
- protected function __construct(){
- $this->init();
- }
-
- /**
- * Initialization method.
- * Registers autoload with this class.
- *
- * @access protected
- */
- protected function init(){
- $this->baseDir = self::getBaseDirectory();
- ini_set('unserialize_callback_func', 'spl_autoload_call');
- if (false === spl_autoload_register(array($this, 'autoload'))){
- throw new \RuntimeException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class($this)));
- }
- }
-
- /**
- * returns the autoload base directory.
- * Registers autoload with this class.
- *
- * @access protected
- * @return string the base directory
- */
- protected static function getBaseDirectory(){
- return str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'));
- }
-
- /**
- * Retrieves Singleton instance
- *
- * @access public
- * @static
- * @return SimpleAutoload
- */
- static public function getInstance(){
- if (!isset(self::$instance)){
- self::$instance = new SimpleAutoload();
- }
- return self::$instance;
- }
-
- /**
- * Retrieves Singleton instance
- * To be overwritten by subclasses
- *
- * @access protected
- * @return SimpleAutoload
- */
- protected static function doGetInstance(){
- return self::$instance = new SimpleAutoload();;
- }
-
- /**
- * Sets a single file-path for a class
- *
- * @access public
- * @param string $class the class name
- * @param string $path the path to the class-file
- * @return void
- */
- public function setClassPath($class, $path){
- $this->classPaths[$class] = $path;
- }
-
- /**
- * Sets all class-paths as key(class)/value(path) pairs array
- *
- * @access public
- * @param array $classPaths class-paths as key(class)/value(path) pairs array
- * @return void
- */
- public function setClassPaths(array $classPaths){
- $this->classPaths = $classPaths;
- }
-
- /**
- * adds class-paths as key(class)/value(path) pairs array
- *
- * @access public
- * @param array $classPaths class-paths as key(class)/value(path) pairs array
- * @return void
- */
- public function addClassPaths(array $classPaths){
- $this->classPaths = array_merge($this->classPaths, $classPaths);
- }
-
-
- /**
- * returns the path to a class-file (if registered)
- *
- * @access public
- * @param string $class the class name
- * @return path to the class-file
- */
- public function getClassPath($class){
- if (!isset($this->classPaths[$class])){
- return null;
- }
- $file = $this->classPaths[$class];
- if(!is_file($file)){
- $file = $this->baseDir.DIRECTORY_SEPARATOR.$file;
- }
- return $file;
- }
-
- /**
- * handles the autoloading of classes
- *
- * @access public
- * @param string $class the class to load
- * @return path to the class-file
- */
- public function autoload($class){
- $path = str_replace('PEIP\\', '', $class);
- $path = $this->baseDir.'/'.str_replace('\\', '/', $path).'.php';
- //$path = $this->getClassPath($class);
- if (is_file($path)){
- require $path;
- if(class_exists($class) || interface_exists($class)){
- return true;
- }
- }
- return false;
- }
-}
-
-
View
12 src/Base/FlyAdapter.php
@@ -18,10 +18,6 @@
* @subpackage base
*/
-
-
-
-
class FlyAdapter {
@@ -30,7 +26,7 @@ class FlyAdapter {
* @param $methodMap
* @return
*/
- public function __construct(ArrayAccess $methodMap){
+ public function __construct(array $methodMap){
$this->methodMap = $methodMap;
}
@@ -54,8 +50,12 @@ public function setSubject($subject){
*/
public function __call($method, $arguments){
if(array_key_exists($method, $this->methodMap)){
- return call_user_func_array(array($this->subject, $this->methodMap[$method]), $arguments);
+ return call_user_func_array(
+ array($this->subject, $this->methodMap[$method]),
+ $arguments
+ );
}
+ return false;
}
}
View
46 src/Base/VisitableArray.php
@@ -1,46 +0,0 @@
-<?php
-
-namespace PEIP\Base;
-
-/*
- * This file is part of the PEIP package.
- * (c) 2009-2011 Timo Michna <timomichna/yahoo.de>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * VisitableArray
- *
- * @author Timo Michna <timomichna/yahoo.de>
- * @package PEIP
- * @subpackage base
- * @extends RecursiveArrayIterator
- * @implements RecursiveIterator, Iterator, Traversable, ArrayAccess, SeekableIterator, Serializable, \PEIP\INF\Base\Visitable
- */
-
-
-
-class VisitableArray
- extends \RecursiveArrayIterator
- implements \PEIP\INF\Base\Visitable{
-
-
-
- /**
- * @access public
- * @param $visitor
- * @return
- */
- public function acceptVisitor(\PEIP\INF\Base\Visitor $visitor){
- if($this->hasChildren()){
- foreach($this->getChildren as $child){
- $child->acceptVisitor($visitor);
- }
- }
- $this->acceptVisitor($visitor);
- }
-}
-
-
View
3 tests/AllTests.php
@@ -2,7 +2,7 @@
ini_set('display_errors', 1);
error_reporting(E_ALL);
-
+require_once dirname(__FILE__).'/autoload/AllTests.php';
require_once dirname(__FILE__).'/base/AllTests.php';
require_once dirname(__FILE__).'/channel/AllTests.php';
require_once dirname(__FILE__).'/command/AllTests.php';
@@ -22,6 +22,7 @@
class AllTests extends PHPUnit_Framework_TestSuite {
public static function suite(){
$suite = new PHPUnit_Framework_TestSuite('');
+ $suite->addTestSuite('Autoload_AllTests');
$suite->addTestSuite('Base_AllTests');
$suite->addTestSuite('Channel_AllTests');
$suite->addTestSuite('Command_AllTests');
View
19 tests/autoload/AllTests.php
@@ -0,0 +1,19 @@
+<?php
+
+ class Autoload_AllTests extends PHPUnit_Framework_TestSuite {
+ public static function suite(){
+ $suite = new PHPUnit_Framework_TestSuite('autoload');
+ $iterator = new DirectoryIterator(__DIR__);
+ $iterator->rewind();
+ while($iterator->valid()){
+ $file = $iterator->current();
+ if($iterator->isFile() && $file != 'AllTests.php'){
+ require_once __DIR__.'/'.$file;
+ $suiteName = str_replace('.php', '', $file);
+ $suite->addTestSuite(str_replace('.php', '', $file));
+ }
+ $iterator->next();
+ }
+ return $suite;
+ }
+}
View
27 tests/autoload/AutoloadTest.php
@@ -0,0 +1,27 @@
+<?php
+
+require_once(__DIR__.'/../../src/Autoload/Autoload.php');
+
+
+class AutoloadTest extends PHPUnit_Framework_TestCase {
+
+
+ public function testGetInstance(){
+ $instance = \PEIP\Autoload\Autoload::getInstance(true);
+ $this->assertSame($instance, \PEIP\Autoload\Autoload::getInstance());
+ $this->assertNotSame($instance, \PEIP\Autoload\Autoload::getInstance(true));
+ }
+
+ public function testAutoload(){
+ $class = 'PEIP\Message\GenericMessage';
+ $this->assertFalse(class_exists($class, false));
+ $autoload = \PEIP\Autoload\Autoload::getInstance();
+ $this->assertTrue($autoload->autoload($class));
+ $this->assertTrue(class_exists($class, false));
+ $this->assertFalse($autoload->autoload($class));
+ $this->assertFalse($autoload->autoload('FooBarFooBar'));
+
+ }
+
+}
+
View
50 tests/base/FlyAdapterTest.php
@@ -0,0 +1,50 @@
+<?php
+
+
+
+require_once dirname(__FILE__).'/../../misc/bootstrap.php';
+
+PHPUnit_Util_Fileloader::checkAndLoad(dirname(__FILE__).'/../_files/HelloService.php');
+
+/**
+ * Test class for FlyAdapter.
+ * Generated by PHPUnit on 2011-07-01 at 01:02:31.
+ */
+class FlyAdapterTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @var FlyAdapter
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp() {
+ $map = array(
+ 'foo' => 'greet',
+ 'bar' => 'getName'
+ );
+ $this->object = new HelloService;
+ $this->adapter = new \PEIP\Base\FlyAdapter($map);
+ }
+
+
+ public function testCall() {
+ $this->assertEquals(
+ $this->object->greet(),
+ $this->adapter->setSubject($this->object)->foo()
+ );
+ $this->assertEquals(
+ $this->object->getName(),
+ $this->adapter->setSubject($this->object)->bar()
+ );
+ $this->assertFalse(
+ $this->adapter->setSubject($this->object)->foobar()
+ );
+ }
+
+}
+
+

No commit comments for this range

Something went wrong with that request. Please try again.