forked from civicrm/civicrm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
\Civi - Add facade accessing system services
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters