MDL-49329 admin: Introduce new \core\update\remote_info class
This is just a thin wrapper for normal objects, allowing us to have explicit type hinting / declarations in method signatures.
This commit is contained in:
@@ -90,7 +90,7 @@ class api {
|
||||
*
|
||||
* @param string $component frankenstyle name of the plugin
|
||||
* @param int $version plugin version as declared via $plugin->version in its version.php
|
||||
* @return stdClass|bool
|
||||
* @return \core\update\remote_info|bool
|
||||
*/
|
||||
public function get_plugin_info($component, $version) {
|
||||
|
||||
@@ -123,7 +123,7 @@ class api {
|
||||
* @param string $component frankenstyle name of the plugin
|
||||
* @param string|int $reqversion minimal required version of the plugin, defaults to ANY_VERSION
|
||||
* @param int $branch moodle core branch such as 29, 30, 31 etc, defaults to $CFG->branch
|
||||
* @return stdClass|bool false or data object
|
||||
* @return \core\update\remote_info|bool
|
||||
*/
|
||||
public function find_plugin($component, $reqversion=ANY_VERSION, $branch=null) {
|
||||
global $CFG;
|
||||
@@ -155,7 +155,7 @@ class api {
|
||||
* provided by the pluginfo.php version this client works with (self::APIVER).
|
||||
*
|
||||
* @param stdClass $data
|
||||
* @return stdClass|bool false if data are not valid, original data otherwise
|
||||
* @return \core\update\remote_info|bool false if data are not valid, original data otherwise
|
||||
*/
|
||||
public function validate_pluginfo_format($data) {
|
||||
|
||||
@@ -163,6 +163,8 @@ class api {
|
||||
return false;
|
||||
}
|
||||
|
||||
$output = new remote_info();
|
||||
|
||||
$rootproperties = array('id' => 1, 'name' => 1, 'component' => 1, 'source' => 0, 'doc' => 0,
|
||||
'bugs' => 0, 'discussion' => 0, 'version' => 0);
|
||||
foreach ($rootproperties as $property => $required) {
|
||||
@@ -172,6 +174,7 @@ class api {
|
||||
if ($required and empty($data->$property)) {
|
||||
return false;
|
||||
}
|
||||
$output->$property = $data->$property;
|
||||
}
|
||||
|
||||
if (!empty($data->version)) {
|
||||
@@ -208,14 +211,14 @@ class api {
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the pluginfo.php end-point with given parameters.
|
||||
*
|
||||
* @param array $params
|
||||
* @return stdClass|bool false or data object
|
||||
* @return \core\update\remote_info|bool
|
||||
*/
|
||||
protected function call_pluginfo_service(array $params) {
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Provides \core\update\remote_info class.
|
||||
*
|
||||
* @package core_plugin
|
||||
* @copyright 2015 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\update;
|
||||
use stdClass;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Thin wrapper for data structures returned by {@link api::get_plugin_info()}
|
||||
*
|
||||
* Given that the API client returns instances of this class instead of pure
|
||||
* objects allows us to have proper type hinting / declarations in method
|
||||
* signatures. The validation of the data structure is happening in the API
|
||||
* client so the rest of the code can simply rely on the class type.
|
||||
*
|
||||
* We extend the stdClass explicitly so that it can be eventually used in
|
||||
* methods signatures, too (not recommended).
|
||||
*
|
||||
* @copyright 2015 David Mudrak <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class remote_info extends stdClass {
|
||||
}
|
||||
Reference in New Issue
Block a user