Skip to content

Commit

Permalink
Reflected AMP v2.16.0 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tg666 committed Oct 1, 2024
1 parent 0ecea98 commit ad6218e
Show file tree
Hide file tree
Showing 50 changed files with 179 additions and 248 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ $ composer require 68publishers/amp-client

## Versions compatibility matrix

| PHP client version | JS client version | AMP version | API version |
|:------------------:|:-----------------:|:-----------:|:-----------:|
| `~1.0.0` | `~1.4.0` | `2.12.0` | `1` |
| `~1.1.0` | `~1.4.0` | `2.12.0` | `1` |
| `~1.2.0` | `~1.5.0` | `>=2.13.0` | `1` |
| `~1.3.0` | `~1.6.0` | `>=2.16.0` | `1` |
| PHP client version | JS client version | AMP version | API version |
|:------------------:|:-----------------:|:--------------------:|:-----------:|
| `~1.0.0` | `~1.4.0` | `2.12.0` | `1` |
| `~1.1.0` | `~1.4.0` | `2.12.0` | `1` |
| `~1.2.0` | `~1.5.0` | `>=2.13.0 <= 2.15.1` | `1` |
| `~1.3.0` | `~1.6.0` | `>=2.16.0` | `1` |

## Integration without a framework

Expand Down
4 changes: 0 additions & 4 deletions src/Renderer/AmpBannerExternalAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public function __toString(): string
'rotationSeconds' => $this->position->getRotationSeconds(),
'displayType' => $this->position->getDisplayType(),
'breakpointType' => $this->position->getBreakpointType(),
'dimensions' => [
'width' => $this->position->getDimensions()->getWidth(),
'height' => $this->position->getDimensions()->getHeight(),
],
],
'state' => [
'value' => $this->state,
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/Latte/Templates/contents.fragment.latte
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
sizes="{$content->getSizes()}"
alt="{$content->getAlt()}"
n:attr="
width => null !== $position->getDimensions()->getWidth() ? $position->getDimensions()->getWidth() : null,
height => null !== $position->getDimensions()->getHeight() ? $position->getDimensions()->getHeight() : null,
width => null !== $content->getDimensions()->getWidth() ? $content->getDimensions()->getWidth() : null,
height => null !== $content->getDimensions()->getHeight() ? $content->getDimensions()->getHeight() : null,
title => '' !== $content->getTitle() ? $content->getTitle() : null,
loading => $options->evaluate('loading', $index),
fetchpriority => $options->evaluate('fetchpriority', $index),
Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/Phtml/Templates/contents.fragment.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use SixtyEightPublishers\AmpClient\Renderer\BreakpointStyle\BreakpointStyle;
src="<?= Helpers::escapeHtmlAttr($content->getSrc()) ?>"
sizes="<?= Helpers::escapeHtmlAttr($content->getSizes()) ?>"
alt="<?= Helpers::escapeHtmlAttr($content->getAlt()) ?>"
<?php if (null !== $position->getDimensions()->getWidth()) : ?>width="<?= Helpers::escapeHtmlAttr($position->getDimensions()->getWidth()) ?>"<?php endif ?>
<?php if (null !== $position->getDimensions()->getHeight()) : ?>height="<?= Helpers::escapeHtmlAttr($position->getDimensions()->getHeight()) ?>"<?php endif ?>
<?php if (null !== $content->getDimensions()->getWidth()) : ?>width="<?= Helpers::escapeHtmlAttr($content->getDimensions()->getWidth()) ?>"<?php endif ?>
<?php if (null !== $content->getDimensions()->getHeight()) : ?>height="<?= Helpers::escapeHtmlAttr($content->getDimensions()->getHeight()) ?>"<?php endif ?>
<?php if ('' !== $content->getTitle()) : ?>title="<?= Helpers::escapeHtmlAttr($content->getTitle()) ?>"<?php endif ?>
<?php if (null !== ($loading = $options->evaluate('loading', $index ?? 0))) : ?>loading="<?= Helpers::escapeHtmlAttr($loading) ?>"<?php endif ?>
<?php if (null !== ($fetchPriority = $options->evaluate('fetchpriority', $index ?? 0))) : ?>fetchpriority="<?= Helpers::escapeHtmlAttr($fetchPriority) ?>"<?php endif ?>>
Expand Down
4 changes: 2 additions & 2 deletions src/Response/Hydrator/BannersResponseHydratorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* srcset: string,
* }>,
* sizes: string,
* dimensions?: DimensionsData,
* }
*
* @phpstan-type BannerData = array{
Expand All @@ -60,7 +61,6 @@
* breakpoint_type: string,
* mode?: string,
* options?: array<string, string>,
* dimensions?: DimensionsData,
* banners: array<int, BannerData>,
* }
*
Expand Down Expand Up @@ -94,7 +94,6 @@ public function hydrate($responseBody): BannersResponse
$positionData['breakpoint_type'],
$positionData['mode'] ?? Position::ModeManaged,
$positionData['options'] ?? [],
$this->hydrateDimensions($positionData['dimensions'] ?? null),
$this->hydrateBanners($positionData['banners']),
);
}
Expand Down Expand Up @@ -155,6 +154,7 @@ private function hydrateContents(array $contentsData): array
),
$contentData['sources'],
),
$this->hydrateDimensions($contentData['dimensions'] ?? null),
);

