Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  update documentation
  make Cookies and Environment constructors private
  make messages constructor private
  move all classes related to the server request in the ServerRequest namespace
  move Method one level up
  move StatusCode to the Response namespace
  move stringable one level up
  simplify classes casting messages to string
  delete Request, ServerRequest and Message interfaces to have a single implementation
  delete Response interface to have a single implementation
  use filesystem 7
  exclude fixtures from code coverage
  • Loading branch information
Baptouuuu committed Oct 22, 2023
2 parents f62167f + ab8c8ef commit 3a9f236
Show file tree
Hide file tree
Showing 65 changed files with 625 additions and 1,270 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Changelog

## 7.0.0 - 2023-10-22

### Changed

- Requires `innmind/filesystem:~7.0`
- `Innmind\Http\Content\Multipart` now longer implements `Innmind\Filesystem\File\Content`, use `->asContent()`
- `Innmind\Http\Message\Response\Response` as been moved to `Innmind\Http\Response`
- `Innmind\Http\Message\Request\Request` as been moved to `Innmind\Http\Request`
- `Innmind\Http\Message\ServerRequest\ServerRequest` as been moved to `Innmind\Http\ServerRequest`
- `Innmind\Http\Message\Request\Stringable` has be called like this now `Stringable::new()($request)`
- `Innmind\Http\Message\Response\Stringable` has be called like this now `Stringable::new()($request)`
- `Innmind\Http\Message\ServerRequest\Stringable` has be called like this now `Stringable::new()($request)`
- `Innmind\Http\Message\Request\Stringable` has been moved to `Innmind\Http\Request\Stringable`
- `Innmind\Http\Message\Response\Stringable` has been moved to `Innmind\Http\Response\Stringable`
- `Innmind\Http\Message\ServerRequest\Stringable` has been moved to `Innmind\Http\ServerRequest\Stringable`
- `Innmind\Http\Message\StatusCode` has been moved to `Innmind\Http\Response\StatusCode`
- `Innmind\Http\Message\StatusCode\Range` has been moved to `Innmind\Http\Response\StatusCode\Range`
- `Innmind\Http\Message\Method` has been moved to `Innmind\Http\Method`
- `Innmind\Http\Message\Cookies` has been moved to `Innmind\Http\ServerRequest\Cookies`
- `Innmind\Http\Message\Environment` has been moved to `Innmind\Http\ServerRequest\Environment`
- `Innmind\Http\Message\Files` has been moved to `Innmind\Http\ServerRequest\Files`
- `Innmind\Http\Message\Form` has been moved to `Innmind\Http\ServerRequest\Form`
- `Innmind\Http\Message\Query` has been moved to `Innmind\Http\ServerRequest\Query`
- `Innmind\Http\Request` constructor is now private, use `::of()` named constructor instead
- `Innmind\Http\ServerRequest` constructor is now private, use `::of()` named constructor instead
- `Innmind\Http\Response` constructor is now private, use `::of()` named constructor instead
- `Innmind\Http\ServerRequest\Cookies` constructor is now private, use `::of()` named constructor instead
- `Innmind\Http\ServerRequest\Environment` constructor is now private, use `::of()` named constructor instead

### Removed

- `Innmind\Http\File\Input`
- `Innmind\Http\Message\Response`
- `Innmind\Http\Message\Request`
- `Innmind\Http\Message\ServerRequest`
- `Innmind\Http\Message`

## 6.4.0 - 2023-09-16

### Added
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ $request = ServerRequestFactory::default()();

