Exemplo n.º 1
0
 public function testCallback3()
 {
     try {
         ezcBaseInit::setCallback('testBaseInit', 'testBaseInitCallback');
         $this->fail("Expected exception not thrown.");
     } catch (ezcBaseInitCallbackConfiguredException $e) {
         $this->assertEquals("The 'testBaseInit' is already configured with callback class 'testBaseInitCallback'.", $e->getMessage());
     }
 }
Exemplo n.º 2
0
 public function testDelayedInit()
 {
     ezcBaseInit::setCallback('ezcInitLog', 'testDelayedInitLog');
     $log = ezcLog::getInstance();
     $rule = new ezcLogFilterRule(new ezcLogFilter(), $writer = new ezcLogUnixFileWriter('/'), true);
     $expected = new ezcLogFilterSet();
     $expected->appendRule($rule);
     $this->assertAttributeEquals($expected, 'writers', $log);
 }
<?php

require_once 'tutorial_autoload.php';
// Create a custom class implementing the singleton pattern
class customSingleton
{
    protected static $instance;
    public static function getInstance()
    {
        if (self::$instance === null) {
            self::$instance = new customSingleton();
            ezcBaseInit::fetchConfig('customKey', self::$instance);
        }
        return self::$instance;
    }
}
// Implement your configuration class
class customSingletonConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject(customSingleton $object)
    {
        echo "Configure customSingleton.\n";
        $object->value = 42;
    }
}
// Register for lazy initilization
ezcBaseInit::setCallback('customKey', 'customSingletonConfiguration');
// Configure on first initilization
$object = customSingleton::getInstance();
var_dump($object->value);
Exemplo n.º 4
0
<?php

$root = dirname(__FILE__);
ini_set('include_path', "/usr/share/php/ezc:{$root}");
require 'Base/ezc_bootstrap.php';
$options = new ezcBaseAutoloadOptions(array('debug' => true));
ezcBase::setOptions($options);
// Add the class repository containing our application's classes. We store
// those in the /lib directory and the classes have the "tcl" prefix.
ezcBase::addClassRepository($p = "{$root}/lib", null, 'tcl');
class customLazyCacheConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($id)
    {
        $options = array('ttl' => 1800);
        switch ($id) {
            case 'scrapers':
                ezcCacheManager::createCache('scrapers', '../cache/scrapers', 'ezcCacheStorageFilePlain', $options);
                break;
        }
    }
}
ezcBaseInit::setCallback('ezcInitCacheManager', 'customLazyCacheConfiguration');
Exemplo n.º 5
0
<?php

require_once 'tutorial_autoload.php';
class customLazyUrlConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($urlCfg)
    {
        // set the basedir and script values
        $urlCfg->basedir = 'mydir';
        $urlCfg->script = 'index.php';
        // define delimiters for unordered parameter names
        $urlCfg->unorderedDelimiters = array('(', ')');
        // define ordered parameters
        $urlCfg->addOrderedParameter('section');
        $urlCfg->addOrderedParameter('group');
        $urlCfg->addOrderedParameter('category');
        $urlCfg->addOrderedParameter('subcategory');
        // define unordered parameters
        $urlCfg->addUnorderedParameter('game');
    }
}
ezcBaseInit::setCallback('ezcUrlConfiguration', 'customLazyUrlConfiguration');
// Classes loaded and configured on first request
$url = new ezcUrl('http://www.example.com/mydir/index.php/groups/Games/Adventure/Adult/(game)/Larry/7', ezcUrlConfiguration::getInstance());
Exemplo n.º 6
0
 public function setUp($appPaths, $factory = null)
 {
     if (!is_null($factory)) {
         if (!is_object($factory) || !method_exists($factory, 'createAppConfiguration')) {
             trigger_error("\$factory argument, if specified, should be an object with method 'createAppConfiguration()'");
         }
     } else {
         $factory = new aiiAppConfigurationFactory();
     }
     foreach ($appPaths as $appPath) {
         // either try something else than the default app configuration
         // factory, either let the user subclass this
         $app = $factory->createAppConfiguration($appPath);
         $this->apps[$app->namespace] = $app;
     }
     ezcBaseInit::setCallback('ezcInitPersistentSessionInstance', 'aiiProjectPersistentObjectInitializer');
     ezcBaseInit::setCallback('ezcInitTemplateConfiguration', 'aiiProjectTemplateInitializer');
 }
<?php

require_once 'tutorial_autoload.php';
class customLazySignalConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($signal)
    {
        $signal->connect('default', 'signal', 'customFunction');
    }
}
ezcBaseInit::setCallback('ezcInitSignalStaticConnections', 'customLazySignalConfiguration');
function customFunction()
{
    echo "Custom function called with:\n", var_export(func_get_args(), true);
}
$signals = new ezcSignalCollection();
$signals->emit('signal', 42);
 public function testDelayedInit()
 {
     ezcBaseInit::setCallback('ezcInitConfigurationManager', 'testDelayedInitConfigurationManager');
     $cfg = ezcConfigurationManager::getInstance();
     $this->assertAttributeEquals('ezcConfigurationIniReader', 'readerClass', $cfg);
 }
