Skip to content

Commit

Permalink
\Civi - Add facade accessing system services
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Sep 17, 2015
1 parent ba3ce4f commit 711aa5d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Civi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* Class Civi
*
* The "Civi" class provides a facade for accessing major subsystems,
* such as the service-container and settings manager. It serves as a
* bridge which allows procedural code to access important objects.
*
* General principles:
* - Each function provides access to a major subsystem.
* - Each function performs a simple lookup.
* - Each function returns an interface.
* - Whenever possible, interfaces should be well-known (e.g. based
* on a standard or well-regarded provider).
*/
class Civi {

/**
* A central location for static variable storage.
*
* @code
* `Civi::$statics[__CLASS__]['foo'] = 'bar';
* @endcode
*/
public static $statics = array();

/**
* Get the service container.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
public static function container() {
return Civi\Core\Container::singleton();
}

/**
* Fetch a service from the container.
*
* @param string $id
* The service ID.
* @return mixed
*/
public static function service($id) {
return \Civi\Core\Container::singleton()->get($id);
}

/**
* Reset all ephemeral system state, e.g. statics,
* singletons, containers.
*/
public static function reset() {
Civi\Core\Container::singleton(TRUE);
self::$statics = array();
}

}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"autoload": {
"psr-0": {
"PHPUnit_": ["packages/"],
"Civi": "",
"Civi\\": [".", "tests/phpunit/"]
}
},
Expand Down

0 comments on commit 711aa5d

Please sign in to comment.