Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ActiveRecord
  • Cache
  • Configs
  • Core
  • DateTime
  • Debug
  • DeleteOperation
  • Errors
  • Event
  • EventHook
  • Events
  • FileCache
  • FormattedString
  • Helpers
  • I18n
  • Image
  • Inflections
  • Inflector
  • Models
  • Module
  • Modules
  • Object
  • Operation
  • PingOperation
  • Prototype
  • Route
  • Routes
  • SaveOperation
  • Session
  • TimeZone
  • TimeZoneLocation
  • Uploaded
  • Vars
  • VarsIterator

Interfaces

  • StorageInterface
  • ToArray
  • ToArrayRecursive

Traits

  • PrototypeTrait
  • ToArrayRecursiveTrait

Exceptions

  • AlreadyAuthenticated
  • AuthenticationRequired
  • Exception
  • ModuleConstructorMissing
  • ModuleIsDisabled
  • ModuleNotDefined
  • OffsetError
  • OffsetNotDefined
  • OffsetNotReadable
  • OffsetNotWritable
  • PermissionRequired
  • PropertyError
  • PropertyIsReserved
  • PropertyNotDefined
  • PropertyNotReadable
  • PropertyNotWritable
  • RouteNotDefined
  • SecurityException

Constants

  • TOKEN_ALPHA
  • TOKEN_ALPHA_UPCASE
  • TOKEN_NUMERIC
  • TOKEN_SYMBOL
  • TOKEN_SYMBOL_WIDE

