mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-57316 media: create different instances for different pages
This commit is contained in:
parent
1abd43763c
commit
63c102e095
@ -457,6 +457,23 @@ class core_medialib_testcase extends advanced_testcase {
|
||||
$this->assertContains('<source src="http://example.org/test.webm"', $t);
|
||||
$this->assertNotContains('<source src="http://example.org/test.flv"', $t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the instance() method returns singleton for the same page and different object for another page
|
||||
*/
|
||||
public function test_initialise() {
|
||||
$moodlepage1 = new moodle_page();
|
||||
|
||||
$mediamanager1 = core_media_manager::instance($moodlepage1);
|
||||
$mediamanager2 = core_media_manager::instance($moodlepage1);
|
||||
|
||||
$this->assertSame($mediamanager1, $mediamanager2);
|
||||
|
||||
$moodlepage3 = new moodle_page();
|
||||
$mediamanager3 = core_media_manager::instance($moodlepage3);
|
||||
|
||||
$this->assertNotSame($mediamanager1, $mediamanager3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -522,6 +539,7 @@ class core_media_manager_test extends core_media_manager {
|
||||
* Override the constructor to access it.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
global $PAGE;
|
||||
parent::__construct($PAGE);
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,9 @@ class core_media_manager {
|
||||
/** @var core_media_manager caches a singleton instance */
|
||||
static protected $instance;
|
||||
|
||||
/** @var moodle_page page this instance was initialised for */
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
* Returns a singleton instance of a manager
|
||||
*
|
||||
@ -105,7 +108,12 @@ class core_media_manager {
|
||||
* @return core_media_manager
|
||||
*/
|
||||
public static function instance($page = null) {
|
||||
if (self::$instance === null) {
|
||||
// Use the passed $page if given, otherwise the $PAGE global.
|
||||
if (!$page) {
|
||||
global $PAGE;
|
||||
$page = $PAGE;
|
||||
}
|
||||
if (self::$instance === null || ($page && self::$instance->page !== $page)) {
|
||||
self::$instance = new self($page);
|
||||
}
|
||||
return self::$instance;
|
||||
@ -117,15 +125,9 @@ class core_media_manager {
|
||||
* @param moodle_page $page The page we are going to add requirements to.
|
||||
* @see core_media_manager::instance()
|
||||
*/
|
||||
protected function __construct($page = null) {
|
||||
// Use the passed $page if given, otherwise the $PAGE global.
|
||||
if ($page == null) {
|
||||
global $PAGE;
|
||||
if (isset($PAGE)) {
|
||||
$page = $PAGE;
|
||||
}
|
||||
}
|
||||
protected function __construct($page) {
|
||||
if ($page) {
|
||||
$this->page = $page;
|
||||
$players = $this->get_players();
|
||||
foreach ($players as $player) {
|
||||
$player->setup($page);
|
||||
|
Loading…
x
Reference in New Issue
Block a user