PHP Version 5
Author: Marcelo Gornstein (marcelog@gmail.com)
Inheritance: implements Ding\Container\IContainer
Example #1
0
 /**
  * @test
  */
 public function can_return_cached_pointcut()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $aManager = $container->getBean('dingAspectManager');
     $p = $aManager->getPointcut('a');
     $this->assertEquals($p->getExpression(), 'b');
     $this->assertEquals($p->getMethod(), 'c');
 }
Example #2
0
 /**
  * @test
  */
 public function can_use_properties()
 {
     $this->_properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array('bdef' => array('yaml' => array('filename' => 'filter-xml-simple.yaml', 'directories' => array(RESOURCES_DIR))), 'properties' => array('a.b.value' => 'this is a value'))));
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aBean');
     $this->assertEquals($bean->constructor, 'this is a value');
     $this->assertEquals($bean->value, 'this is a value');
 }
 /**
  * @test
  */
 public function can_inject()
 {
     $properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array('properties' => array('aResource' => 'file://' . RESOURCES_DIR . DIRECTORY_SEPARATOR . 'someresource.txt'), 'bdef' => array('xml' => array('filename' => 'resource-autoload.xml', 'directories' => array(RESOURCES_DIR))))));
     $container = ContainerImpl::getInstance($properties);
     $bean = $container->getBean('aBean');
     $this->assertTrue($bean->resource1 instanceof IResource);
     $this->assertTrue($bean->resource2 instanceof IResource);
     $this->assertTrue($bean->resource3[0] instanceof IResource);
     $this->assertTrue($bean->resource4[0] instanceof IResource);
 }
Example #4
0
 /**
  * @test
  */
 public function can_resolve_with_slash_at_the_end()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $resolver = $container->getBean('HttpViewResolver2');
     $view = $resolver->resolve(new ModelAndView('name'));
     $ref = new ReflectionObject($view);
     $prop = $ref->getProperty('_path');
     $prop->setAccessible(true);
     $this->assertEquals($prop->getValue($view), './views/view.name.html');
     $this->assertTrue($view->getModelAndView() instanceof ModelAndView);
 }
Example #5
0
 /**
  * @test
  */
 public function can_trigger_events()
 {
     $container = \Ding\Container\Impl\ContainerImpl::getInstance($this->_properties);
     $container->eventListen('beanCreated', 'aBeanPragmaticallyListeningForEvents');
     $bean = $container->getBean('eventBean2');
     $this->assertTrue(EventBean::$eventDetected);
     $this->assertTrue(EventBean3::$eventDetected);
     $this->assertTrue(EventBean4::$eventDetected);
     $this->assertTrue(EventBean5::$eventDetected);
     $this->assertTrue(ParentThatListensForEvent::$eventDetected);
 }
Example #6
0
 /**
  * @test
  */
 public function can_be_lifecycle_aware()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aSimpleLifecycleAwareBean');
     $bean = $container->getBean('aSimpleLifecycleAwareBean2');
     $this->assertEquals($bean->something['bc'], 'yeah');
     $this->assertEquals($bean->something['ac'], 'yeah');
     $this->assertEquals($bean->something['aa'], 'yeah');
     $this->assertEquals($bean->something['ad'], 'yeah');
     $this->assertEquals($bean->something['ba'], 'yeah');
 }
Example #7
0
 /**
  * @test
  */
 public function can_use_properties_from_holder_string()
 {
     ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . RESOURCES_DIR);
     $this->_properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array('bdef' => array('xml' => array('filename' => 'filter-xml-simple-holder-string.xml', 'directories' => array(RESOURCES_DIR))), 'properties' => array('file' => 'filter.properties', 'a.b.value' => 'this is a value'))));
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aBean');
     $this->assertEquals($bean->constructor, 'indeedavaluethis is a value');
     $this->assertEquals($bean->value, 'indeedavaluethis is a value');
     $this->assertEquals($bean->constructorArray[0], 'indeedavaluethis is a value');
     $this->assertEquals($bean->valueArray[0], 'indeedavaluethis is a value');
     $this->assertEquals(ini_get('date.timezone'), 'Navajo');
 }
Example #8
0
 /**
  * @test
  */
 public function can_honor_default_values()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('methodIntercepted');
     $some = 'dsa';
     $result = $bean->anotherMethodWithDefaultValues(array(), $some, new DummyClass());
     $this->assertTrue(empty($result[0]));
     $this->assertEquals($result[1], 'dsa');
     $this->assertTrue($result[2] instanceof DummyClass);
     $this->assertTrue($result[3]);
     $this->assertFalse($result[4]);
     $this->assertNull($result[5]);
     $this->assertEquals($result[6], 'asd');
     $this->assertTrue(is_array($result[7]));
 }
Example #9
0
 /**
  * @test
  */
 public function can_use_syslog()
 {
     $properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array('bdef' => array('xml' => array('filename' => 'syslog.xml', 'directories' => array(RESOURCES_DIR))))));
     $container = ContainerImpl::getInstance($properties);
     $syslog = $container->getBean('syslog');
     $syslog->open();
     $syslog->emerg('some log');
     $syslog->alert('some log');
     $syslog->critical('some log');
     $syslog->error('some log');
     $syslog->warning('some log');
     $syslog->notice('some log');
     $syslog->info('some log');
     $syslog->debug('some log');
     $syslog->close();
 }
Example #10
0
 /**
  * @test
  */
 public function can_render_and_translate()
 {
     // For language stuff
     ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . RESOURCES_DIR);
     $this->expectOutputString('hi there');
     $mav = new ModelAndView('some');
     $mav->add(array('headers' => array('HTTP/1.0 404 Not Found')));
     $container = ContainerImpl::getInstance($this->_properties);
     $resolver = $container->getBean('HttpViewResolver3');
     $view = $resolver->resolve($mav);
     $render = $container->getBean('HttpViewRender');
     $render->render($view);
     $this->assertEquals($render->translate('abundle', 'message.some', array('arg1' => '1', 'arg2' => '2', 'arg3' => '3')), 'This is a test message, arg1=1 arg2=2 arg3=3');
     $session = HttpSession::getSession();
     $session->setAttribute('LANGUAGE', 'es_AR');
     $this->assertEquals($render->translate('abundle', 'message.some', array('arg1' => '1', 'arg2' => '2', 'arg3' => '3')), 'Este es un mensaje de prueba, arg1=1 arg2=2 arg3=3');
 }
Example #11
0
 /**
  * @test
  */
 public function can_do_nothing_if_no_handlers()
 {
     $properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array()));
     $container = ContainerImpl::getInstance($properties);
 }
Example #12
0
 /**
  * @test
  */
 public function can_remove()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $cache = CacheLocator::getProxyCacheInstance();
     $cache->remove('a');
 }
Example #13
0
 /**
  * @test
  */
 public function can_dispatch_multiple_with_annotations()
 {
     $properties = array('ding' => array('log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties', 'factory' => array('bdef' => array('annotation' => array('scanDir' => array(__DIR__)), 'xml' => array('filename' => 'mvc.xml', 'directories' => array(RESOURCES_DIR))))));
     $container = ContainerImpl::getInstance($properties);
     $dispatcher = $container->getBean('HttpDispatcher');
     $mapper = $container->getBean('HttpUrlMapper');
     $action = new HttpAction('/MyAnnotatedController1/something');
     $dispatchInfo = $mapper->map($action);
     $model = $dispatcher->dispatch($dispatchInfo);
     $this->assertTrue($model instanceof ModelAndView);
     $this->assertEquals($model->getName(), 'blah');
     $action = new HttpAction('/MyAnnotatedController2/something');
     $dispatchInfo = $mapper->map($action);
     $model = $dispatcher->dispatch($dispatchInfo);
     $this->assertTrue($model instanceof ModelAndView);
     $this->assertEquals($model->getName(), 'blah');
 }
Example #14
0
 /**
  * @test
  * @expectedException Ding\Bean\Factory\Exception\BeanFactoryException
  */
 public function cannot_create_with_cyclic_dependencies()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('cyclicDependency1');
 }
Example #15
0
 /**
  * @test
  */
 public function can_close_on_server_disconnect()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $server = $container->getBean('Server');
     $server->open();
     MyServerHandler::doClient($container->getBean('Client6'));
     $server->close();
     $this->assertEquals(MyClientHandler666::$data, "disconnect");
 }
Example #16
0
        $this->_a = $a;
        $this->_b = $b;
    }
}
/**
 * @Configuration
 */