break;
Expand Down
11 changes: 10 additions & 1 deletion src/Response/ValueObject/ImageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ final class ImageContent implements ContentInterface
/** @var array<int, Source> */
private array $sources;

private Dimensions $dimensions;

/**
* @param array<int, Source> $sources
*/
Expand All @@ -37,7 +39,8 @@ public function __construct(
string $src,
string $srcset,
string $sizes,
array $sources
array $sources,
Dimensions $dimensions
) {
$this->breakpoint = $breakpoint;
$this->href = $href;
Expand All @@ -48,6 +51,7 @@ public function __construct(
$this->srcset = $srcset;
$this->sizes = $sizes;
$this->sources = $sources;
$this->dimensions = $dimensions;
}

public function getBreakpoint(): ?int
Expand Down Expand Up @@ -97,4 +101,9 @@ public function getSources(): array
{
return $this->sources;
}

public function getDimensions(): Dimensions
{
return $this->dimensions;
}
}
9 changes: 0 additions & 9 deletions src/Response/ValueObject/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ final class Position
/** @var array<string, string> */
private array $options;

private Dimensions $dimensions;

/** @var array<int, Banner> */
private array $banners;

Expand All @@ -51,7 +49,6 @@ public function __construct(
string $breakpointType,
string $mode,
array $options,
Dimensions $dimensions,
array $banners
) {
$this->id = $id;
Expand All @@ -62,7 +59,6 @@ public function __construct(
$this->breakpointType = $breakpointType;
$this->mode = $mode;
$this->options = $options;
$this->dimensions = $dimensions;
$this->banners = $banners;
}

Expand Down Expand Up @@ -109,11 +105,6 @@ public function getOptions(): array
return $this->options;
}

public function getDimensions(): Dimensions
{
return $this->dimensions;
}