```php
use Innmind\Http\{
Message\Response\Response,
Message\StatusCode,
Response,
Response\StatusCode,
ProtocolVersion,
Headers,
Header,
Expand All @@ -32,7 +32,7 @@ use Innmind\Http\{
use Innmind\Filesystem\File\Content;
use Innmind\TimeContinuum\Earth\Clock;

$response = new Response(
$response = Response::of(
StatusCode::ok,
ProtocolVersion::v11,
Headers::of(
Expand All @@ -58,8 +58,8 @@ Content-Type : application/json

```php
use Innmind\Http\{
Message\Request\Request,
Message\Method,
Request,
Method,
Content\Multipart,
Header\ContentType,
Header\ContentType\Boundary,
Expand All @@ -73,7 +73,7 @@ use Innmind\Filesystem\{
use Innmind\Url\Url;

$boundary = Boundary::uuid();
$request = new Request(
$request = Request::of(
Url::of('http://some-server.com/')
Method::post,
ProtocolVersion::v11,
Expand All @@ -82,7 +82,7 @@ $request = new Request(
->with('some[key]', 'some value')
->withFile('some[file]', File::named(
'whatever.txt',
Content\Lines::ofContent(' can be any file content'),
Content::ofString(' can be any file content'),
)),
);
```
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore:
- fixtures/*
- .php-cs-fixer.dist.php
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"php": "~8.2",
"innmind/url": "~4.0",
"innmind/immutable": "~4.15|~5.0",
"innmind/filesystem": "^6.3.2",
"innmind/filesystem": "~7.0",
"innmind/io": "~2.2",
"innmind/time-continuum": "~3.0",
"innmind/stream": "~4.0",
"innmind/media-type": "^2.0.1",
Expand Down
79 changes: 7 additions & 72 deletions src/Content/Multipart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
use Innmind\Filesystem\{
File as Binary,
File\Content,
File\Content\Chunkable,
};
use Innmind\Stream\Stream\Size;
use Innmind\Immutable\{
Sequence,
Str,
Maybe,
SideEffect,
};

/**
* @psalm-immutable
*/
final class Multipart implements Content, Chunkable
final class Multipart
{
private Boundary $boundary;
/** @var Sequence<Data|File> */
Expand Down Expand Up @@ -66,32 +62,15 @@ public function withFile(string $name, Binary $file): self
);
}

public function foreach(callable $function): SideEffect
public function asContent(): Content
{
return $this->content()->foreach($function);
return Content::ofChunks($this->chunks());
}

public function map(callable $map): Content
{
return $this->content()->map($map);
}

public function flatMap(callable $map): Content
{
return $this->content()->flatMap($map);
}

public function filter(callable $filter): Content
{
return $this->content()->filter($filter);
}

public function lines(): Sequence
{
return $this->content()->lines();
}

public function chunks(): Sequence
/**
* @return Sequence<Str>
*/
private function chunks(): Sequence
{
$boundary = $this->boundaryStr();
$boundaryLine = Sequence::lazyStartingWith($boundary->append("\r\n"));
Expand All @@ -109,50 +88,6 @@ public function chunks(): Sequence
->add($boundary->append('--'));
}

public function reduce($carry, callable $reducer)
{
return $this->content()->reduce($carry, $reducer);
}

public function size(): Maybe
{
// +2 for carriage return and -- (for last boundary)
$boundary = $this->boundaryStr()->toEncoding(Str\Encoding::ascii)->length() + 2;

if ($this->parts->empty()) {
return Maybe::just(new Size($boundary + $boundary));
}

/** @var Maybe<int> */
$parts = $this
->parts
->map(
static fn($part) => $part
->size()
->map(static fn($size) => $boundary + $size + 2),
)
->match(
static fn($first, $rest) => Maybe::all($first, ...$rest->toList())->map(
static fn(int ...$sizes) => \array_sum($sizes),
),
static fn() => Maybe::nothing(),
);

return $parts
->map(static fn($size) => $size + $boundary)
->map(static fn($size) => new Size($size));
}

public function toString(): string
{
return $this->content()->toString();
}

private function content(): Content
{
return Content\Chunks::of($this->chunks());
}

private function boundaryStr(): Str
{
return Str::of('--'.$this->boundary->value());
Expand Down
7 changes: 2 additions & 5 deletions src/Content/Multipart/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

namespace Innmind\Http\Content\Multipart;

use Innmind\Filesystem\{
File as Binary,
Chunk,
};
use Innmind\Filesystem\File as Binary;
use Innmind\Immutable\{
Sequence,
Str,
Expand Down Expand Up @@ -35,7 +32,7 @@ public function chunks(): Sequence
{
return $this
->headers()
->append((new Chunk)($this->file->content()));
->append($this->file->content()->chunks());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Cookies/CookiesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Http\{
Factory\CookiesFactory as CookiesFactoryInterface,
Message\Cookies,
ServerRequest\Cookies,
};
use Innmind\Immutable\Map;

Expand Down Expand Up @@ -34,7 +34,7 @@ public function __invoke(): Cookies
$map = ($map)($name, $value);
}

return new Cookies($map);
return Cookies::of($map);
}

public static function default(): self
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/CookiesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Http\Factory;

use Innmind\Http\Message\Cookies;
use Innmind\Http\ServerRequest\Cookies;

/**
* @psalm-immutable
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/Environment/EnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Http\{
Factory\EnvironmentFactory as EnvironmentFactoryInterface,
Message\Environment,
ServerRequest\Environment,
};
use Innmind\Immutable\Map;

Expand Down Expand Up @@ -34,7 +34,7 @@ public function __invoke(): Environment
$map = ($map)($name, $value);
}

return new Environment($map);
return Environment::of($map);
}

public static function default(): self
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/EnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Http\Factory;

use Innmind\Http\Message\Environment;
use Innmind\Http\ServerRequest\Environment;

/**
* @psalm-immutable
Expand Down
27 changes: 20 additions & 7 deletions src/Factory/Files/FilesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Innmind\Http\{
Factory\FilesFactory as FilesFactoryInterface,
Message\Files,
ServerRequest\Files,
File\Status,
Exception\LogicException,
};
Expand All @@ -15,6 +15,8 @@
File\Content,
};
use Innmind\Url\Path;
use Innmind\IO\IO;
use Innmind\Stream\Capabilities;
use Innmind\Immutable\{
Map,
Either,
Expand All @@ -29,10 +31,14 @@
*/
final class FilesFactory implements FilesFactoryInterface
{
private Capabilities $capabilities;
private IO $io;
private array $files;

public function __construct(array $files)
public function __construct(Capabilities $capabilities, IO $io, array $files)
{
$this->capabilities = $capabilities;
$this->io = $io;
$this->files = $files;
}

Expand All @@ -48,9 +54,9 @@ public function __invoke(): Files
return Files::of($files);
}

public static function default(): self
public static function default(Capabilities $capabilities, IO $io): self
{
return new self($_FILES);
return new self($capabilities, $io, $_FILES);
}

private function map(array $content): array|Either
Expand Down Expand Up @@ -105,10 +111,17 @@ private function buildFile(
return Either::left($status);
}

/** @var Either<Status, File> */
return Either::right(File\File::named(
/**
* @psalm-suppress ImpureMethodCall
* @var Either<Status, File>
*/
return Either::right(File::named(
$name,
Content\AtPath::of(Path::of($path)),
Content::atPath(
$this->capabilities->readable(),
$this->io->readable(),
Path::of($path),
),
MediaType::maybe($media)->match(
static fn($media) => $media,
static fn() => MediaType::null(),
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FilesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Http\Factory;

use Innmind\Http\Message\Files;
use Innmind\Http\ServerRequest\Files;

/**
* @psalm-immutable
Expand Down
3 changes: 1 addition & 2 deletions src/Factory/Form/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

use Innmind\Http\{
Factory\FormFactory as FormFactoryInterface,
Message\Form,
Message\Form\Parameter,
ServerRequest\Form,
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Innmind\Http\Factory;

use Innmind\Http\Message\Form;
use Innmind\Http\ServerRequest\Form;

/**
* @psalm-immutable
Expand Down
3 changes: 1 addition & 2 deletions src/Factory/Query/QueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

use Innmind\Http\{
Factory\QueryFactory as QueryFactoryInterface,
Message\Query,
Message\Query\Parameter,
ServerRequest\Query,
};

/**
Expand Down
Loading

0 comments on commit 3a9f236

Please sign in to comment.