123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- declare(strict_types=1);
- /**
- * This file is part of the Carbon package.
- *
- * (c) Brian Nesbitt <brian@nesbot.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Tests\Laravel;
- use ArrayAccess;
- use Symfony\Component\Translation\Translator;
- class App implements ArrayAccess
- {
- /**
- * @var string
- */
- protected $locale = 'en';
- /**
- * @var string
- */
- protected static $version;
- /**
- * @var Translator
- */
- public $translator;
- /**
- * @var \Illuminate\Events\EventDispatcher
- */
- public $events;
- public function register()
- {
- include_once __DIR__.'/EventDispatcher.php';
- $this->locale = 'de';
- $this->translator = new Translator($this->locale);
- }
- public function setEventDispatcher($dispatcher)
- {
- $this->events = $dispatcher;
- }
- public static function version($version = null)
- {
- if ($version !== null) {
- static::$version = $version;
- }
- return static::$version;
- }
- public static function getLocaleChangeEventName()
- {
- return version_compare((string) static::version(), '5.5') >= 0
- ? 'Illuminate\Foundation\Events\LocaleUpdated'
- : 'locale.changed';
- }
- public function setLocaleWithoutEvent($locale)
- {
- $this->locale = $locale;
- $this->translator->setLocale($locale);
- }
- public function setLocale($locale)
- {
- $this->setLocaleWithoutEvent($locale);
- $this->events->dispatch(static::getLocaleChangeEventName());
- }
- public function getLocale()
- {
- return $this->locale;
- }
- public function bound($service)
- {
- return isset($this->{$service});
- }
- #[\ReturnTypeWillChange]
- public function offsetExists($offset)
- {
- return isset($this->$offset);
- }
- #[\ReturnTypeWillChange]
- public function offsetGet($offset)
- {
- return $this->$offset;
- }
- #[\ReturnTypeWillChange]
- public function offsetSet($offset, $value)
- {
- // noop
- }
- #[\ReturnTypeWillChange]
- public function offsetUnset($offset)
- {
- // noop
- }
- public function removeService($offset)
- {
- $this->$offset = null;
- }
- }
|