default services conflit ?
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App\Controller;
|
||||
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
|
||||
final class PsrRequestController
|
||||
{
|
||||
private $responseFactory;
|
||||
private $streamFactory;
|
||||
|
||||
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
|
||||
{
|
||||
$this->responseFactory = $responseFactory;
|
||||
$this->streamFactory = $streamFactory;
|
||||
}
|
||||
|
||||
public function serverRequestAction(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->responseFactory
|
||||
->createResponse()
|
||||
->withBody($this->streamFactory->createStream(sprintf('<html><body>%s</body></html>', $request->getMethod())));
|
||||
}
|
||||
|
||||
public function requestAction(RequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->responseFactory
|
||||
->createResponse()
|
||||
->withStatus(403)
|
||||
->withBody($this->streamFactory->createStream(sprintf('<html><body>%s %s</body></html>', $request->getMethod(), $request->getBody()->getContents())));
|
||||
}
|
||||
|
||||
public function messageAction(MessageInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->responseFactory
|
||||
->createResponse()
|
||||
->withStatus(422)
|
||||
->withBody($this->streamFactory->createStream(sprintf('<html><body>%s</body></html>', $request->getHeader('X-My-Header')[0])));
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App;
|
||||
|
||||
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ServerRequestFactoryInterface;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileFactoryInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver\PsrServerRequestResolver;
|
||||
use Symfony\Bridge\PsrHttpMessage\EventListener\PsrResponseListener;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App\Controller\PsrRequestController;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
|
||||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
|
||||
|
||||
class Kernel extends SymfonyKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
yield new FrameworkBundle();
|
||||
}
|
||||
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
|
||||
protected function configureRoutes(RoutingConfigurator $routes): void
|
||||
{
|
||||
$routes
|
||||
->add('server_request', '/server-request')->controller([PsrRequestController::class, 'serverRequestAction'])->methods(['GET'])
|
||||
->add('request', '/request')->controller([PsrRequestController::class, 'requestAction'])->methods(['POST'])
|
||||
->add('message', '/message')->controller([PsrRequestController::class, 'messageAction'])->methods(['PUT'])
|
||||
;
|
||||
}
|
||||
|
||||
protected function configureContainer(ContainerConfigurator $container): void
|
||||
{
|
||||
$container->extension('framework', [
|
||||
'router' => ['utf8' => true],
|
||||
'secret' => 'for your eyes only',
|
||||
'test' => true,
|
||||
]);
|
||||
|
||||
$container->services()
|
||||
->set('nyholm.psr_factory', Psr17Factory::class)
|
||||
->alias(ResponseFactoryInterface::class, 'nyholm.psr_factory')
|
||||
->alias(ServerRequestFactoryInterface::class, 'nyholm.psr_factory')
|
||||
->alias(StreamFactoryInterface::class, 'nyholm.psr_factory')
|
||||
->alias(UploadedFileFactoryInterface::class, 'nyholm.psr_factory')
|
||||
;
|
||||
|
||||
$container->services()
|
||||
->defaults()->autowire()->autoconfigure()
|
||||
->set(HttpFoundationFactoryInterface::class, HttpFoundationFactory::class)
|
||||
->set(HttpMessageFactoryInterface::class, PsrHttpFactory::class)
|
||||
->set(PsrResponseListener::class)
|
||||
->set(PsrServerRequestResolver::class)
|
||||
;
|
||||
|
||||
$container->services()
|
||||
->set('logger', NullLogger::class)
|
||||
->set(PsrRequestController::class)->public()->autowire()
|
||||
;
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App;
|
||||
|
||||
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||
use Psr\Http\Message\ResponseFactoryInterface;
|
||||
use Psr\Http\Message\ServerRequestFactoryInterface;
|
||||
use Psr\Http\Message\StreamFactoryInterface;
|
||||
use Psr\Http\Message\UploadedFileFactoryInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver\PsrServerRequestResolver;
|
||||
use Symfony\Bridge\PsrHttpMessage\EventListener\PsrResponseListener;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\App\Controller\PsrRequestController;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\Kernel as SymfonyKernel;
|
||||
use Symfony\Component\Routing\RouteCollectionBuilder;
|
||||
|
||||
class Kernel44 extends SymfonyKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
|
||||
public function registerBundles(): iterable
|
||||
{
|
||||
yield new FrameworkBundle();
|
||||
}
|
||||
|
||||
public function getProjectDir(): string
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes): void
|
||||
{
|
||||
$routes->add('/server-request', PsrRequestController::class.'::serverRequestAction')->setMethods(['GET']);
|
||||
$routes->add('/request', PsrRequestController::class.'::requestAction')->setMethods(['POST']);
|
||||
$routes->add('/message', PsrRequestController::class.'::messageAction')->setMethods(['PUT']);
|
||||
}
|
||||
|
||||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
|
||||
{
|
||||
$container->loadFromExtension('framework', [
|
||||
'secret' => 'for your eyes only',
|
||||
'test' => true,
|
||||
]);
|
||||
|
||||
$container->register('nyholm.psr_factory', Psr17Factory::class);
|
||||
$container->setAlias(ResponseFactoryInterface::class, 'nyholm.psr_factory');
|
||||
$container->setAlias(ServerRequestFactoryInterface::class, 'nyholm.psr_factory');
|
||||
$container->setAlias(StreamFactoryInterface::class, 'nyholm.psr_factory');
|
||||
$container->setAlias(UploadedFileFactoryInterface::class, 'nyholm.psr_factory');
|
||||
|
||||
$container->register(HttpFoundationFactoryInterface::class, HttpFoundationFactory::class)->setAutowired(true)->setAutoconfigured(true);
|
||||
$container->register(HttpMessageFactoryInterface::class, PsrHttpFactory::class)->setAutowired(true)->setAutoconfigured(true);
|
||||
$container->register(PsrResponseListener::class)->setAutowired(true)->setAutoconfigured(true);
|
||||
$container->register(PsrServerRequestResolver::class)->setAutowired(true)->setAutoconfigured(true);
|
||||
|
||||
$container->register('logger', NullLogger::class);
|
||||
$container->register(PsrRequestController::class)->setPublic(true)->setAutowired(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Message.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class Message implements MessageInterface
|
||||
{
|
||||
private $version = '1.1';
|
||||
private $headers = [];
|
||||
private $body;
|
||||
|
||||
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null)
|
||||
{
|
||||
$this->version = $version;
|
||||
$this->headers = $headers;
|
||||
$this->body = $body ?? new Stream();
|
||||
}
|
||||
|
||||
public function getProtocolVersion(): string
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withProtocolVersion($version)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function hasHeader($name): bool
|
||||
{
|
||||
return isset($this->headers[$name]);
|
||||
}
|
||||
|
||||
public function getHeader($name): array
|
||||
{
|
||||
return $this->hasHeader($name) ? $this->headers[$name] : [];
|
||||
}
|
||||
|
||||
public function getHeaderLine($name): string
|
||||
{
|
||||
return $this->hasHeader($name) ? implode(',', $this->headers[$name]) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withHeader($name, $value)
|
||||
{
|
||||
$this->headers[$name] = (array) $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withAddedHeader($name, $value)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withoutHeader($name)
|
||||
{
|
||||
unset($this->headers[$name]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBody(): StreamInterface
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withBody(StreamInterface $body)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class Response extends Message implements ResponseInterface
|
||||
{
|
||||
private $statusCode;
|
||||
|
||||
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null, $statusCode = 200)
|
||||
{
|
||||
parent::__construct($version, $headers, $body);
|
||||
|
||||
$this->statusCode = $statusCode;
|
||||
}
|
||||
|
||||
public function getStatusCode(): int
|
||||
{
|
||||
return $this->statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function withStatus($code, $reasonPhrase = '')
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getReasonPhrase(): string
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
}
|
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class ServerRequest extends Message implements ServerRequestInterface
|
||||
{
|
||||
private $requestTarget;
|
||||
private $method;
|
||||
private $uri;
|
||||
private $server;
|
||||
private $cookies;
|
||||
private $query;
|
||||
private $uploadedFiles;
|
||||
private $data;
|
||||
private $attributes;
|
||||
|
||||
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null, $requestTarget = '/', $method = 'GET', $uri = null, array $server = [], array $cookies = [], array $query = [], array $uploadedFiles = [], $data = null, array $attributes = [])
|
||||
{
|
||||
parent::__construct($version, $headers, $body);
|
||||
|
||||
$this->requestTarget = $requestTarget;
|
||||
$this->method = $method;
|
||||
$this->uri = $uri;
|
||||
$this->server = $server;
|
||||
$this->cookies = $cookies;
|
||||
$this->query = $query;
|
||||
$this->uploadedFiles = $uploadedFiles;
|
||||
$this->data = $data;
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getRequestTarget(): string
|
||||
{
|
||||
return $this->requestTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withRequestTarget($requestTarget)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getMethod(): string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withMethod($method)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return UriInterface
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withUri(UriInterface $uri, $preserveHost = false)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getServerParams(): array
|
||||
{
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
public function getCookieParams(): array
|
||||
{
|
||||
return $this->cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withCookieParams(array $cookies)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getQueryParams(): array
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withQueryParams(array $query)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getUploadedFiles(): array
|
||||
{
|
||||
return $this->uploadedFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withUploadedFiles(array $uploadedFiles)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return array|object|null
|
||||
*/
|
||||
public function getParsedBody()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withParsedBody($data)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function getAttributes(): array
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAttribute($name, $default = null)
|
||||
{
|
||||
return $this->attributes[$name] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withAttribute($name, $value)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withoutAttribute($name)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class Stream implements StreamInterface
|
||||
{
|
||||
private $stringContent;
|
||||
private $eof = true;
|
||||
|
||||
public function __construct($stringContent = '')
|
||||
{
|
||||
$this->stringContent = $stringContent;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->stringContent;
|
||||
}
|
||||
|
||||
public function close(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function detach()
|
||||
{
|
||||
return fopen('data://text/plain,'.$this->stringContent, 'r');
|
||||
}
|
||||
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function tell(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function eof(): bool
|
||||
{
|
||||
return $this->eof;
|
||||
}
|
||||
|
||||
public function isSeekable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function seek($offset, $whence = \SEEK_SET): void
|
||||
{
|
||||
}
|
||||
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->eof = false;
|
||||
}
|
||||
|
||||
public function isWritable(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function write($string): int
|
||||
{
|
||||
return \strlen($string);
|
||||
}
|
||||
|
||||
public function isReadable(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function read($length): string
|
||||
{
|
||||
$this->eof = true;
|
||||
|
||||
return $this->stringContent;
|
||||
}
|
||||
|
||||
public function getContents(): string
|
||||
{
|
||||
return $this->stringContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMetadata($key = null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
/**
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class UploadedFile implements UploadedFileInterface
|
||||
{
|
||||
private $filePath;
|
||||
private $size;
|
||||
private $error;
|
||||
private $clientFileName;
|
||||
private $clientMediaType;
|
||||
|
||||
public function __construct($filePath, $size = null, $error = \UPLOAD_ERR_OK, $clientFileName = null, $clientMediaType = null)
|
||||
{
|
||||
$this->filePath = $filePath;
|
||||
$this->size = $size;
|
||||
$this->error = $error;
|
||||
$this->clientFileName = $clientFileName;
|
||||
$this->clientMediaType = $clientMediaType;
|
||||
}
|
||||
|
||||
public function getStream(): Stream
|
||||
{
|
||||
return new Stream(file_get_contents($this->filePath));
|
||||
}
|
||||
|
||||
public function moveTo($targetPath): void
|
||||
{
|
||||
rename($this->filePath, $targetPath);
|
||||
}
|
||||
|
||||
public function getSize(): ?int
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
public function getError(): int
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getClientFilename(): ?string
|
||||
{
|
||||
return $this->clientFileName;
|
||||
}
|
||||
|
||||
public function getClientMediaType(): ?string
|
||||
{
|
||||
return $this->clientMediaType;
|
||||
}
|
||||
}
|
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
|
||||
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* @author Rougin Royce Gutib <rougingutib@gmail.com>
|
||||
*/
|
||||
class Uri implements UriInterface
|
||||
{
|
||||
private $scheme = '';
|
||||
private $userInfo = '';
|
||||
private $host = '';
|
||||
private $port;
|
||||
private $path = '';
|
||||
private $query = '';
|
||||
private $fragment = '';
|
||||
private $uriString;
|
||||
|
||||
public function __construct(string $uri = '')
|
||||
{
|
||||
$parts = parse_url($uri);
|
||||
|
||||
$this->scheme = $parts['scheme'] ?? '';
|
||||
$this->userInfo = $parts['user'] ?? '';
|
||||
$this->host = $parts['host'] ?? '';
|
||||
$this->port = $parts['port'] ?? null;
|
||||
$this->path = $parts['path'] ?? '';
|
||||
$this->query = $parts['query'] ?? '';
|
||||
$this->fragment = $parts['fragment'] ?? '';
|
||||
$this->uriString = $uri;
|
||||
}
|
||||
|
||||
public function getScheme(): string
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
public function getAuthority(): string
|
||||
{
|
||||
if (empty($this->host)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$authority = $this->host;
|
||||
|
||||
if (!empty($this->userInfo)) {
|
||||
$authority = $this->userInfo.'@'.$authority;
|
||||
}
|
||||
|
||||
$authority .= ':'.$this->port;
|
||||
|
||||
return $authority;
|
||||
}
|
||||
|
||||
public function getUserInfo(): string
|
||||
{
|
||||
return $this->userInfo;
|
||||
}
|
||||
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
public function getPort(): ?int
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getQuery(): string
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function getFragment(): string
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withScheme($scheme)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withUserInfo($user, $password = null)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withHost($host)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withPort($port)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withPath($path)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withQuery($query)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function withFragment($fragment)
|
||||
{
|
||||
throw new \BadMethodCallException('Not implemented.');
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->uriString;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user