maximebf / atomik

Micro framework for PHP 5.3+ [UNMAINTAINED]
MIT License
46 stars 18 forks source link

Shouldn't bootstrap be called after Atomik::Start ? #14

Closed zessx closed 11 years ago

zessx commented 11 years ago

Atomik.php:192

self::fireEvent('Atomik::Bootstrap');
if ($filename = self::path(self::get('atomik.files.bootstrap'))) {
    include $filename;
}

$cancel = false;
self::fireEvent('Atomik::Start', array(&$cancel));
if ($cancel) {
    self::end(true);
}

Calling bootstrap before Atomik::Start prevent us to act on sessions, or access to Atomik content. I saw (didn't remember where so...) it was originally called after Atomik::Start, what was the goal to revert the call order ?

An example, how can I manage my sessions if I can't access to Atomik content :

bootstrap.php

if(!Atomik::has('session.user')) {
    if(PAGE != 'connexion')
        Atomik::redirect(ROOT.'connexion');
} else {
    /* Create session using Atomik::set() */
}

Note : using Session.autostart => false doesn't look like a good alternative, as it rise a few issues (like the lost of Flash messages). I maybe doesn't use it in the right way.

maximebf commented 11 years ago

You're looking for "pre_dispatch.php" which will be called before dispatching the action. It is a much better place for the snippet you provided.

the goal of bootstrap.php is to do some things before the framework starts.

zessx commented 11 years ago

Exactly what I was looking for. I made a first unsuccessful try with pre_dispatch and post_dispatch, and totally forgot about those files later. This allows me to manage sessions, thanks !