Exemplo n.º 9
0
 public function testDelayedInit1()
 {
     ezcBaseInit::setCallback('ezcInitPersistentSessionInstance', 'testDelayedInitPersistentSessionInstance');
     $instance1 = ezcPersistentSessionInstance::get('delayed1');
 }
Exemplo n.º 10
0
<?php

require_once 'tutorial_autoload.php';
class customLazyTemplateConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($cfg)
    {
        $cfg->templatePath = "/usr/share/templates";
        $cfg->compilePath = "/tmp/compiled_templates";
        $cfg->context = new ezcTemplateXhtmlContext();
    }
}
ezcBaseInit::setCallback('ezcInitTemplateConfiguration', 'customLazyTemplateConfiguration');
$t = new ezcTemplate();
$t->process("hello_world.ezt");
Exemplo n.º 11
0
 public function testDelayedInit()
 {
     ezcBaseInit::setCallback('ezcUrlConfiguration', 'testDelayedInitUrlConfiguration');
     $urlCfg = ezcUrlConfiguration::getInstance();
     $this->assertEquals(array('section' => 0), $urlCfg->orderedParameters);
     $this->assertEquals(array('article' => 1), $urlCfg->unorderedParameters);
 }
Exemplo n.º 12
0
<?php

class erLhcoreClassLog implements ezcBaseConfigurationInitializer
{
    // to write to the log put a write statement in the code with the content to log
    //
    // Example: erLhcoreClassLog::write(print_r($_POST,true));
    // or: erLhcoreClassLog::write("Log entry");
    //
    // default log location is CACHE/DEFAULT.LOG since it is writable Change below.
    static function write($msg)
    {
        // Use log
        $log = ezcLog::getInstance();
        $log->log($msg, ezcLog::WARNING);
    }
    public static function configureObject($log)
    {
        $writeAll = new ezcLogUnixFileWriter("cache", "default.log");
        $log->getMapper()->appendRule(new ezcLogFilterRule(new ezcLogFilter(), $writeAll, true));
    }
}
ezcBaseInit::setCallback('ezcInitLog', 'erLhcoreClassLog');
<?php

require_once 'tutorial_autoload.php';
class customLazyDatabaseConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($instance)
    {
        switch ($instance) {
            case false:
                // Default instance
                return ezcDbFactory::create('mysql://*****:*****@host/database');
            case 'sqlite':
                return ezcDbFactory::create('sqlite://:memory:');
        }
    }
}
ezcBaseInit::setCallback('ezcInitDatabaseInstance', 'customLazyDatabaseConfiguration');
// Create and configure default mysql connection
$db = ezcDbInstance::get();
// Create and configure additional sqlite connection
$sb = ezcDbInstance::get('sqlite');
Exemplo n.º 14
0
 public function testDelayedInitialization()
 {
     ezcBaseInit::setCallback('ezcInitSignalStaticConnections', 'testDelayedInitSignalStaticConnections');
     ezcSignalStaticConnections::getInstance()->connect('TheDelayed', 'signal', 'two');
     $this->assertEquals(array(1000 => array('two', 'one')), ezcSignalStaticConnections::getInstance()->getConnections('TheDelayed', 'signal'));
 }
Exemplo n.º 15
0
 public function testDelayedInit()
 {
     ezcBaseInit::setCallback('ezcInitDebug', 'testDelayedInitDebug');
     $dbg = ezcDebug::getInstance();
     $this->assertAttributeEquals(new TestReporter(), 'formatter', $dbg);
 }
<?php

require_once 'tutorial_autoload.php';
class customLazyPersistentSessionConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($instance)
    {
        switch ($instance) {
            case null:
                // Default instance
                $session = new ezcPersistentSession(ezcDbInstance::get(), new ezcPersistentCodeManager('../persistent'));
                return $session;
            case 'second':
                $session = new ezcPersistentSession(ezcDbInstance::get(), new ezcPersistentCodeManager('../additionalPersistent'));
                return $session;
        }
    }
}
ezcBaseInit::setCallback('ezcInitPersistentSessionInstance', 'customLazyPersistentSessionConfiguration');
// Create and configure default persistent session
$db = ezcPersistentSessionInstance::get();
// Create and configure additional persistent session
$sb = ezcPersistentSessionInstance::get('second');
Exemplo n.º 17
0
 public function testDelayedInit1()
 {
     ezcBaseInit::setCallback('ezcInitDatabaseInstance', 'testDelayedInitDatabaseInstance');
     $instance1 = ezcDbInstance::get('delayed1');
 }
Exemplo n.º 18
0
<?php
/**
 * Tests configurationfile
 */
define( 'ROOT', getcwd() );
ini_set( 'include_path', "/usr/share/php/ezc:/usr/share/php" . ROOT );

require 'Base/ezc_bootstrap.php';

