public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new testBaseInitClass(); ezcBaseInit::fetchConfig('testBaseInit', self::$instance); } return self::$instance; }
/** * Returns the instance of the ezcSignalStaticConnections.. * * @return ezcConfigurationManager */ public static function getInstance() { if (self::$instance === null) { self::$instance = new ezcSignalStaticConnections(); ezcBaseInit::fetchConfig('ezcInitSignalStaticConnections', self::$instance); } return self::$instance; }
public static function getInstance() { if (self::$instance === null) { self::$instance = new customSingleton(); ezcBaseInit::fetchConfig('customKey', self::$instance); } return self::$instance; }
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); }
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()); } }
/** * Returns the persistent session instance named $identifier. * * If $identifier is ommited the default persistent session * specified by chooseDefault() is returned. * * @throws ezcPersistentSessionNotFoundException if the specified instance is not found. * @param string $identifier * @return ezcPersistentSession */ public static function get($identifier = null) { if ($identifier === null && self::$defaultInstanceIdentifier) { $identifier = self::$defaultInstanceIdentifier; } if (!isset(self::$instances[$identifier])) { // The ezcInitPersistentSessionInstance callback should return an // ezcPersistentSession object which will then be set as instance. $ret = ezcBaseInit::fetchConfig('ymcJobQueueInstance', $identifier); if ($ret === null) { throw new Exception('Did not find queue instance ' . $identifier); } else { self::set($ret, $identifier); } } return self::$instances[$identifier]; }
public function testDelayedInit() { ezcBaseInit::setCallback('ezcInitConfigurationManager', 'testDelayedInitConfigurationManager'); $cfg = ezcConfigurationManager::getInstance(); $this->assertAttributeEquals('ezcConfigurationIniReader', 'readerClass', $cfg); }
/** * Returns the ezcCacheStorage object with the given ID. * The cache ID has to be defined before using the * {@link ezcCacheManager::createCache()} method. If no instance of this * cache does exist yet, it's created on the fly. If one exists, it will * be reused. * * @param string $id The ID of the cache to return. * @return ezcCacheStorage The cache with the given ID. * * @throws ezcCacheInvalidIdException * If the ID of a cache you try to access does not exist. To access * a cache using this method, it first hast to be created using * {@link ezcCacheManager::createCache()}. * @throws ezcBaseFileNotFoundException * If the storage location does not exist. This should usually not * happen, since {@link ezcCacheManager::createCache()} already * performs sanity checks for the cache location. In case this * exception is thrown, your cache location has been corrupted * after the cache was configured. * @throws ezcBaseFileNotFoundException * If the storage location is not a directory. This should usually * not happen, since {@link ezcCacheManager::createCache()} already * performs sanity checks for the cache location. In case this * exception is thrown, your cache location has been corrupted * after the cache was configured. * @throws ezcBaseFilePermissionException * If the storage location is not writeable. This should usually not * happen, since {@link ezcCacheManager::createCache()} already * performs sanity checks for the cache location. In case this * exception is thrown, your cache location has been corrupted * after the cache was configured. * @throws ezcBasePropertyNotFoundException * If you tried to set a non-existent option value. The accepted * options depend on the ezcCacheStorage implementation and may * vary. */ public static function getCache($id) { // Look for already existing cache object if (!isset(self::$caches[$id])) { // Failed, look for configuration, and if it does not exist, use // delayed initialization. if (!isset(self::$configurations[$id])) { ezcBaseInit::fetchConfig('ezcInitCacheManager', $id); } // Check whether delayed initialization actually worked, if not, // throw an exception if (!isset(self::$configurations[$id])) { throw new ezcCacheInvalidIdException($id); } $class = self::$configurations[$id]['class']; self::$caches[$id] = new $class(self::$configurations[$id]['location'], self::$configurations[$id]['options']); } return self::$caches[$id]; }
public function testDelayedInit1() { ezcBaseInit::setCallback('ezcInitDatabaseInstance', 'testDelayedInitDatabaseInstance'); $instance1 = ezcDbInstance::get('delayed1'); }
/** * Returns the instance of the class ezcConfigurationManager. * * @return ezcConfigurationManager */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new ezcConfigurationManager(); ezcBaseInit::fetchConfig('ezcInitConfigurationManager', self::$instance); } return self::$instance; }
public function testDelayedInit() { ezcBaseInit::setCallback('ezcInitDebug', 'testDelayedInitDebug'); $dbg = ezcDebug::getInstance(); $this->assertAttributeEquals(new TestReporter(), 'formatter', $dbg); }
public function testDelayedInit() { ezcBaseInit::setCallback('ezcUrlConfiguration', 'testDelayedInitUrlConfiguration'); $urlCfg = ezcUrlConfiguration::getInstance(); $this->assertEquals(array('section' => 0), $urlCfg->orderedParameters); $this->assertEquals(array('article' => 1), $urlCfg->unorderedParameters); }
<?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');
/** * Returns the database instance $identifier. * * If $identifier is ommited the default database instance * specified by chooseDefault() is returned. * * @throws ezcDbHandlerNotFoundException if the specified instance is not found. * @param string $identifier * @return ezcDbHandler */ public static function get($identifier = false) { if ($identifier === false && self::$DefaultInstanceIdentifier) { $identifier = self::$DefaultInstanceIdentifier; } if (!isset(self::$Instances[$identifier])) { // The DatabaseInstanceFetchConfig callback should return an // ezcDbHandler object which will then be set as instance. $ret = ezcBaseInit::fetchConfig('ezcInitDatabaseInstance', $identifier); if ($ret === null) { throw new ezcDbHandlerNotFoundException($identifier); } else { self::set($ret, $identifier); } } return self::$Instances[$identifier]; }
/** * Returns the unique configuration instance named $name. * * Note: You only need to specify the name if you need multiple configuration * objects. * * @param string $name Name of the configuration to use. * @return ezcTemplateConfiguration */ public static function getInstance($name = "default") { if (!isset(self::$instanceList[$name])) { self::$instanceList[$name] = new ezcTemplateConfiguration(); ezcBaseInit::fetchConfig('ezcInitTemplateConfiguration', self::$instanceList[$name]); } return self::$instanceList[$name]; }
public function testGetCacheDelayedInit2() { testDelayedInitCacheManager::$tmpDir = $this->createTempDir(__CLASS__); ezcBaseInit::setCallback('ezcInitCacheManager', 'testDelayedInitCacheManager'); $cache = ezcCacheManager::getCache('simple'); self::assertSame('.cache', $cache->options->extension); }
/** * Returns the value of the property $name. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @ignore */ public function __get($name) { switch ($name) { case 'locale': return $this->properties[$name]; case 'manager': if ($this->properties[$name] === null) { ezcBaseInit::fetchConfig('ezcInitTemplateTranslationManager', $this); } if ($this->properties[$name] === null) { throw new ezcTemplateTranslationManagerNotConfiguredException(); } return $this->properties[$name]; } throw new ezcBasePropertyNotFoundException($name); }
<?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' ); ?>
<?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');
<?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");
// @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' ); ?>
<?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');
<?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());
public function testDelayedInit1() { ezcBaseInit::setCallback('ezcInitPersistentSessionInstance', 'testDelayedInitPersistentSessionInstance'); $instance1 = ezcPersistentSessionInstance::get('delayed1'); }
<?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);
<?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');
/** * Returns the instance of this class. * * When the ezcDebug instance is created it is automatically added to the instance * of ezcLog. * * @return ezcDebug */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new ezcDebug(); ezcBaseInit::fetchConfig('ezcInitDebug', self::$instance); } return self::$instance; }
/** * Returns the instance of the class * * @param boolean $isCliMode * @return CjwNewsletterLog */ public static function getInstance($isCliMode = false) { try { if (is_null(self::$instance)) { self::$instance = new self($isCliMode); ezcBaseInit::fetchConfig('cjwNewsletterInitLog', self::$instance); } return self::$instance; } catch (ezcBaseFilePermissionException $e) { eZDebug::writeError($e->getMessage(), 'CjwNewsletterLog::getInstance()'); if ($isCliMode) { $output = new ezcConsoleOutput(); $output->formats->error->color = 'red'; $output->formats->error->style = array('bold'); $output->outputLine($e->getMessage(), 'error'); exit; } } }
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';
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')); }