Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
Components (core subsystems + plugins) related code.
Copyright: | 2013 Petr Skoda {@link http://skodak.org} |
License: | http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
File Size: | 1454 lines (54 kb) |
Included or required: | 1 time |
Referenced: | 0 times |
Includes or requires: | 1 file version.php |
core_component:: (46 methods):
classloader()
psr_classloader()
get_class_file()
init()
is_developer()
get_cache_content()
fill_all_caches()
fetch_core_version()
fetch_subsystems()
fetch_apis()
fetch_plugintypes()
fetch_component_source()
fetch_subtypes()
fetch_plugins()
fill_classmap_cache()
fill_filemap_cache()
load_classes()
get_core_subsystems()
get_core_apis()
get_plugin_types()
get_plugin_list()
get_plugin_list_with_class()
get_plugin_list_with_file()
get_component_classes_in_namespace()
get_plugin_directory()
get_subsystem_directory()
is_valid_plugin_name()
normalize_componentname()
normalize_component()
get_component_directory()
get_plugin_types_with_subplugins()
get_subtype_parent()
get_subplugins()
get_all_versions_hash()
get_all_versions()
get_all_component_hash()
get_all_directory_hashes()
invalidate_opcode_php_cache()
is_core_subsystem()
is_core_api()
fill_classmap_renames_cache()
load_renamed_classes()
get_component_list()
get_component_names()
get_core_api_names()
has_monologo_icon()
Class: core_component - X-Ref
Collection of components related methods.classloader($classname) X-Ref |
Class loader for Frankenstyle named classes in standard locations. Frankenstyle namespaces are supported. The expected location for core classes is: 1/ core_xx_yy_zz ---> lib/classes/xx_yy_zz.php 2/ \core\xx_yy_zz ---> lib/classes/xx_yy_zz.php 3/ \core\xx\yy_zz ---> lib/classes/xx/yy_zz.php The expected location for plugin classes is: 1/ mod_name_xx_yy_zz ---> mod/name/classes/xx_yy_zz.php 2/ \mod_name\xx_yy_zz ---> mod/name/classes/xx_yy_zz.php 3/ \mod_name\xx\yy_zz ---> mod/name/classes/xx/yy_zz.php param: string $classname |
psr_classloader($class) X-Ref |
Return the path to a class from our defined PSR-0 or PSR-4 standard namespaces on demand. Only returns paths to files that exist. Adapated from http://www.php-fig.org/psr/psr-4/examples/ and made PSR-0 compatible. param: string $class the name of the class. return: string|bool The full path to the file defining the class. Or false if it could not be resolved or does not exist. |
get_class_file($class, $prefix, $path, $separators) X-Ref |
Return the path to the class based on the given namespace prefix and path it corresponds to. Will return the path even if the file does not exist. Check the file esists before requiring. param: string $class the name of the class. param: string $prefix The namespace prefix used to identify the base directory of the source files. param: string $path The relative path to the base directory of the source files. param: string[] $separators The characters that should be used for separating. return: string|bool The full path to the file defining the class. Or false if it could not be resolved. |
init() X-Ref |
Initialise caches, always call before accessing self:: caches. |
is_developer() X-Ref |
Are we in developer debug mode? Note: You need to set "$CFG->debug = (E_ALL | E_STRICT);" in config.php, the reason is we need to use this before we setup DB connection or caches for CFG. return: bool |
get_cache_content() X-Ref |
Create cache file content. return: string |
fill_all_caches() X-Ref |
Fill all caches. |
fetch_core_version() X-Ref |
Get the core version. In order for this to work properly, opcache should be reset beforehand. return: float core version. |
fetch_subsystems() X-Ref |
Returns list of core subsystems. return: array |
fetch_apis() X-Ref |
Returns list of core APIs. return: stdClass[] |
fetch_plugintypes() X-Ref |
Returns list of known plugin types. return: array |
fetch_component_source(string $key) X-Ref |
Returns the component source content as loaded from /lib/components.json. return: array |
fetch_subtypes($ownerdir) X-Ref |
Returns list of subtypes. param: string $ownerdir return: array |
fetch_plugins($plugintype, $fulldir) X-Ref |
Returns list of plugins of given type in given directory. param: string $plugintype param: string $fulldir return: array |
fill_classmap_cache() X-Ref |
Find all classes that can be autoloaded including frankenstyle namespaces. |
fill_filemap_cache() X-Ref |
Fills up the cache defining what plugins have certain files. return: void |
load_classes($component, $fulldir, $namespace = '') X-Ref |
Find classes in directory and recurse to subdirs. param: string $component param: string $fulldir param: string $namespace |
get_core_subsystems() X-Ref |
List all core subsystems and their location This is a list of components that are part of the core and their language strings are defined in /lang/en/<<subsystem>>.php. If a given plugin is not listed here and it does not have proper plugintype prefix, then it is considered as course activity module. The location is absolute file path to dir. NULL means there is no special directory for this subsystem. If the location is set, the subsystem's renderer.php is expected to be there. return: array of (string)name => (string|null)full dir location |
get_core_apis() X-Ref |
List all core APIs and their attributes. This is a list of all the existing / allowed APIs in moodle, each one with the following attributes: - component: the component, usually a subsystem or core, the API belongs to. - allowedlevel2: if the API is allowed as level2 namespace or no. - allowedspread: if the API can spread out from its component or no. return: stdClass[] array of APIs (as keys) with their attributes as object instances. |
get_plugin_types() X-Ref |
Get list of available plugin types together with their location. return: array as (string)plugintype => (string)fulldir |
get_plugin_list($plugintype) X-Ref |
Get list of plugins of given type. param: string $plugintype return: array as (string)pluginname => (string)fulldir |
get_plugin_list_with_class($plugintype, $class, $file = null) X-Ref |
Get a list of all the plugins of a given type that define a certain class in a certain file. The plugin component names and class names are returned. param: string $plugintype the type of plugin, e.g. 'mod' or 'report'. param: string $class the part of the name of the class after the param: string $file the name of file within the plugin that defines the class. return: array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum') |
get_plugin_list_with_file($plugintype, $file, $include = false) X-Ref |
Get a list of all the plugins of a given type that contain a particular file. param: string $plugintype the type of plugin, e.g. 'mod' or 'report'. param: string $file the name of file that must be present in the plugin. param: bool $include if true (default false), the file will be include_once-ed if found. return: array with plugin name as keys (e.g. 'forum', 'courselist') and the path |
get_component_classes_in_namespace($component = null, $namespace = '') X-Ref |
Returns all classes in a component matching the provided namespace. It checks that the class exists. e.g. get_component_classes_in_namespace('mod_forum', 'event') param: string|null $component A valid moodle component (frankenstyle) or null if searching all components param: string $namespace Namespace from the component name or empty string if all $component classes. return: array The full class name as key and the class path as value, empty array if $component is `null` |
get_plugin_directory($plugintype, $pluginname) X-Ref |
Returns the exact absolute path to plugin directory. param: string $plugintype type of plugin param: string $pluginname name of the plugin return: string full path to plugin directory; null if not found |
get_subsystem_directory($subsystem) X-Ref |
Returns the exact absolute path to plugin directory. param: string $subsystem type of core subsystem return: string full path to subsystem directory; null if not found |
is_valid_plugin_name($plugintype, $pluginname) X-Ref |
This method validates a plug name. It is much faster than calling clean_param. param: string $plugintype type of plugin param: string $pluginname a string that might be a plugin name. return: bool if this string is a valid plugin name. |
normalize_componentname($componentname) X-Ref |
Normalize the component name. Note: this does not verify the validity of the plugin or component. param: string $component return: string |
normalize_component($component) X-Ref |
Normalize the component name using the "frankenstyle" rules. Note: this does not verify the validity of plugin or type names. param: string $component return: array two-items list of [(string)type, (string|null)name] |
get_component_directory($component) X-Ref |
Return exact absolute path to a plugin directory. param: string $component name such as 'moodle', 'mod_forum' return: string full path to component directory; NULL if not found |
get_plugin_types_with_subplugins() X-Ref |
Returns list of plugin types that allow subplugins. return: array as (string)plugintype => (string)fulldir |
get_subtype_parent($type) X-Ref |
Returns parent of this subplugin type. param: string $type return: string parent component or null |
get_subplugins($component) X-Ref |
Return all subplugins of this component. param: string $component. return: array $subtype=>array($component, ..), null if no subtypes defined |
get_all_versions_hash() X-Ref |
Returns hash of all versions including core and all plugins. This is relatively slow and not fully cached, use with care! return: string sha1 hash |
get_all_versions() X-Ref |
Returns hash of all versions including core and all plugins. This is relatively slow and not fully cached, use with care! return: array as (string)plugintype_pluginname => (int)version |
get_all_component_hash(?array $components = null) X-Ref |
Returns hash of all core + plugin /db/ directories. This is relatively slow and not fully cached, use with care! param: array|null $components optional component directory => hash array to use. Only used in PHPUnit. return: string sha1 hash. |
get_all_directory_hashes(?array $directories = null) X-Ref |
Get the hashes of all core + plugin /db/ directories. param: array|null $directories optional component directory array to hash. Only used in PHPUnit. return: array of directory => hash. |
invalidate_opcode_php_cache($file) X-Ref |
Invalidate opcode cache for given file, this is intended for php files that are stored in dataroot. Note: we need it here because this class must be self-contained. param: string $file |
is_core_subsystem($subsystemname) X-Ref |
Return true if subsystemname is core subsystem. param: string $subsystemname name of the subsystem. return: bool true if core subsystem. |
is_core_api($apiname) X-Ref |
Return true if apiname is a core API. param: string $apiname name of the API. return: bool true if core API. |
fill_classmap_renames_cache() X-Ref |
Records all class renames that have been made to facilitate autoloading. |
load_renamed_classes(?string $fulldir) X-Ref |
Loads the db/renamedclasses.php file from the given directory. The renamedclasses.php should contain a key => value array ($renamedclasses) where the key is old class name, and the value is the new class name. It is only included when we are populating the component cache. After that is not needed. param: string|null $fulldir The directory to the renamed classes. |
get_component_list() X-Ref |
Returns a list of frankenstyle component names and their paths, for all components (plugins and subsystems). E.g. [ 'mod' => [ 'mod_forum' => FORUM_PLUGIN_PATH, ... ], ... 'core' => [ 'core_comment' => COMMENT_SUBSYSTEM_PATH, ... ] ] return: array an associative array of components and their corresponding paths. |
get_component_names() X-Ref |
Returns a list of frankenstyle component names. E.g. [ 'core_course', 'core_message', 'mod_assign', ... ] return: array the list of frankenstyle component names. |
get_core_api_names() X-Ref |
Returns the list of available API names. return: string[] the list of available API names. |
has_monologo_icon(string $plugintype, string $pluginname) X-Ref |
Checks for the presence of monologo icons within a plugin. Only checks monologo icons in PNG and SVG formats as they are formats that can have transparent background. param: string $plugintype The plugin type. param: string $pluginname The plugin name. return: bool True if the plugin has a monologo icon |