Functions

  • array_flatten
  • array_insert
  • array_merge_recursive
  • camelize
  • capitalize
  • downcase
  • dump
  • escape
  • escape_all
  • exact_array_merge_recursive
  • excerpt
  • format
  • generate_token
  • generate_token_wide
  • generate_v4_uuid
  • get_autoconfig
  • humanize
  • hyphenate
  • log
  • log_error
  • log_info
  • log_success
  • log_time
  • normalize
  • normalize_namespace_part
  • normalize_url_path
  • pbkdf2
  • pluralize
  • remove_accents
  • shorten
  • singularize
  • sort_by_weight
  • stable_sort
  • strip_root
  • titleize
  • unaccent_compare
  • unaccent_compare_ci
  • underscore
  • upcase
  1 <?php
  2 
  3 /*
  4  * This file is part of the ICanBoogie package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace ICanBoogie;
 13 
 14 /**
 15  * Core of the framework.
 16  *
 17  * @property \ICanBoogie\Configs $configs Configurations accessor.
 18  * @property \ICanBoogie\ActiveRecord\Connections $connections Database connections accessor.
 19  * @property \ICanBoogie\Models $models Models accessor.
 20  * @property \ICanBoogie\Modules $modules Modules accessor.
 21  * @property \ICanBoogie\Vars $vars Persistent variables accessor.
 22  * @property \ICanBoogie\Database $db Primary database connection.
 23  * @property \ICanBoogie\Session $session User's session.
 24  * @property string $language Locale language.
 25  * @property string|int $timezone Date and time timezone.
 26  * @property-read \ICanBoogie\I18n\Locale $locale Locale object matching the locale language.
 27  * @property array $config The "core" configuration.
 28  * @property-read \ICanBoogie\HTTP\Request $request The request being processed.
 29  * @property-read \ICanBoogie\Events $events Event collection.
 30  * @property-read \ICanBoogie\Routes $routes Route collection.
 31  */
 32 class Core extends Object
 33 {
 34     static private $instance;
 35 
 36     /**
 37      * Returns the unique instance of the core object.
 38      *
 39      * @return Core The core object.
 40      */
 41     static public function get()
 42     {
 43         return self::$instance;
 44     }
 45 
 46     /**
 47      * Whether the core is running or not.
 48      *
 49      * @var boolean
 50      */
 51     static public $is_running = false;
 52 
 53     /**
 54      * Echos the exception and kills PHP.
 55      *
 56      * @param \Exception $exception
 57      */
 58     static public function exception_handler(\Exception $exception)
 59     {
 60         Debug::exception_handler($exception);
 61     }
 62 
 63     /**
 64      * Constructor.
 65      *
 66      * @param array $options Initial options to create the core object.
 67      *
 68      * @throws \Exception when one tries to create a second instance.
 69      */
 70     public function __construct(array $options=[])
 71     {
 72         if (self::$instance)
 73         {
 74             throw new \Exception('Only one instance of the Core object can be created');
 75         }
 76 
 77         self::$instance = $this;
 78 
 79         if (php_sapi_name() !== 'cli')
 80         {
 81             $class = get_class($this);
 82 
 83             set_exception_handler($class . '::exception_handler');
 84             set_error_handler('ICanBoogie\Debug::error_handler');
 85         }
 86 
 87         if (!date_default_timezone_get())
 88         {
 89             date_default_timezone_set('UTC');
 90         }
 91 
 92         $this->configs = $configs = $this->create_config_manager($options['config-path'], $options['config-constructor']);
 93 
 94         $config = $this->config;
 95 
 96         $this->config['locale-path'] = $options['locale-path'];
 97         $this->config['module-path'] = $options['module-path'];
 98 
 99         #
100 
101         if (class_exists('ICanBoogie\I18n', true))
102         {
103             I18n::$load_paths = array_merge(I18n::$load_paths, $options['locale-path']);
104         }
105 
106         #
107         # Setting the cache repository to enable config caching.
108         #
109 
110         if ($config['cache configs'])
111         {
112             $configs->cache_repository = $config['repository.cache'] . '/core';
113         }
114     }
115 
116     protected function create_config_manager($path_list, $constructors)
117     {
118         return new Configs($path_list, $constructors);
119     }
120 
121     /**
122      * Returns modules accessor.
123      *
124      * @return Modules The modules accessor.
125      */
126     protected function lazy_get_modules()
127     {
128         $config = $this->config;
129 
130         return new Modules($config['module-path'], $config['cache modules'] ? $this->vars : null);
131     }
132 
133     /**
134      * Returns models accessor.
135      *
136      * @return Models The models accessor.
137      */
138     protected function lazy_get_models()
139     {
140         return new Models($this->connections, [], $this->modules);
141     }
142 
143     /**
144      * Returns the non-volatile variables accessor.
145      *
146      * @return Vars The non-volatile variables accessor.
147      */
148     protected function lazy_get_vars()
149     {
150         return new Vars(REPOSITORY . 'vars' . DIRECTORY_SEPARATOR);
151     }
152 
153     /**
154      * Returns the _core_ configuration.
155      *
156      * @return array
157      */
158     protected function lazy_get_config()
159     {
160         $config = $this->configs['core'];
161 
162         return $config;
163     }
164 
165     /**
166      * Returns the dispatcher used to dispatch HTTP requests.
167      *
168      * @return HTTP\Dispatcher
169      */
170     protected function get_dispatcher()
171     {
172         return HTTP\get_dispatcher();
173     }
174 
175     /**
176      * Returns the initial request object.
177      *
178      * @return HTTP\Request
179      */
180     protected function lazy_get_initial_request()
181     {
182         return HTTP\Request::from($_SERVER);
183     }
184 
185     /**
186      * Returns the current request.
187      *
188      * @return HTTP\Request
189      */
190     protected function get_request()
191     {
192         return HTTP\Request::get_current_request() ?: $this->initial_request;
193     }
194 
195     /**
196      * Returns the locale language.
197      *
198      * @return string
199      */
200     protected function get_language()
201     {
202         return I18n\get_language();
203     }
204 
205     /**
206      * Sets the working locate.
207      *
208      * @param string $id Locale identifier.
209      */
210     protected function set_locale($id)
211     {
212         I18n\set_locale($id);
213     }
214 
215     /**
216      * Returns the working locale object.
217      *
218      * @return I18n\Locale
219      */
220     protected function get_locale()
221     {
222         return I18n\get_locale();
223     }
224 
225     /**
226      * @var string The working time zone.
227      */
228     private $timezone;
229 
230     /**
231      * Sets the working time zone.
232      *
233      * When the time zone is set the default time zone is also set with
234      * {@link date_default_timezone_set()}.
235      *
236      * @param \ICanBoogie\Timezone|string|int $timezone An instance of {@link TimeZone},
237      * the name of a timezone, or numeric equivalent e.g. 3600.
238      */
239     protected function set_timezone($timezone)
240     {
241         if (is_numeric($timezone))
242         {
243             $timezone = timezone_name_from_abbr(null, $timezone, 0);
244         }
245 
246         $this->timezone = TimeZone::from($timezone);
247 
248         date_default_timezone_set((string) $this->timezone);
249     }
250 
251     /**
252      * Returns the working time zone.
253      *
254      * If the time zone is not defined yet it defaults to the value of
255      * {@link date_default_timezone_get()} or "UTC".
256      *
257      * @return string
258      */
259     protected function get_timezone()
260     {
261         if (!$this->timezone)
262         {
263             $this->timezone = TimeZone::from(date_default_timezone_get() ?: 'UTC');
264         }
265 
266         return $this->timezone;
267     }
268 
269     /**
270      * Returns the route collection.
271      *
272      * @return \ICanBoogie\Routes
273      */
274     protected function get_routes()
275     {
276         return Routes::get();
277     }
278 
279     /**
280      * Launch the application.
281      */
282     public function __invoke()
283     {
284         self::$is_running = true;
285 
286         Debug::configure($this->configs['debug']);
287 
288         $this->run_modules();
289 
290         Prototype::configure($this->configs['prototypes']);
291 
292         Events::patch('get', function() { // TODO-20140310: deprecate
293 
294             return $this->events;
295 
296         });
297 
298         new Core\RunEvent($this, $this->initial_request);
299 
300         #
301         # Register the time at which the core was running.
302         #
303 
304         $_SERVER['ICANBOOGIE_READY_TIME_FLOAT'] = microtime(true);
305 
306         return $this->initial_request;
307     }
308 
309     /**
310      * Run the enabled modules.
311      *
312      * Before the modules are actually ran, their index is used to alter the I18n load paths, the
313      * config paths and the core's `classes aliases` config properties.
314      */
315     protected function run_modules()
316     {
317         $modules = $this->modules;
318         $index = $modules->index;
319 
320         if (class_exists('ICanBoogie\I18n', true))
321         {
322             I18n::$load_paths = array_merge(I18n::$load_paths, $modules->locale_paths);
323         }
324 
325         #
326         # add modules config paths to the configs path
327         #
328 
329         $modules_config_paths = $modules->config_paths;
330 
331         if ($modules_config_paths)
332         {
333             $this->configs->add($modules->config_paths, -10);
334         }
335     }
336 
337     /**
338      * Genreates a path with the specified parameters.
339      *
340      * @param strign|Route $pattern_or_route_id_or_route A pattern, a route identifier or a
341      * {@link Route} instance.
342      * @param string $params
343      * @param array $options
344      *
345      * @return string
346      */
347     public function generate_path($pattern_or_route_id_or_route, $params=null, array $options=[])
348     {
349         if ($pattern_or_route_id_or_route instanceof Route)
350         {
351             $path = $pattern_or_route_id_or_route->format($params);
352         }
353         else if (isset($this->routes[$pattern_or_route_id_or_route]))
354         {
355             $path = $this->routes[$pattern_or_route_id_or_route]->format($params);
356         }
357         else if (Route::is_pattern($pattern_or_route_id_or_route))
358         {
359             $path = Routing\Pattern::from($pattern_or_route_id_or_route)->format($params);
360         }
361         else
362         {
363             throw new \InvalidArgumentException("Invalid \$pattern_or_route_id_or_route.");
364         }
365 
366         return Routing\contextualize($path);
367     }
368 
369     public function generate_url($pattern_or_route_id_or_route, $params=null, array $options=[])
370     {
371         return $this->site->url . $this->generate_path($pattern_or_route_id_or_route, $params, $options);
372     }
373 }
374 
375 namespace ICanBoogie\Core;
376 
377 use ICanBoogie\HTTP\Request;
378 
379 /**
380  * Event class for the `ICanBoogie\Core::run:before` event.
381  */
382 class BeforeRunEvent extends \ICanBoogie\Event
383 {
384     /**
385      * The event is constructed with the type `run:before`.
386      *
387      * @param \ICanBoogie\Core $target
388      */
389     public function __construct(\ICanBoogie\Core $target)
390     {
391         parent::__construct($target, 'run:before');
392     }
393 }
394 
395 /**
396  * Event class for the `ICanBoogie\Core::run` event.
397  */
398 class RunEvent extends \ICanBoogie\Event
399 {
400     /**
401      * Initial request.
402      *
403      * @var Request
404      */
405     public $request;
406 
407     /**
408      * The event is constructed with the type `run`.
409      *
410      * @param \ICanBoogie\Core $target
411      */
412     public function __construct(\ICanBoogie\Core $target, Request $request)
413     {
414         $this->request = $request;
415 
416         parent::__construct($target, 'run');
417     }
418 }
419 
420 /*
421  * Possessions don't touch you in your heart.
422  * Possessions only tear you apart.
423  * Possessions cannot kiss you good night.
424  * Possessions will never hold you tight.
425  */
Autodoc API documentation generated by ApiGen 2.8.0