7.2. The Solar_User Object

In Solar, we rarely (if ever) address authentication, roles, and access control separately. Instead, we use a Solar_User object composed of Solar_Auth_Adapter, Solar_Role_Adapter, and Solar_Access_Adapter instances.

As such, we should start by keeping a Solar_User object in the registry so that we have the same user information available across the whole system. In the config file, we tell Solar to automatically register a Solar_User object called 'user' like so:

// SYSTEM/config.php
$config['Solar']['registry_set']['user'] = 'Solar_User';
// ...
return $config;

Now we can retrieve the registered 'user' object from anywhere in the Solar system:

$user = Solar_Registry::get('user');

At contruction time, Solar_User automatically creates an instance of each of the following adapters, using their respective configuration values from the config file, under each of the following properties:

  • $user->auth: a Solar_Auth_Adapter instance

  • $user->role: a Solar_Role_Adapter instance

  • $user->access: a Solar_Access_Adapter instance

This means you don't need to create, for example, an instance of Solar_Auth yourself. Instead, you get the registered Solar_User object and address its $auth property.

[Note] What About Configuration?

If Solar_User creates the adapter instances automatically, how can we configure those instances?

Because Solar uses a unified constructor, unified configuration, and a unified adapter mechanism, the instances will automatically pick up their configuration from the config file based on their class names, just like everything else in Solar.