diff --git a/src/Phug/Partial/ExtensionsTrait.php b/src/Phug/Partial/ExtensionsTrait.php index 15f7aad7..ea89da78 100644 --- a/src/Phug/Partial/ExtensionsTrait.php +++ b/src/Phug/Partial/ExtensionsTrait.php @@ -2,6 +2,7 @@ namespace Phug\Partial; +use Phug\PhugException; use Phug\Renderer; use Phug\Util\ModuleInterface; @@ -108,4 +109,75 @@ public static function getExtensionsOptions(array $extensions, array $options = return $options; } + + /** + * Check if an extension is available globally. + * + * @param string $extensionClassName + * + * @return bool + */ + public static function hasExtension($extensionClassName) + { + return in_array( + self::normalizeExtensionClassName($extensionClassName), + array_map( + [self::class, 'normalizeExtensionClassName'], + self::$extensions + ) + ); + } + + /** + * Add an extension to the Phug facade (will be available in the current renderer instance and next static calls). + * Throws an exception if the extension is not a valid class name. + * + * @param string $extensionClassName + * + * @throws PhugException + */ + public static function addExtension($extensionClassName) + { + if (!class_exists($extensionClassName)) { + throw new PhugException( + 'Invalid '.$extensionClassName.' extension given: '. + 'it must be a class name.' + ); + } + + if (!static::hasExtension($extensionClassName)) { + self::$extensions[] = $extensionClassName; + + /* @var Renderer $renderer */ + if ($renderer = self::$renderer) { + $renderer->setOptionsRecursive(static::getOptions()); + } + } + } + + /** + * Remove an extension from the Phug facade (remove from current renderer instance). + * + * @param string $extensionClassName + */ + public static function removeExtension($extensionClassName) + { + if (static::hasExtension($extensionClassName)) { + if (self::$renderer) { + self::removeExtensionFromCurrentRenderer($extensionClassName); + } + + self::$extensions = array_diff(self::$extensions, [$extensionClassName]); + } + } + + /** + * Get extensions list added through the Phug facade. + * + * @return array + */ + public static function getExtensions() + { + return self::$extensions; + } } diff --git a/src/Phug/Phug.php b/src/Phug/Phug.php index 1a6df45d..d9edf64f 100644 --- a/src/Phug/Phug.php +++ b/src/Phug/Phug.php @@ -432,76 +432,6 @@ public static function getKeywords() return self::$keywords; } - /** - * Check if an extension is available globally. - * - * @param string $extensionClassName - * - * @return bool - */ - public static function hasExtension($extensionClassName) - { - return in_array( - self::normalizeExtensionClassName($extensionClassName), - array_map( - [self::class, 'normalizeExtensionClassName'], - self::$extensions - ) - ); - } - - /** - * Add an extension to the Phug facade (will be available in the current renderer instance and next static calls). - * Throws an exception if the extension is not a valid class name. - * - * @param string $extensionClassName - * - * @throws PhugException - */ - public static function addExtension($extensionClassName) - { - if (!class_exists($extensionClassName)) { - throw new PhugException( - 'Invalid '.$extensionClassName.' extension given: '. - 'it must be a class name.' - ); - } - - if (!static::hasExtension($extensionClassName)) { - self::$extensions[] = $extensionClassName; - - if (self::$renderer) { - self::$renderer->setOptionsRecursive(static::getOptions()); - } - } - } - - /** - * Remove an extension from the Phug facade (remove from current renderer instance). - * - * @param string $extensionClassName - */ - public static function removeExtension($extensionClassName) - { - if (static::hasExtension($extensionClassName)) { - if (self::$renderer) { - self::removeExtensionFromCurrentRenderer($extensionClassName); - } - - self::$extensions = array_diff(self::$extensions, [$extensionClassName]); - } - } - - /** - * Get extensions list added through the Phug facade. - * - * @return array - */ - public static function getExtensions() - { - return self::$extensions; - } - /** * Cache a whole directory and return an array with [$successCount, $errorCount, $errorDetails]. *