first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php
/**
* 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 Carbon\MessageFormatter;
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
if (!class_exists(LazyMessageFormatter::class, false)) {
abstract class LazyMessageFormatter implements MessageFormatterInterface
{
public function format(string $message, string $locale, array $parameters = []): string
{
return $this->formatter->format(
$message,
$this->transformLocale($locale),
$parameters
);
}
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* 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 Carbon\MessageFormatter;
use Symfony\Component\Translation\Formatter\ChoiceMessageFormatterInterface;
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;
if (!class_exists(LazyMessageFormatter::class, false)) {
abstract class LazyMessageFormatter implements MessageFormatterInterface, ChoiceMessageFormatterInterface
{
abstract protected function transformLocale(?string $locale): ?string;
public function format($message, $locale, array $parameters = [])
{
return $this->formatter->format(
$message,
$this->transformLocale($locale),
$parameters
);
}
public function choiceFormat($message, $number, $locale, array $parameters = [])
{
return $this->formatter->choiceFormat($message, $number, $locale, $parameters);
}
}
}

View File

@ -0,0 +1,36 @@
<?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 Carbon\PHPStan;
use PHPStan\BetterReflection\Reflection;
use ReflectionMethod;
if (!class_exists(AbstractReflectionMacro::class, false)) {
abstract class AbstractReflectionMacro extends AbstractMacro
{
/**
* {@inheritdoc}
*/
public function getReflection(): ?ReflectionMethod
{
if ($this->reflectionFunction instanceof Reflection\ReflectionMethod) {
return new Reflection\Adapter\ReflectionMethod($this->reflectionFunction);
}
return $this->reflectionFunction instanceof ReflectionMethod
? $this->reflectionFunction
: null;
}
}
}

View File

@ -0,0 +1,45 @@
<?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 Carbon\PHPStan;
use PHPStan\BetterReflection\Reflection;
use ReflectionMethod;
if (!class_exists(AbstractReflectionMacro::class, false)) {
abstract class AbstractReflectionMacro extends AbstractMacro
{
/**
* {@inheritdoc}
*/
public function getReflection(): ?Reflection\Adapter\ReflectionMethod
{
if ($this->reflectionFunction instanceof Reflection\Adapter\ReflectionMethod) {
return $this->reflectionFunction;
}
if ($this->reflectionFunction instanceof Reflection\ReflectionMethod) {
return new Reflection\Adapter\ReflectionMethod($this->reflectionFunction);
}
return $this->reflectionFunction instanceof ReflectionMethod
? new Reflection\Adapter\ReflectionMethod(
Reflection\ReflectionMethod::createFromName(
$this->reflectionFunction->getDeclaringClass()->getName(),
$this->reflectionFunction->getName()
)
)
: null;
}
}
}

View File

@ -0,0 +1,45 @@
<?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 Carbon\PHPStan;
if (!class_exists(LazyMacro::class, false)) {
abstract class LazyMacro extends AbstractReflectionMacro
{
/**
* {@inheritdoc}
*/
public function getFileName(): ?string
{
$file = $this->reflectionFunction->getFileName();
return (($file ? realpath($file) : null) ?: $file) ?: null;
}
/**
* {@inheritdoc}
*/
public function getStartLine(): ?int
{
return $this->reflectionFunction->getStartLine();
}
/**
* {@inheritdoc}
*/
public function getEndLine(): ?int
{
return $this->reflectionFunction->getEndLine();
}
}
}

View File

@ -0,0 +1,51 @@
<?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 Carbon\PHPStan;
if (!class_exists(LazyMacro::class, false)) {
abstract class LazyMacro extends AbstractReflectionMacro
{
/**
* {@inheritdoc}
*
* @return string|false
*/
public function getFileName()
{
$file = $this->reflectionFunction->getFileName();
return (($file ? realpath($file) : null) ?: $file) ?: null;
}
/**
* {@inheritdoc}
*
* @return int|false
*/
public function getStartLine()
{
return $this->reflectionFunction->getStartLine();
}
/**
* {@inheritdoc}
*
* @return int|false
*/
public function getEndLine()
{
return $this->reflectionFunction->getEndLine();
}
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* 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 Carbon;
use Symfony\Component\Translation\MessageCatalogueInterface;
if (!class_exists(LazyTranslator::class, false)) {
class LazyTranslator extends AbstractTranslator implements TranslatorStrongTypeInterface
{
public function trans(?string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string
{
return $this->translate($id, $parameters, $domain, $locale);
}
public function getFromCatalogue(MessageCatalogueInterface $catalogue, string $id, string $domain = 'messages')
{
$messages = $this->getPrivateProperty($catalogue, 'messages');
if (isset($messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id])) {
return $messages[$domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX][$id];
}
if (isset($messages[$domain][$id])) {
return $messages[$domain][$id];
}
$fallbackCatalogue = $this->getPrivateProperty($catalogue, 'fallbackCatalogue');
if ($fallbackCatalogue !== null) {
return $this->getFromCatalogue($fallbackCatalogue, $id, $domain);
}
return $id;
}
private function getPrivateProperty($instance, string $field)
{
return (function (string $field) {
return $this->$field;
})->call($instance, $field);
}
}
}

View File

@ -0,0 +1,32 @@
<?php
/**
* 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 Carbon;
if (!class_exists(LazyTranslator::class, false)) {
class LazyTranslator extends AbstractTranslator
{
/**
* Returns the translation.
*
* @param string|null $id
* @param array $parameters
* @param string|null $domain
* @param string|null $locale
*
* @return string
*/
public function trans($id, array $parameters = [], $domain = null, $locale = null)
{
return $this->translate($id, $parameters, $domain, $locale);
}
}
}