polyfony-inc/polyfony

Implement a read-only option for Sessions & Database

Opened this issue · 0 comments

Session

session_start(['read_and_close'=>true]);

Database

// try to connect
self::$_handle = new \PDO(
	$dsn, 
	self::$_config['username'] ?: null, 
	self::$_config['password'] ?: null,
	[\PDO::SQLITE_ATTR_OPEN_FLAGS => \PDO::SQLITE_OPEN_READONLY]
);

The main challenge is : where & when to define that we want to go read-only.
It should be defined as soon as possible. Ideally, it would be in the route, before the session has the chance to get initialized, and before any connection to the database occurs.

Router::get(
     '/xhr/status/:id/',
     'Bundle/Controller@xhr',
     'xhr-status'
)
     ->readOnlyDatabase()
     ->readOnlySession();
Session::setReadOnly();
Database::setReadOnly();