Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
<?php

namespace PhpOffice\PhpSpreadsheet;

use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer;
use PhpOffice\PhpSpreadsheet\Collection\Memory;
> use Psr\Http\Client\ClientInterface; use Psr\SimpleCache\CacheInterface; > use Psr\Http\Message\RequestFactoryInterface;
class Settings { /** * Class name of the chart renderer used for rendering charts * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph. * * @var string */ private static $chartRenderer; /** * Default options for libxml loader. * * @var int */
< private static $libXmlLoaderOptions = null;
> private static $libXmlLoaderOptions;
/**
< * Allow/disallow libxml_disable_entity_loader() call when not thread safe. < * Default behaviour is to do the check, but if you're running PHP versions < * 7.2 < 7.2.1 < * 7.1 < 7.1.13 < * 7.0 < 7.0.27 < * then you may need to disable this check to prevent unwanted behaviour in other threads < * SECURITY WARNING: Changing this flag is not recommended.
> * The cache implementation to be used for cell collection.
*
< * @var bool
> * @var CacheInterface
*/
< private static $libXmlDisableEntityLoader = true;
> private static $cache;
/**
< * The cache implementation to be used for cell collection.
> * The HTTP client implementation to be used for network request.
*
< * @var CacheInterface
> * @var null|ClientInterface
*/
< private static $cache;
> private static $httpClient; > > /** > * @var null|RequestFactoryInterface > */ > private static $requestFactory;
/** * Set the locale code to use for formula translations and any special formatting. * * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") * * @return bool Success or failure */
< public static function setLocale($locale)
> public static function setLocale(string $locale)
{ return Calculation::getInstance()->setLocale($locale); }
> public static function getLocale(): string /** > { * Identify to PhpSpreadsheet the external library to use for rendering charts. > return Calculation::getInstance()->getLocale(); * > } * @param string $rendererClass Class name of the chart renderer >
< * @param string $rendererClass Class name of the chart renderer
> * @param string $rendererClassName Class name of the chart renderer
< * < * @throws Exception
*/
< public static function setChartRenderer($rendererClass)
> public static function setChartRenderer(string $rendererClassName): void
{
< if (!is_a($rendererClass, IRenderer::class, true)) {
> if (!is_a($rendererClassName, IRenderer::class, true)) {
throw new Exception('Chart renderer must implement ' . IRenderer::class); }
< self::$chartRenderer = $rendererClass;
> self::$chartRenderer = $rendererClassName;
} /** * Return the Chart Rendering Library that PhpSpreadsheet is currently configured to use. * * @return null|string Class name of the chart renderer * eg: PhpOffice\PhpSpreadsheet\Chart\Renderer\JpGraph */
< public static function getChartRenderer()
> public static function getChartRenderer(): ?string
{ return self::$chartRenderer; }
> public static function htmlEntityFlags(): int /** > { * Set default options for libxml loader. > return \ENT_COMPAT; * > } * @param int $options Default options for libxml loader >
*/
< public static function setLibXmlLoaderOptions($options)
> public static function setLibXmlLoaderOptions($options): void
{ if ($options === null && defined('LIBXML_DTDLOAD')) { $options = LIBXML_DTDLOAD | LIBXML_DTDATTR; } self::$libXmlLoaderOptions = $options; } /** * Get default options for libxml loader. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly. * * @return int Default options for libxml loader */
< public static function getLibXmlLoaderOptions()
> public static function getLibXmlLoaderOptions(): int
{ if (self::$libXmlLoaderOptions === null && defined('LIBXML_DTDLOAD')) { self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR); } elseif (self::$libXmlLoaderOptions === null) {
< self::$libXmlLoaderOptions = true;
> self::$libXmlLoaderOptions = 0;
} return self::$libXmlLoaderOptions; } /**
< * Enable/Disable the entity loader for libxml loader. < * Allow/disallow libxml_disable_entity_loader() call when not thread safe. < * Default behaviour is to do the check, but if you're running PHP versions < * 7.2 < 7.2.1 < * 7.1 < 7.1.13 < * 7.0 < 7.0.27 < * then you may need to disable this check to prevent unwanted behaviour in other threads < * SECURITY WARNING: Changing this flag to false is not recommended.
> * Deprecated, has no effect.
* * @param bool $state
> * */ > * @deprecated will be removed without replacement as it is no longer necessary on PHP 7.3.0+
< public static function setLibXmlDisableEntityLoader($state)
> public static function setLibXmlDisableEntityLoader($state): void
{
< self::$libXmlDisableEntityLoader = (bool) $state;
> // noop
} /**
< * Return the state of the entity loader (disabled/enabled) for libxml loader.
> * Deprecated, has no effect.
* * @return bool $state
> * */ > * @deprecated will be removed without replacement as it is no longer necessary on PHP 7.3.0+
< public static function getLibXmlDisableEntityLoader()
> public static function getLibXmlDisableEntityLoader(): bool
{
< return self::$libXmlDisableEntityLoader;
> return true;
} /** * Sets the implementation of cache that should be used for cell collection.
< * < * @param CacheInterface $cache
*/
< public static function setCache(CacheInterface $cache)
> public static function setCache(CacheInterface $cache): void
{ self::$cache = $cache; } /**
< * Gets the implementation of cache that should be used for cell collection. < * < * @return CacheInterface
> * Gets the implementation of cache that is being used for cell collection.
*/
< public static function getCache()
> public static function getCache(): CacheInterface
{ if (!self::$cache) { self::$cache = new Memory(); } return self::$cache;
> } } > } > /** > * Set the HTTP client implementation to be used for network request. > */ > public static function setHttpClient(ClientInterface $httpClient, RequestFactoryInterface $requestFactory): void > { > self::$httpClient = $httpClient; > self::$requestFactory = $requestFactory; > } > > /** > * Unset the HTTP client configuration. > */ > public static function unsetHttpClient(): void > { > self::$httpClient = null; > self::$requestFactory = null; > } > > /** > * Get the HTTP client implementation to be used for network request. > */ > public static function getHttpClient(): ClientInterface > { > self::assertHttpClient(); > > return self::$httpClient; > } > > /** > * Get the HTTP request factory. > */ > public static function getRequestFactory(): RequestFactoryInterface > { > self::assertHttpClient(); > > return self::$requestFactory; > } > > private static function assertHttpClient(): void > { > if (!self::$httpClient || !self::$requestFactory) { > throw new Exception('HTTP client must be configured via Settings::setHttpClient() to be able to use WEBSERVICE function.'); > }