summaryrefslogtreecommitdiff
path: root/includes/bootstrap.inc
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2015-10-12 23:32:29 -0400
committerDavid Rothstein <drothstein@gmail.com>2015-10-12 23:32:29 -0400
commit183a425c551969d4f56b04766fca82819a2a7b15 (patch)
tree08a4a9651b71c031133e2c7b508bc908793d62c9 /includes/bootstrap.inc
parentf12effc70c835e77bfdea394214df9247533d319 (diff)
downloadbrdo-183a425c551969d4f56b04766fca82819a2a7b15.tar.gz
brdo-183a425c551969d4f56b04766fca82819a2a7b15.tar.bz2
Issue #2508055 by Dave Reid, David_Rothstein, hussainweb: Add support for autoloading Traits
Diffstat (limited to 'includes/bootstrap.inc')
-rw-r--r--includes/bootstrap.inc21
1 files changed, 20 insertions, 1 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 086cef0a9..70d426b4a 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -2468,6 +2468,9 @@ function _drupal_bootstrap_database() {
// the install or upgrade process.
spl_autoload_register('drupal_autoload_class');
spl_autoload_register('drupal_autoload_interface');
+ if (version_compare(PHP_VERSION, '5.4') >= 0) {
+ spl_autoload_register('drupal_autoload_trait');
+ }
}
/**
@@ -3112,6 +3115,22 @@ function drupal_autoload_class($class) {
}
/**
+ * Confirms that a trait is available.
+ *
+ * This function is rarely called directly. Instead, it is registered as an
+ * spl_autoload() handler, and PHP calls it for us when necessary.
+ *
+ * @param string $trait
+ * The name of the trait to check or load.
+ *
+ * @return bool
+ * TRUE if the trait is currently available, FALSE otherwise.
+ */
+function drupal_autoload_trait($trait) {
+ return _registry_check_code('trait', $trait);
+}
+
+/**
* Checks for a resource in the registry.
*
* @param $type
@@ -3129,7 +3148,7 @@ function drupal_autoload_class($class) {
function _registry_check_code($type, $name = NULL) {
static $lookup_cache, $cache_update_needed;
- if ($type == 'class' && class_exists($name) || $type == 'interface' && interface_exists($name)) {
+ if ($type == 'class' && class_exists($name) || $type == 'interface' && interface_exists($name) || $type == 'trait' && trait_exists($name)) {
return TRUE;
}