class MyConfigClass
{
    /**
     * @Bean
     * @Value(name=a, value=${asd}/a)
     * @Value(name=b, value=${asd}/b)
     */
    public function myOtherBeanName($b, $a)
    {
        return new ABean($a, $b);
    }
}
require_once 'Ding/Autoloader/Autoloader.php';
// Include ding autoloader.
\Ding\Autoloader\Autoloader::register();
// Call autoloader register for ding autoloader.
use Ding\Container\Impl\ContainerImpl;
// Here you configure the container, its subcomponents, drivers, etc.
$properties = array('ding' => array('log4php.properties' => __DIR__ . '/../log4php.properties', 'factory' => array('bdef' => array('annotation' => array('scanDir' => array(realpath(__DIR__)))), 'properties' => array('asd' => 'myValue'))));
$container = ContainerImpl::getInstance($properties);
$bean = $container->getBean('myBeanName');
var_dump($bean);
$bean = $container->getBean('myOtherBeanName');
var_dump($bean);
Example #17
0
 /**
  * Handles the request. This will instantiate the container with the given
  * properties (via static method configure(), see below). Then it will
  * getBean(HttpDispatcher) and call dispatch() on it with an Action created
  * based on the request uri and method parameters (get, post, etc).
  *
  * @return void
  */
 public static function handle(array $properties = array(), $baseUrl = '/')
 {
     $exceptionThrown = null;
     $filtersPassed = true;
     $session = HttpSession::getSession();
     $container = ContainerImpl::getInstance($properties);
     self::$_logger = \Logger::getLogger(__CLASS__);
     $baseUrlLen = strlen($baseUrl);
     ob_start();
     $exceptionMapper = $render = $dispatcher = $viewResolver = false;
     $interceptors = array();
     try {
         $dispatcher = $container->getBean('HttpDispatcher');
         $viewResolver = $container->getBean('HttpViewResolver');
         $exceptionMapper = $container->getBean('HttpExceptionMapper');
         $render = $container->getBean('HttpViewRender');
         $method = strtolower($_SERVER['REQUEST_METHOD']);
         $url = $_SERVER['REQUEST_URI'];
         $urlStart = strpos($url, $baseUrl);
         self::$_logger->debug('Trying to match: ' . $url);
         if ($urlStart === false || $urlStart > 0) {
             throw new MvcException($url . ' is not a base url.');
         }
         $url = substr($url, $baseUrlLen);
         $variables = array();
         if (!empty($_GET)) {
             $variables = array_merge($variables, $_GET);
         }
         if (!empty($_POST)) {
             $variables = array_merge($variables, $_POST);
         }
         $action = new HttpAction($url, $variables);
         $action->setMethod($method);
         $mapper = $container->getBean('HttpUrlMapper');
         self::dispatch($dispatcher, $viewResolver, $action, $mapper, $render);
     } catch (\Exception $exception) {
         $exceptionThrown = $exception;
         self::$_logger->debug('Got Exception: ' . $exception);
         ob_end_clean();
         ob_start();
         if ($exceptionMapper === false) {
             header('HTTP/1.1 500 Error.');
         } else {
             $action = new HttpAction(get_class($exception), array('exception' => $exception));
             self::dispatch($dispatcher, $viewResolver, $action, $exceptionMapper, $render);
         }
     }
     ob_end_flush();
 }
 /**
  * @test
  */
 public function can_be_resource_loader_aware()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aSimpleResourceLoaderAwareBean');
     $this->assertTrue($bean->resourceLoader instanceof IResourceLoader);
 }
Example #19
0
require_once __DIR__ . '/../vendor/autoload.php';
use Doctrine\Common\Annotations\AnnotationReader;
use MetaPlayer\ErrorException;
use Doctrine\ORM\Tools\Setup;
use Ding\Container\Impl\ContainerImpl;
use Doctrine\Common\Annotations\AnnotationRegistry;
define('PROJECT_ROOT', realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR);
// TODO: refuse of it
require_once PROJECT_ROOT . '/config/app.config.php';
$config = (include PROJECT_ROOT . '/config/ding.config.php');
if (isset($config['ding']['log4php.properties'])) {
    \Logger::configure($config['ding']['log4php.properties']);
}
$logger = \Logger::getLogger("MetaPlayer.bootstrap");
$app = $logger->getAllAppenders();
$container = ContainerImpl::getInstance($config);
// force override error handler
set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
    throw new ErrorException("Unhandled Error: {$errstr}\n {$errfile} ({$errline}) [{$errno}]");
});
$logger->debug("container initialized");
$logger->trace("container initialized trace");
$checkContainer = $container->getBean("container");
if ($container != $checkContainer) {
    $logger->error("container was not successfully self registered");
}
$logger->debug("initialize doctrine");
$entityManager = $container->getBean("entityManager");
if (!isset($entityManager)) {
    $logger->error("entity manager was not successfully created");
}
Example #20
0
 /**
  * @test
  */
 public function can_timeout_on_starving_reading()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $server = $container->getBean('Server4');
     $server->open();
     MyServerHandler::doClient($container->getBean('Client'));
     while (strlen(MyServerHandler::$data) < 1) {
         usleep(1000);
     }
     $this->assertEquals(MyServerHandler::$data, "timeout");
     $server->close();
 }
Example #21
0
<?php

