Exemple #1
0
 function test_setting_an_instance_and_getting_it_should_return_same_instance()
 {
     $bucket = new bucket_Container();
     $obj = new StdClass();
     $bucket->set($obj);
     $this->assertSame($bucket->get('StdClass'), $obj);
 }
Exemple #2
0
 function test_parent_scope_doesnt_see_child_state()
 {
     $factory = new TestFactory();
     $bucket = new bucket_Container($factory);
     $scope = $bucket->makeChildContainer();
     $o = $scope->get('NoDependencies');
     $this->assertFalse($o === $bucket->get('NoDependencies'));
 }
Exemple #3
0
        // Default to English
        $phrases = array('Hello' => 'Hello', 'Meatballs' => 'Meatballs');
        if ($context->language()->isoCode() == 'sv') {
            $phrases = array('Hello' => 'Bork, bork, bork!', 'Meatballs' => 'Swedish meatballs');
        }
        return new SimpleTranslator($phrases);
    }
}
class VIH_NotFoundComponent extends k_Component
{
    protected $template;
    function __construct(k_TemplateFactory $template)
    {
        $this->template = $template;
    }
    function dispatch()
    {
        $tpl = $this->template->create('404');
        $response = new k_HtmlResponse($tpl->render($this));
        $response->setStatus(404);
        return $response;
    }
}
$factory = new VIH_Factory();
$container = new bucket_Container($factory);
$mdb2 = $container->get('mdb2_driver_common');
if (realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) {
    $components = new k_InjectorAdapter($container, new VIH_Document());
    $components->setImplementation('k_DefaultPageNotFoundComponent', 'VIH_NotFoundComponent');
    k()->setComponentCreator($components)->setLanguageLoader(new MyLanguageLoader())->setTranslatorLoader(new SimpleTranslatorLoader())->run('VIH_Controller_Root')->out();
}
Exemple #4
0
    function __construct($phrases = array())
    {
        $this->phrases = $phrases;
    }
    function translate($phrase, k_Language $language = null)
    {
        return isset($this->phrases[$phrase]) ? $this->phrases[$phrase] : $phrase;
    }
}
class SimpleTranslatorLoader implements k_TranslatorLoader
{
    function load(k_Context $context)
    {
        // Default to English
        $phrases = array('Hello' => 'Hello', 'Meatballs' => 'Meatballs');
        if ($context->language()->isoCode() == 'sv') {
            $phrases = array('Hello' => 'Bork, bork, bork!', 'Meatballs' => 'Swedish meatballs');
        }
        return new SimpleTranslator($phrases);
    }
}
$factory = new VIH_Intranet_Factory();
$container = new bucket_Container($factory);
$db = $container->get('db_common');
$db = $container->get('mdb2_driver_common');
if (realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) {
    $components = new k_InjectorAdapter($container, new VIH_Intranet_Document());
    $components->setImplementation('k_DefaultNotAuthorizedComponent', 'NotAuthorizedComponent');
    $identity_loader = new k_SessionIdentityLoader();
    k()->setLanguageLoader(new MyLanguageLoader())->setTranslatorLoader(new SimpleTranslatorLoader())->setComponentCreator($components)->setIdentityLoader($identity_loader)->run('VIH_Intranet_Controller_Root')->out();
}