本文整理汇总了PHP中normalize_component函数的典型用法代码示例。如果您正苦于以下问题:PHP normalize_component函数的具体用法?PHP normalize_component怎么用?PHP normalize_component使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_component函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Do not instantinate this directly, use {@link grading_manager::get_controller()}
*
* @param stdClass $context the context of the form
* @param string $component the frankenstyle name of the component
* @param string $area the name of the gradable area
* @param int $areaid the id of the gradable area record
*/
public function __construct(stdClass $context, $component, $area, $areaid)
{
global $DB;
$this->context = $context;
list($type, $name) = normalize_component($component);
$this->component = $type . '_' . $name;
$this->area = $area;
$this->areaid = $areaid;
$this->load_definition();
}
示例2: coursereport_engagement_get_plugin_info
function coursereport_engagement_get_plugin_info($manager, $component)
{
list($type, $name) = normalize_component($component);
$plugins = $manager->get_plugins();
if (isset($plugins[$type][$name])) {
return $plugins[$type][$name];
} else {
return null;
}
}
示例3: get_plugin_generator
/**
* Return generator for given plugin
* @param string $component
* @return mixed plugin data generator
*/
public function get_plugin_generator($component)
{
list($type, $plugin) = normalize_component($component);
if ($type !== 'mod' and $type !== 'block') {
throw new coding_exception("Plugin type {$type} does not support generators yet");
}
$dir = get_plugin_directory($type, $plugin);
if (!isset($this->generators[$type . '_' . $plugin])) {
$lib = "{$dir}/tests/generator/lib.php";
if (!(include_once $lib)) {
throw new coding_exception("Plugin {$component} does not support data generator, missing tests/generator/lib");
}
$classname = $type . '_' . $plugin . '_generator';
$this->generators[$type . '_' . $plugin] = new $classname($this);
}
return $this->generators[$type . '_' . $plugin];
}
示例4: definition
function definition()
{
$mform = $this->_form;
$current = $this->_customdata['current'];
$mform->addElement('header', 'filtersettings', get_string('filter', 'report_customlang'));
// Component
$options = array();
foreach (report_customlang_utils::list_components() as $component => $normalized) {
list($type, $plugin) = normalize_component($normalized);
if ($type == 'core' and is_null($plugin)) {
$plugin = 'moodle';
}
$options[$type][$normalized] = $component . '.php';
}
$mform->addElement('selectgroups', 'component', get_string('filtercomponent', 'report_customlang'), $options, array('multiple' => 'multiple', 'size' => 7));
// Customized only
$mform->addElement('advcheckbox', 'customized', get_string('filtercustomized', 'report_customlang'));
$mform->setType('customized', PARAM_BOOL);
$mform->setDefault('customized', 0);
// Only helps
$mform->addElement('advcheckbox', 'helps', get_string('filteronlyhelps', 'report_customlang'));
$mform->setType('helps', PARAM_BOOL);
$mform->setDefault('helps', 0);
// Modified only
$mform->addElement('advcheckbox', 'modified', get_string('filtermodified', 'report_customlang'));
$mform->setType('filtermodified', PARAM_BOOL);
$mform->setDefault('filtermodified', 0);
// Substring
$mform->addElement('text', 'substring', get_string('filtersubstring', 'report_customlang'));
$mform->setType('substring', PARAM_RAW);
// String identifier
$mform->addElement('text', 'stringid', get_string('filterstringid', 'report_customlang'));
$mform->setType('stringid', PARAM_STRINGID);
// Show strings - submit button
$mform->addElement('submit', 'submit', get_string('filtershowstrings', 'report_customlang'));
}
示例5: get_plugin_generator
/**
* Return generator for given plugin or component.
* @param string $component the component name, e.g. 'mod_forum' or 'core_question'.
* @return component_generator_base or rather an instance of the appropriate subclass.
*/
public function get_plugin_generator($component)
{
list($type, $plugin) = normalize_component($component);
$cleancomponent = $type . '_' . $plugin;
if ($cleancomponent != $component) {
debugging("Please specify the component you want a generator for as " . "{$cleancomponent}, not {$component}.", DEBUG_DEVELOPER);
$component = $cleancomponent;
}
if (isset($this->generators[$component])) {
return $this->generators[$component];
}
$dir = get_component_directory($component);
$lib = $dir . '/tests/generator/lib.php';
if (!$dir || !is_readable($lib)) {
throw new coding_exception("Component {$component} does not support " . "generators yet. Missing tests/generator/lib.php.");
}
include_once $lib;
$classname = $component . '_generator';
if (!class_exists($classname)) {
throw new coding_exception("Component {$component} does not support " . "data generators yet. Class {$classname} not found.");
}
$this->generators[$component] = new $classname($this);
return $this->generators[$component];
}
示例6: test_deprecated_normalize_component
public function test_deprecated_normalize_component()
{
// Moodle core.
$this->assertSame(array('core', null), normalize_component('core'));
$this->assertSame(array('core', null), normalize_component(''));
$this->assertSame(array('core', null), normalize_component('moodle'));
// Moodle core subsystems.
$this->assertSame(array('core', 'admin'), normalize_component('admin'));
$this->assertSame(array('core', 'admin'), normalize_component('core_admin'));
$this->assertSame(array('core', 'admin'), normalize_component('moodle_admin'));
// Activity modules and their subplugins.
$this->assertSame(array('mod', 'workshop'), normalize_component('workshop'));
$this->assertSame(array('mod', 'workshop'), normalize_component('mod_workshop'));
$this->assertSame(array('workshopform', 'accumulative'), normalize_component('workshopform_accumulative'));
$this->assertSame(array('mod', 'quiz'), normalize_component('quiz'));
$this->assertSame(array('quiz', 'grading'), normalize_component('quiz_grading'));
$this->assertSame(array('mod', 'data'), normalize_component('data'));
$this->assertSame(array('datafield', 'checkbox'), normalize_component('datafield_checkbox'));
// Other plugin types.
$this->assertSame(array('auth', 'mnet'), normalize_component('auth_mnet'));
$this->assertSame(array('enrol', 'self'), normalize_component('enrol_self'));
$this->assertSame(array('block', 'html'), normalize_component('block_html'));
$this->assertSame(array('block', 'mnet_hosts'), normalize_component('block_mnet_hosts'));
$this->assertSame(array('local', 'amos'), normalize_component('local_amos'));
$this->assertSame(array('local', 'admin'), normalize_component('local_admin'));
// Unknown words without underscore are supposed to be activity modules.
$this->assertSame(array('mod', 'whoonearthwouldcomewithsuchastupidnameofcomponent'), normalize_component('whoonearthwouldcomewithsuchastupidnameofcomponent'));
// Module names can not contain underscores, this must be a subplugin.
$this->assertSame(array('whoonearth', 'wouldcomewithsuchastupidnameofcomponent'), normalize_component('whoonearth_wouldcomewithsuchastupidnameofcomponent'));
$this->assertSame(array('whoonearth', 'would_come_withsuchastupidnameofcomponent'), normalize_component('whoonearth_would_come_withsuchastupidnameofcomponent'));
}
示例7: upgrade_log
/**
* Adds log entry into upgrade_log table
*
* @param int $type UPGRADE_LOG_NORMAL, UPGRADE_LOG_NOTICE or UPGRADE_LOG_ERROR
* @param string $plugin frankenstyle component name
* @param string $info short description text of log entry
* @param string $details long problem description
* @param string $backtrace string used for errors only
* @return void
*/
function upgrade_log($type, $plugin, $info, $details=null, $backtrace=null) {
global $DB, $USER, $CFG;
if (empty($plugin)) {
$plugin = 'core';
}
list($plugintype, $pluginname) = normalize_component($plugin);
$component = is_null($pluginname) ? $plugintype : $plugintype . '_' . $pluginname;
$backtrace = format_backtrace($backtrace, true);
$currentversion = null;
$targetversion = null;
//first try to find out current version number
if ($plugintype === 'core') {
//main
$currentversion = $CFG->version;
$version = null;
include("$CFG->dirroot/version.php");
$targetversion = $version;
} else if ($plugintype === 'mod') {
try {
$currentversion = $DB->get_field('modules', 'version', array('name'=>$pluginname));
$currentversion = ($currentversion === false) ? null : $currentversion;
} catch (Exception $ignored) {
}
$cd = get_component_directory($component);
if (file_exists("$cd/version.php")) {
$module = new stdClass();
$module->version = null;
include("$cd/version.php");
$targetversion = $module->version;
}
} else if ($plugintype === 'block') {
try {
if ($block = $DB->get_record('block', array('name'=>$pluginname))) {
$currentversion = $block->version;
}
} catch (Exception $ignored) {
}
$cd = get_component_directory($component);
if (file_exists("$cd/version.php")) {
$plugin = new stdClass();
$plugin->version = null;
include("$cd/version.php");
$targetversion = $plugin->version;
}
} else {
$pluginversion = get_config($component, 'version');
if (!empty($pluginversion)) {
$currentversion = $pluginversion;
}
$cd = get_component_directory($component);
if (file_exists("$cd/version.php")) {
$plugin = new stdClass();
$plugin->version = null;
include("$cd/version.php");
$targetversion = $plugin->version;
}
}
$log = new stdClass();
$log->type = $type;
$log->plugin = $component;
$log->version = $currentversion;
$log->targetversion = $targetversion;
$log->info = $info;
$log->details = $details;
$log->backtrace = $backtrace;
$log->userid = $USER->id;
$log->timemodified = time();
try {
$DB->insert_record('upgrade_log', $log);
} catch (Exception $ignored) {
// possible during install or 2.0 upgrade
}
}
示例8: validate_version_php
/**
* @return bool false if the version.php file does not declare required information
*/
protected function validate_version_php()
{
if (!isset($this->assertions['plugintype'])) {
throw new coding_exception('Required plugin type must be set before calling this');
}
if (!isset($this->assertions['moodleversion'])) {
throw new coding_exception('Required Moodle version must be set before calling this');
}
$fullpath = $this->extractdir . '/' . $this->rootdir . '/version.php';
if (!file_exists($fullpath)) {
// This is tolerated for themes only.
if ($this->assertions['plugintype'] === 'theme') {
$this->add_message(self::DEBUG, 'missingversionphp');
return true;
} else {
$this->add_message(self::ERROR, 'missingversionphp');
return false;
}
}
$this->versionphp = array();
$info = $this->parse_version_php($fullpath);
if ($this->assertions['plugintype'] === 'mod') {
$type = 'module';
} else {
$type = 'plugin';
}
if (!isset($info[$type . '->version'])) {
if ($type === 'module' and isset($info['plugin->version'])) {
// Expect the activity module using $plugin in version.php instead of $module.
$type = 'plugin';
$this->versionphp['version'] = $info[$type . '->version'];
$this->add_message(self::INFO, 'pluginversion', $this->versionphp['version']);
} else {
$this->add_message(self::ERROR, 'missingversion');
return false;
}
} else {
$this->versionphp['version'] = $info[$type . '->version'];
$this->add_message(self::INFO, 'pluginversion', $this->versionphp['version']);
}
if (isset($info[$type . '->requires'])) {
$this->versionphp['requires'] = $info[$type . '->requires'];
if ($this->versionphp['requires'] > $this->assertions['moodleversion']) {
$this->add_message(self::ERROR, 'requiresmoodle', $this->versionphp['requires']);
return false;
}
$this->add_message(self::INFO, 'requiresmoodle', $this->versionphp['requires']);
}
if (isset($info[$type . '->component'])) {
$this->versionphp['component'] = $info[$type . '->component'];
list($reqtype, $reqname) = normalize_component($this->versionphp['component']);
if ($reqtype !== $this->assertions['plugintype']) {
$this->add_message(self::ERROR, 'componentmismatchtype', array('expected' => $this->assertions['plugintype'], 'found' => $reqtype));
return false;
}
if ($reqname !== $this->rootdir) {
$this->add_message(self::ERROR, 'componentmismatchname', $reqname);
return false;
}
$this->add_message(self::INFO, 'componentmatch', $this->versionphp['component']);
}
if (isset($info[$type . '->maturity'])) {
$this->versionphp['maturity'] = $info[$type . '->maturity'];
if ($this->versionphp['maturity'] === 'MATURITY_STABLE') {
$this->add_message(self::INFO, 'maturity', $this->versionphp['maturity']);
} else {
$this->add_message(self::WARNING, 'maturity', $this->versionphp['maturity']);
}
}
if (isset($info[$type . '->release'])) {
$this->versionphp['release'] = $info[$type . '->release'];
$this->add_message(self::INFO, 'release', $this->versionphp['release']);
}
return true;
}
示例9: component_writable
/**
* Checks if the given component's directory is writable
*
* For the purpose of the deployment, the web server process has to have
* write access to all files in the component's directory (recursively) and for the
* directory itself.
*
* @see worker::move_directory_source_precheck()
* @param string $component normalized component name
* @return boolean
*/
protected function component_writable($component)
{
list($plugintype, $pluginname) = normalize_component($component);
$directory = get_plugin_directory($plugintype, $pluginname);
if (is_null($directory)) {
throw new coding_exception('Unknown component location', $component);
}
return $this->directory_writable($directory);
}
示例10: message_get_providers_for_user
/**
* Returns the active providers for the user specified, based on capability
*
* @param int $userid id of user
* @return array An array of message providers
*/
function message_get_providers_for_user($userid) {
global $DB, $CFG;
$systemcontext = context_system::instance();
$providers = get_message_providers();
// Remove all the providers we aren't allowed to see now
foreach ($providers as $providerid => $provider) {
if (!empty($provider->capability)) {
if (!has_capability($provider->capability, $systemcontext, $userid)) {
unset($providers[$providerid]); // Not allowed to see this
continue;
}
}
// Ensure user is not allowed to configure instantmessage if it is globally disabled.
if (!$CFG->messaging && $provider->name == 'instantmessage') {
unset($providers[$providerid]);
continue;
}
// If the component is an enrolment plugin, check it is enabled
list($type, $name) = normalize_component($provider->component);
if ($type == 'enrol') {
if (!enrol_is_enabled($name)) {
unset($providers[$providerid]);
continue;
}
}
}
return $providers;
}
示例11: plugin_name
/**
* Returns a localized name of a given plugin
*
* @param string $plugin name of the plugin, eg mod_workshop or auth_ldap
* @return string
*/
public function plugin_name($plugin)
{
list($type, $name) = normalize_component($plugin);
return $this->pluginsinfo[$type][$name]->displayname;
}
示例12: check_rating_is_valid
/**
* Validates a submitted rating
* @param array $params submitted data
* context => object the context in which the rated items exists [required]
* component => The component the rating belongs to [required]
* ratingarea => The ratingarea the rating is associated with [required]
* itemid => int the ID of the object being rated [required]
* scaleid => int the scale from which the user can select a rating. Used for bounds checking. [required]
* rating => int the submitted rating
* rateduserid => int the id of the user whose items have been rated. NOT the user who submitted the ratings. 0 to update all. [required]
* aggregation => int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [optional]
* @return boolean true if the rating is valid. False if callback wasnt found and will throw rating_exception if rating is invalid
*/
public function check_rating_is_valid($params)
{
if (!isset($params['context'])) {
throw new coding_exception('The context option is a required option when checking rating validity.');
}
if (!isset($params['component'])) {
throw new coding_exception('The component option is now a required option when checking rating validity');
}
if (!isset($params['ratingarea'])) {
throw new coding_exception('The ratingarea option is now a required option when checking rating validity');
}
if (!isset($params['itemid'])) {
throw new coding_exception('The itemid option is now a required option when checking rating validity');
}
if (!isset($params['scaleid'])) {
throw new coding_exception('The scaleid option is now a required option when checking rating validity');
}
if (!isset($params['rateduserid'])) {
throw new coding_exception('The rateduserid option is now a required option when checking rating validity');
}
list($plugintype, $pluginname) = normalize_component($params['component']);
//this looks for a function like forum_rating_validate() in mod_forum lib.php
//wrapping the params array in another array as call_user_func_array() expands arrays into multiple arguments
$isvalid = plugin_callback($plugintype, $pluginname, 'rating', 'validate', array($params), null);
//if null then the callback doesn't exist
if ($isvalid === null) {
$isvalid = false;
debugging('rating validation callback not found for component ' . clean_param($component, PARAM_ALPHANUMEXT));
}
return $isvalid;
}
示例13: require_login
try {
$autologinguest = true;
$setwantsurltome = true;
$preventredirect = true;
require_login($course, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} catch (Exception $e) {
if (isguestuser()) {
rss_error('rsserrorguest');
} else {
rss_error('rsserrorauth');
}
}
// Work out which component in Moodle we want (from the frankenstyle name)
$componentdir = get_component_directory($componentname);
list($type, $plugin) = normalize_component($componentname);
// Call the component to check/update the feed and tell us the path to the cached file
$pathname = null;
if (file_exists($componentdir)) {
require_once("$componentdir/rsslib.php");
$functionname = $plugin.'_rss_get_feed';
if (function_exists($functionname)) {
// $pathname will be null if there was a problem (eg user doesn't have the necessary capabilities)
// NOTE:the component providing the feed must do its own capability checks and security
$pathname = $functionname($context, $args);
}
}
示例14: set_component
/**
* Sets the component.
*
* This method shouldn't be public, changing the component once it has been set potentially
* invalidates permission checks.
* A coding_error is now thrown if code attempts to change the component.
*
* @param string $component
*/
public function set_component($component) {
if (!empty($this->component) && $this->component !== $component) {
throw new coding_exception('You cannot change the component of a comment once it has been set');
}
$this->component = $component;
list($this->plugintype, $this->pluginname) = normalize_component($component);
}
示例15: decode_remote_request
/**
* Decode the request from the Moodle Plugins directory
*
* @param string $request submitted via 'installaddonrequest' HTTP parameter
* @return stdClass|bool false on error, object otherwise
*/
protected function decode_remote_request($request)
{
$data = base64_decode($request, true);
if ($data === false) {
return false;
}
$data = json_decode($data);
if (is_null($data)) {
return false;
}
if (!isset($data->name) or !isset($data->component) or !isset($data->version)) {
return false;
}
$data->name = s(strip_tags($data->name));
if ($data->component !== clean_param($data->component, PARAM_COMPONENT)) {
return false;
}
list($plugintype, $pluginname) = normalize_component($data->component);
if ($plugintype === 'core') {
return false;
}
if ($data->component !== $plugintype . '_' . $pluginname) {
return false;
}
// Keep this regex in sync with the one used by the download.moodle.org/api/x.y/pluginfo.php
if (!preg_match('/^[0-9]+$/', $data->version)) {
return false;
}
return $data;
}