Class \Scrivo\Context

Class that defines a Scrivo context.

Working with Scrivo data requires a number of resources to be present. Of course there should be a database connection to a Scrivo database and also an instance id that refers to the data if a scrivo instance in the database (a Scrivo database can store data for multiple instances/websites).

Also a principal id is required. This principal id is used to determine the permissions for actions that are excecuted on behalf of the principal.

Then there is the configuration data: the entries in the ".htscrivo" file and the object id labels.

All this information is what we call the Scrivo context. Working with Scrivo data will almost always require you to setup a Scrivo context first. The parameters for the database connection and the instance id are mandatory entries in the Scrivo config file, a principal id will usually be retrieved from a session or is set progammatically. Thus configuration data and a principal id is all what is required to instantiate a Scrivo context.

$context = new \Scrivo\Context( new \Scrivo\Config(), \Scrivo\User::PRIMARY_ADMIN_ID); $homepage = new \Scrivo\Page($context, $context->labels->HOME);

Some other usage examples:

// Get the current (user) principal from the context. $currentUser = new \Scrivo\User($context, $context->principalId);

// Get a reference to the contexts PDO connection and instance id. $conn = $context->connection; $instId = $context->instanceId;

// Get the value of a configuration entry $wwwRoot = $context->config->WWW_ROOT;

// Get an object id by its label. $contactPageId = $context->labels->CONTACT;

// Check write permission on the page labelled contact. $context->checkPermission( \Scrivo\AccessController::WRITE_ACCESS, $context->labels->CONTACT);

Defined in: Context.php.


Constructor summary

Attr. Name / Description
public

Context($config, $user)

Construct a Scrivo context using a configuration file and a user id.

Properties

Attr. Type Name Description
read-only \..\LocalCache $cache The object cache.
read-only \..\Config $config A Config object holding this site's configuration data
read-only \..\PdoConnection $connection A PDO connection to a Scrivo database.
read-only \..\IdLabel $labels A IdLabel object that holding this sites id-label pairs.
read-only \..\User $principal The principal.

Member summary

Attr. Type Name Description
private \..\LocalCache $cache The object cache.
private \..\Config $config A Config object holding this site's configuration data
private \..\PdoConnection $conn A PDO connection to a Scrivo database.
private \..\IdLabel $idLabel A IdLabel object that holding this sites id-label pairs.
private \..\User $principal The principal.

Method summary

Attr. Type Name / Description
public mixed

__get($name)

Implementation of the readable properties using the PHP magic method __get().

public array

__sleep()

Prepare for serialization.

public

checkPermission($perm, $objectId)

Check a permission on an object using this Scrivo context.

 


Constructor

public Context(\Scrivo\Config $config, \Scrivo\User $user)

Construct a Scrivo context using a configuration file and a user id.

Parameters:

Type Name Def. Description
\Scrivo\Config $config

A Scrivo configuration object.

\Scrivo\User $user

A Scrivo user.


Members


				
private \Scrivo\LocalCache $cache

The object cache.

Inital value: null


				
private \Scrivo\Config $config

A Config object holding this site's configuration data

Inital value: null


				
private \Scrivo\PdoConnection $conn

A PDO connection to a Scrivo database.

Inital value: null


				
private \Scrivo\IdLabel $idLabel

A IdLabel object that holding this sites id-label pairs.

Inital value: null


				
private \Scrivo\User $principal

The principal.

Inital value: null


Methods

public mixed __get(string $name)

Implementation of the readable properties using the PHP magic method __get().

Parameters:

Type Name Def. Description
string $name

The name of the property to get.

Returns:

mixed Implementation of the readable properties using the PHP magic method __get().

public array __sleep()

Prepare for serialization.

Context data can never be stored in caches, so prevent this by returning an empty array when the context is serialized.

Returns:

array Prepare for serialization.

public checkPermission(int $perm, int $objectId=null)

Check a permission on an object using this Scrivo context.

Parameters:

Type Name Def. Description
int $perm

The permission to test (READ_ACCESS || WRITE_ACCESS || PUBLISH_ACCESS)

int $objectId null

A valid object id of a page or asset.

Throws:

Exception Type Description
\Scrivo\ApplicationException if no access was granted.

Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013