/**
* @return array<int, Banner>
*/
Expand Down
16 changes: 0 additions & 16 deletions tests/Bridge/Latte/RendererProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use SixtyEightPublishers\AmpClient\Request\ValueObject\BannerResource;
use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
use SixtyEightPublishers\AmpClient\Response\BannersResponse;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
use SixtyEightPublishers\AmpClient\Tests\Bridge\Latte\Event\ConfigureClientEventHandlerFixture;
use SixtyEightPublishers\AmpClient\Tests\Exception\AmpExceptionFixture;
Expand All @@ -47,7 +46,6 @@ public function testInvokingDefaultInstanceWithoutResources(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -93,7 +91,6 @@ public function testInvokingDefaultInstanceWithSameModeAsDefault(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -139,7 +136,6 @@ public function testInvokingDefaultInstanceWithAttributes(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -185,7 +181,6 @@ public function testInvokingDefaultInstanceWithOptions(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -231,7 +226,6 @@ public function testInvokingDefaultInstanceWithResources(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -293,7 +287,6 @@ public function testInvokingDefaultInstanceWithPositionInEmbedMode(): void
ResponsePosition::BreakpointTypeMin,
$positionMode,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -340,7 +333,6 @@ public function testClientConfigurationEventsShouldBeInvokedBeforeFirstFetch():
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);

Expand Down Expand Up @@ -461,7 +453,6 @@ public function testExceptionShouldBeThrownWhenRendererThrowsExceptionInDebugMod
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);

Expand Down Expand Up @@ -501,7 +492,6 @@ public function testEmptyStringShouldBeReturnedWhenRendererThrowsExceptionInNonD
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);

Expand Down Expand Up @@ -539,7 +529,6 @@ public function testExceptionShouldBeLoggedWhenRendererThrowsExceptionInNonDebug
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);

Expand Down Expand Up @@ -627,7 +616,6 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$responsePosition2 = new ResponsePosition(
Expand All @@ -639,7 +627,6 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -741,7 +728,6 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$responsePosition2 = new ResponsePosition(
Expand All @@ -753,7 +739,6 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down Expand Up @@ -845,7 +830,6 @@ public function testEmbedPositionReturnedFromApiShouldBeQueuedAndReplacedInStrin
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeEmbed,
[],
new Dimensions(null, null),
[],
);
$response = new BannersResponse([
Expand Down
7 changes: 0 additions & 7 deletions tests/Renderer/BannersResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use SixtyEightPublishers\AmpClient\Renderer\BannersResolver;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
use Tester\Assert;
use Tester\TestCase;
Expand All @@ -26,7 +25,6 @@ public function testNullShouldBeReturnedWhenResolvingSinglePositionWithoutBanner
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$resolver = new BannersResolver();
Expand All @@ -49,7 +47,6 @@ public function testFirstBannerWithHighestScoreShouldBeReturnedWhenResolvingSing
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[$banner1, $banner2, $banner3, $banner4],
);
$resolver = new BannersResolver();
Expand All @@ -68,7 +65,6 @@ public function testEmptyArrayShouldBeReturnedWhenResolvingMultiplePositionWitho
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$resolver = new BannersResolver();
Expand All @@ -91,7 +87,6 @@ public function testSortedBannersShouldBeReturnedWhenResolvingMultiplePosition()
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[$banner1, $banner2, $banner3, $banner4],
);
$resolver = new BannersResolver();
Expand All @@ -115,7 +110,6 @@ public function testNullShouldBeReturnedWhenResolvingRandomPositionWithoutBanner
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[],
);
$resolver = new BannersResolver();
Expand All @@ -138,7 +132,6 @@ public function testRandomBannerShouldBeReturnedWhenResolvingRandomPosition(): v
Position::BreakpointTypeMin,
Position::ModeManaged,
[],
new Dimensions(null, null),
[$banner1, $banner2, $banner3, $banner4],
);
$resolver = new BannersResolver();
Expand Down
2 changes: 0 additions & 2 deletions tests/Renderer/BreakpointStyle/BreakpointStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use SixtyEightPublishers\AmpClient\Renderer\BreakpointStyle\BreakpointStyle;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions;
use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
Expand Down Expand Up @@ -134,7 +133,6 @@ private function createBreakpointStyle(string $breakpointType, array $contents):
$breakpointType,
ResponsePosition::ModeManaged,
[],
new Dimensions(null, null),
[$banner],
);

Expand Down
Loading

0 comments on commit ad6218e

Please sign in to comment.