Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1917b8d
Add first draft of attributes-based implementation
apfelbox Nov 3, 2023
814d8a7
Move storyblok type and add number field
apfelbox Nov 3, 2023
0f183b0
Sort components by name alphabetically
apfelbox Nov 3, 2023
3237b38
Add first draft of story hydration
apfelbox Nov 3, 2023
6ab8cf2
Use NotBlank instead of NotNull
apfelbox Nov 3, 2023
0a22a46
Add better logging for storyblok errors
apfelbox Nov 3, 2023
2a787b2
Also validate regex values
apfelbox Nov 3, 2023
c4ba6cc
Make datatransformer static
apfelbox Nov 3, 2023
11666cd
Add value normalization
apfelbox Nov 3, 2023
c78c2b2
Start implementation of embedded fields
apfelbox Nov 6, 2023
31cbfa3
Rename factory to hydrator
apfelbox Nov 6, 2023
e9b1789
Finalize embed handling
apfelbox Nov 6, 2023
a4c9daa
Improve name of transform method
apfelbox Nov 6, 2023
e7884bb
Stories should implement the interface
apfelbox Nov 6, 2023
4058f7a
Finaliz blok mapping + hydration
apfelbox Nov 6, 2023
b6ae73a
Remove obsolete classes
apfelbox Nov 6, 2023
79bd417
Move data validator
apfelbox Nov 6, 2023
d926d1c
Remove obsolete class
apfelbox Nov 6, 2023
a9396ec
CS
apfelbox Nov 6, 2023
620a6dd
Move folder data class
apfelbox Nov 6, 2023
fb4be23
Update namespaces after moving
apfelbox Nov 6, 2023
64caa0f
Remove obsolete class
apfelbox Nov 6, 2023
33abf07
Inline reserved field key
apfelbox Nov 6, 2023
bc7d908
CS
apfelbox Nov 6, 2023
8a5517f
Remove component validator
apfelbox Nov 6, 2023
da6f764
Remove obsolete class
apfelbox Nov 6, 2023
9578af6
Unify blok meta data
apfelbox Nov 6, 2023
e09ab08
Unify attributes and depend and extended classes
apfelbox Nov 6, 2023
eab6ec7
Move helper functions
apfelbox Nov 6, 2023
912e584
Improve class names
apfelbox Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
}
],
"require": {
"php": ">= 8.1",
"php": ">= 8.2",
"21torr/bundle-helpers": "^2.1.2",
"21torr/cli": "^1.0",
"psr/log": "^3.0",
"symfony/cache-contracts": "^3.3",
"symfony/console": "^6.1",
"symfony/http-client": "^6.1",
"symfony/lock": "^6.2",
"symfony/property-access": "^6.3",
"symfony/rate-limiter": "^6.2",
"symfony/string": "^6.2",
"symfony/string": "^6.3",
"symfony/validator": "^6.1"
},
"require-dev": {
Expand Down
5 changes: 2 additions & 3 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ services:
$managementToken: !abstract set via config
$contentToken: !abstract set via config


Torr\Storyblok\Manager\ComponentManager:
$components: !tagged_locator { tag: 'storyblok.component.definition', default_index_method: 'getKey' }
Torr\Storyblok\Cache\DebugCacheFactory:
$isDebug: '%kernel.debug%'
20 changes: 10 additions & 10 deletions src/Api/ContentApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Torr\Storyblok\Exception\Story\InvalidDataException;
use Torr\Storyblok\Manager\ComponentManager;
use Torr\Storyblok\Release\ReleaseVersion;
use Torr\Storyblok\Story\Story;
use Torr\Storyblok\Story\StoryFactory;
use Torr\Storyblok\Story\StandaloneNestedStory;
use Torr\Storyblok\Hydrator\StoryHydrator;

final class ContentApi implements ResetInterface
{
Expand All @@ -31,7 +31,7 @@ final class ContentApi implements ResetInterface
public function __construct (
HttpClientInterface $client,
private readonly StoryblokConfig $config,
private readonly StoryFactory $storyFactory,
private readonly StoryHydrator $storyFactory,
private readonly ComponentManager $componentManager,
private readonly LoggerInterface $logger,
)
Expand All @@ -54,7 +54,7 @@ public function __construct (
public function fetchSingleStory (
string|int $identifier,
ReleaseVersion $version = ReleaseVersion::PUBLISHED,
) : ?Story
) : ?StandaloneNestedStory
{
try
{
Expand Down Expand Up @@ -102,14 +102,14 @@ public function fetchSingleStory (
* This method provides certain commonly used named parameters, but also supports passing arbitrary parameters
* in the parameter. Passing named parameters will always overwrite parameters in $query.
*
* @template TStory of Story
* @template TStory of StandaloneNestedStory
*
* @param class-string<TStory> $storyType
*
* @throws ContentRequestFailedException
* @throws UnknownStoryTypeException
*
* @return array<TStory>
*@throws UnknownStoryTypeException
*
* @throws ContentRequestFailedException
*/
public function fetchStories (
string $storyType,
Expand Down Expand Up @@ -154,9 +154,9 @@ public function fetchStories (
*
* @param string|string[]|null $slug
*
* @throws ContentRequestFailedException
* @return array<StandaloneNestedStory>
*@throws ContentRequestFailedException
*
* @return array<Story>
*/
public function fetchAllStories (
string|array|null $slug,
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Data/PaginatedApiResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Torr\Storyblok\Api\Data;

use Torr\Storyblok\Story\Story;
use Torr\Storyblok\Story\StandaloneNestedStory;

final class PaginatedApiResult
{
/**
* @param array<Story> $stories
* @param array<StandaloneNestedStory> $stories
*/
public function __construct (
public readonly int $perPage,
Expand Down
2 changes: 1 addition & 1 deletion src/Api/ManagementApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Torr\Storyblok\Api\Data\ComponentIdMap;
use Torr\Storyblok\Config\StoryblokConfig;
use Torr\Storyblok\Exception\Api\ApiRequestFailedException;
use Torr\Storyblok\Folder\FolderData;
use Torr\Storyblok\Data\Folder\FolderData;

final class ManagementApi
{
Expand Down
46 changes: 46 additions & 0 deletions src/Cache/DebugCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);

namespace Torr\Storyblok\Cache;

use Symfony\Contracts\Cache\CacheInterface;

/**
* @template DataType of mixed
*/
final class DebugCache
{
private bool $hasLocaleCache = false;
private mixed $localCache = null;
/** @var callable */
private mixed $itemGenerator;

public function __construct (
private readonly CacheInterface $cache,
private readonly string $cacheKey,
callable $itemGenerator,
private readonly bool $isDebug,
)
{
$this->itemGenerator = $itemGenerator;
}


/**
* @return DataType
*/
public function get () : mixed
{
if ($this->isDebug)
{
if ($this->hasLocaleCache)
{
return $this->localCache;
}

$this->hasLocaleCache = true;
return $this->localCache = ($this->itemGenerator)();
}

return $this->cache->get($this->cacheKey, $this->itemGenerator);
}
}
32 changes: 32 additions & 0 deletions src/Cache/DebugCacheFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Torr\Storyblok\Cache;

use Symfony\Contracts\Cache\CacheInterface;

final readonly class DebugCacheFactory
{
/**
*/
public function __construct (
private CacheInterface $cache,
private bool $isDebug,
) {}


/**
* Creates a new debug cache
*/
public function createCache (
string $cacheKey,
callable $itemGenerator,
) : DebugCache
{
return new DebugCache(
$this->cache,
$cacheKey,
$itemGenerator,
$this->isDebug,
);
}
}
67 changes: 67 additions & 0 deletions src/Command/DebugCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php declare(strict_types=1);

namespace Torr\Storyblok\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Torr\Cli\Console\Style\TorrStyle;
use Torr\Storyblok\Api\ContentApi;
use Torr\Storyblok\Manager\ComponentManager;
use Torr\Storyblok\Release\ReleaseVersion;

#[AsCommand("storyblok:debug")]
final class DebugCommand extends Command
{
/**
* @inheritDoc
*/
public function __construct (
private readonly ComponentManager $componentManager,
private readonly ContentApi $contentApi,
)
{
parent::__construct();
}

/**
* @inheritDoc
*/
protected function configure ()
{
$this
->addOption("fetch")
->addOption("sync");
}


/**
* @inheritDoc
*/
protected function execute (InputInterface $input, OutputInterface $output) : int
{
$io = new TorrStyle($input, $output);
$io->title("Storyblok: Debug");

if ($input->getOption("fetch"))
{
$stories = $this->contentApi->fetchAllStories(null, version: ReleaseVersion::DRAFT);
dd($stories);
}

$definitions = $this->componentManager->getDefinitions();
dump($definitions);

if ($input->getOption("sync"))
{
foreach ($definitions->getComponents() as $component)
{
$io->section($component->definition->name);
dump($component->generateManagementApiData());
}
}

return self::SUCCESS;
}
}
62 changes: 0 additions & 62 deletions src/Command/ValidateDefinitionsCommand.php

This file was deleted.

Loading