require_once __DIR__ . '/public/bootstrap.php';
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$container = \Ding\Container\Impl\ContainerImpl::getInstance($properties);
$em = $container->getBean('entityManager');
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)));
Example #22
0
 /**
  * @test
  */
 public function can_trigger_events_without_listeners()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $container->eventDispatch('inexistantEvent', 'blah');
 }
Example #23
0
// register Ding autoloader
require_once 'Ding/Autoloader/Autoloader.php';
// Include ding autoloader.
\Ding\Autoloader\Autoloader::register();
// Call autoloader register for ding autoloader.
// Uncomment these two lines if you want to try zend_cache instead of
// the default available cache backends. Also, modify one of the 'impl' options
// below to use it (see example below).
//require_once 'Zend/Loader/Autoloader.php';
//Zend_Loader_Autoloader::getInstance();
use Ding\Container\Impl\ContainerImpl;
use Doctrine\ORM\EntityManager;
try {
    $myProperties = array('doctrine.proxy.dir' => './proxies', 'doctrine.proxy.autogenerate' => true, 'doctrine.proxy.namespace' => "\\Test\\Proxies", 'doctrine.entity.path' => __DIR__ . "/entities", 'doctrine.db.driver' => "pdo_sqlite", 'doctrine.db.path' => __DIR__ . "/db.sqlite3", 'user.name' => 'nobody', 'log.dir' => '/tmp/alogdir', 'log.file' => 'alog.log', 'php.date.timezone' => 'America/Buenos_Aires');
    $dingProperties = array('ding' => array('log4php.properties' => __DIR__ . '/../log4php.properties', 'factory' => array('bdef' => array('xml' => array('filename' => 'beans.xml', 'directories' => array(__DIR__))), 'properties' => $myProperties), 'cache' => array('proxy' => array('impl' => 'dummy', 'directories' => '/tmp/Ding/proxy'), 'bdef' => array('impl' => 'dummy', 'directories' => '/tmp/Ding/bdef'), 'beans' => array('impl' => 'dummy'))));
    $a = ContainerImpl::getInstance($dingProperties);
    $em = $a->getBean('repository-locator');
    createSchema($myProperties);
    $person = new Person('foobar', 'Foo', 'Bar');
    echo "Persisting {$person}\n";
    $em->persist($person);
    $em->flush();
    $person = $em->find('Person', 1);
    echo "Retrieved from db:{$person}\n";
    @unlink($myProperties['doctrine.db.path']);
} catch (Exception $exception) {
    echo $exception . "\n";
}
function createSchema($props)
{
    $schema = file_get_contents(__DIR__ . '/schema.sql');
Example #24
0
 /**
  * @test
  */
 public function can_be_bean_name_aware()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aSimpleBeanNameAwareBean');
     $this->assertEquals($bean->name, 'aSimpleBeanNameAwareBean');
 }
 /**
  * @test
  */
 public function can_class_destroy_method()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aSimpleDestroyMethodClass');
     // XXX bad... unset() does not work because ContainerImpl is a singleton
     // and holds a reference to itself, so the destructor is never called.
     $container->__destruct();
     $this->assertNull($bean->something);
 }
Example #26
0
 /**
  * @test
  * @expectedException InvalidArgumentException
  */
 public function can_throw_exception_when_no_exception_interceptors()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('throwsUnaspectedException');
     $bean->thisWillThrowAnException();
 }
Example #27
0
 /**
  * @test
  */
 public function can_cache_property_name_for_setter_driver()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('aSimpleSetArgBean');
     $bean2 = $container->getBean('aSimpleSetArgBean2');
     $this->assertTrue($bean instanceof ClassSimpleXML3);
     $this->assertTrue($bean2 instanceof ClassSimpleXML12);
 }
Example #28
0
 /**
  * @test
  */
 public function can_resolve_unknown_message_with_arguments()
 {
     ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . RESOURCES_DIR);
     $container = ContainerImpl::getInstance($this->_properties);
     $this->assertFalse($container->getMessage('abundle', 'message.some2', array('1', '2', '3'), 'es_AR'));
 }
Example #29
0
 /**
  * @test
  */
 public function can_define_global_pointcuts()
 {
     $container = ContainerImpl::getInstance($this->_properties);
     $bean = $container->getBean('globalPointcut');
     $this->assertEquals($bean->getSomething('aSd'), 'BEFOREmethodReturnForaSdAFTER');
     $this->assertEquals($bean->getSomethingElse('aSd'), 'BEFOREmethodReturnForaSdAFTER');
 }
Example #30
0
 /**
  * @Bean(name=container)
  * @return \Ding\Container\IContainer
  */
 public function getContainer()
 {
     return ContainerImpl::getInstance();
 }