<?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( $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 ); ?>
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
repos | Folder | 0755 |
|
|
CREDITS | File | 229 B | 0644 |
|
LICENSE | File | 1.53 KB | 0644 |
|
tutorial.txt | File | 8.59 KB | 0644 |
|
tutorial_autoload.php | File | 495 B | 0644 |
|
tutorial_example_01.php | File | 215 B | 0644 |
|
tutorial_example_02.php | File | 189 B | 0644 |
|
tutorial_example_03.php | File | 107 B | 0644 |
|
tutorial_example_04.php | File | 1.39 KB | 0644 |
|
tutorial_lazy_initialization.php | File | 914 B | 0644 |
|