Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 57... Línea 57...
57
    /** @var array list of redirected callbacks in PHPUnit tests */
57
    /** @var array list of redirected callbacks in PHPUnit tests */
58
    private $redirectedcallbacks = [];
58
    private $redirectedcallbacks = [];
Línea 59... Línea 59...
59
 
59
 
60
    /**
60
    /**
-
 
61
     * Constructor can be used only from factory methods.
-
 
62
     *
61
     * Constructor can be used only from factory methods.
63
     * @param bool $phpunit Whether this is a PHPUnit instantiated instance
62
     */
64
     */
-
 
65
    private function __construct(
-
 
66
        /** @var bool Whether this is a PHPUnit instantiated instance */
-
 
67
        private bool $phpunit = false,
63
    private function __construct() {
68
    ) {
Línea 64... Línea 69...
64
    }
69
    }
65
 
70
 
66
    /**
71
    /**
Línea 87... Línea 92...
87
     */
92
     */
88
    public static function phpunit_get_instance(array $componentfiles): manager {
93
    public static function phpunit_get_instance(array $componentfiles): manager {
89
        if (!PHPUNIT_TEST) {
94
        if (!PHPUNIT_TEST) {
90
            throw new \coding_exception('Invalid call of manager::phpunit_get_instance() outside of tests');
95
            throw new \coding_exception('Invalid call of manager::phpunit_get_instance() outside of tests');
91
        }
96
        }
92
        $instance = new self();
97
        $instance = new self(
-
 
98
            phpunit: true,
-
 
99
        );
93
        $instance->load_callbacks($componentfiles);
100
        $instance->load_callbacks($componentfiles);
94
        return $instance;
101
        return $instance;
95
    }
102
    }
Línea 96... Línea 103...
96
 
103
 
-
 
104
    /**
-
 
105
     * Whether to warn when an unmigrated legacy hook is found.
-
 
106
     *
-
 
107
     * @return bool
-
 
108
     */
-
 
109
    public function warn_on_unmigrated_legacy_hooks(): bool {
-
 
110
        if ($this->phpunit) {
-
 
111
            // This is an empty instance used in PHPUnit tests.
-
 
112
            // It does not know of any migrated hooks.
-
 
113
            return false;
-
 
114
        }
-
 
115
 
-
 
116
        return true;
-
 
117
    }
-
 
118
 
97
    /**
119
    /**
98
     * Override hook callbacks for testing purposes.
120
     * Override hook callbacks for testing purposes.
99
     *
121
     *
100
     * @param string $hookname
122
     * @param string $hookname
101
     * @param callable $callback
123
     * @param callable $callback
Línea 182... Línea 204...
182
        }
204
        }
183
        if (is_subclass_of($hookclassname, \core\hook\deprecated_callback_replacement::class)) {
205
        if (is_subclass_of($hookclassname, \core\hook\deprecated_callback_replacement::class)) {
184
            return $hookclassname::get_deprecated_plugin_callbacks();
206
            return $hookclassname::get_deprecated_plugin_callbacks();
185
        }
207
        }
Línea 186... Línea -...
186
 
-
 
187
        // Ensure that the replaces_callbacks attribute is loaded.
-
 
188
        // TODO MDL-81134 Remove after LTS+1.
-
 
189
        require_once(dirname(__DIR__) . '/attribute/hook/replaces_callbacks.php');
208
 
190
        if ($replaces = attribute_helper::instance($hookclassname, \core\attribute\hook\replaces_callbacks::class)) {
209
        if ($replaces = attribute_helper::instance($hookclassname, \core\attribute\hook\replaces_callbacks::class)) {
191
            return $replaces->callbacks;
210
            return $replaces->callbacks;
Línea 192... Línea 211...
192
        }
211
        }