$options = new ezcBaseAutoloadOptions( array( 'debug' => true ) );
ezcBase::setOptions( $options );

// Add the class repository containing our application's classes. We store
// those in the /lib directory and the classes have the "tcl" prefix.
ezcBase::addClassRepository( ROOT . "/lib", ROOT . "/lib/autoload", 'mm' );

class mmLazySettingsConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject( $cfgManager )
    {
        $cfgManager->init( 'ezcConfigurationIniReader', ROOT . "/tests/config" );
    }
}

ezcBaseInit::setCallback(
    'ezcInitConfigurationManager',
    'mmLazySettingsConfiguration'
);

?>
Exemplo n.º 19
0
            // @TODO: Add a proper exception type here.
            throw new Exception( "Unknown / unmapped DB type '$dbType'" );
        }

        $dbType = $dbMapping[$dbType];

        $dsnHost = $dbHost . ( $dbPort != '' ? ":$dbPort" : '' );
        $dsnAuth = $dbUser . ( $dbPass != '' ? ":$dbPass" : '' );
        $dsn = "{$dbType}://{$dbUser}:{$dbPass}@{$dsnHost}/{$dbName}";

        return $dsn;
    }
}
ezcBaseInit::setCallback( 'ezcInitDatabaseInstance', 'ezpRestDbConfig' );

class ezpRestPoConfig implements ezcBaseConfigurationInitializer
{
    public static function configureObject( $instance )
    {
        return new ezcPersistentSession( ezcDbInstance::get(),
            new ezcPersistentMultiManager( array(
                new ezcPersistentCodeManager( 'kernel/private/rest/classes/po_maps/' ),
                new ezcPersistentCodeManager( 'kernel/private/oauth/classes/persistentobjects/' )
            ))
        );
    }
}
ezcBaseInit::setCallback( 'ezcInitPersistentSessionInstance', 'ezpRestPoConfig' );

?>
Exemplo n.º 20
0
 public function testGetCacheDelayedInit2()
 {
     testDelayedInitCacheManager::$tmpDir = $this->createTempDir(__CLASS__);
     ezcBaseInit::setCallback('ezcInitCacheManager', 'testDelayedInitCacheManager');
     $cache = ezcCacheManager::getCache('simple');
     self::assertSame('.cache', $cache->options->extension);
 }
Exemplo n.º 21
0
function __autoload($className)
{
    ezcBase::autoload($className);
}
ezcBase::addClassRepository(dirname(__FILE__) . '/', dirname(__FILE__) . '/lib/autoloads');
$input = new ezcConsoleInput();
$helpOption = $input->registerOption(new ezcConsoleOption('s', 'siteaccess', ezcConsoleInput::TYPE_STRING));
$cronjobPartOption = $input->registerOption(new ezcConsoleOption('c', 'cronjob', ezcConsoleInput::TYPE_STRING));
$cronjobPathOption = $input->registerOption(new ezcConsoleOption('p', 'path', ezcConsoleInput::TYPE_STRING));
$extensionPartOption = $input->registerOption(new ezcConsoleOption('e', 'extension', ezcConsoleInput::TYPE_STRING));
try {
    $input->process();
} catch (ezcConsoleOptionException $e) {
    die($e->getMessage());
}
ezcBaseInit::setCallback('ezcInitDatabaseInstance', 'erLhcoreClassLazyDatabaseConfiguration');
$instance = erLhcoreClassSystem::instance();
$instance->SiteAccess = $helpOption->value;
$instance->SiteDir = dirname(__FILE__) . '/';
$cfgSite = erConfigClassLhConfig::getInstance();
$defaultSiteAccess = $cfgSite->getSetting('site', 'default_site_access');
$optionsSiteAccess = $cfgSite->getSetting('site_access_options', $helpOption->value);
$instance->Language = $optionsSiteAccess['locale'];
$instance->ThemeSite = $optionsSiteAccess['theme'];
$instance->WWWDirLang = '/' . $helpOption->value;
// php cron.php -s site_admin -c cron/workflow
// php cron.php -s site_admin -e customstatus -c cron/customcron
if ($extensionPartOption->value) {
    include_once 'extension/' . $extensionPartOption->value . '/modules/lh' . $cronjobPartOption->value . '.php';
} else {
    include_once 'modules/lh' . $cronjobPartOption->value . '.php';
<?php

require_once 'tutorial_autoload.php';
class customLazyLogConfiguration implements ezcBaseConfigurationInitializer
{
    public static function configureObject($log)
    {
        $writeAll = new ezcLogUnixFileWriter("/tmp/logs", "general.log");
        $log->getMapper()->appendRule(new ezcLogFilterRule(new ezcLogFilter(), $writeAll, true));
    }
}
ezcBaseInit::setCallback('ezcInitLog', 'customLazyLogConfiguration');
// Use log
$log = ezcLog::getInstance();
$log->log("Paid with credit card.", ezcLog::SUCCESS_AUDIT, array("category" => "shop"));
$log->log("The credit card information is removed.", ezcLog::NOTICE, array("category" => "shop"));