Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/resource channel #18

Merged
merged 34 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
db7ef18
feat: add ResourceHierarchyLoader::findRecursive() and new CachedReso…
sitepark-veltrup Mar 13, 2024
7ccc28e
feat: work in process
sitepark-veltrup Mar 14, 2024
72a4ef1
docs: typo
sitepark-veltrup Mar 14, 2024
80540ef
refactor: create findRecursiveInternal for internal method signatur
sitepark-veltrup Mar 14, 2024
3e022b9
refactor: remove $parentPath for findResource() callable
sitepark-veltrup Mar 14, 2024
5e210dd
Merge branch 'feature/find-in-hierarchy' into feature/refactore-serve…
sitepark-veltrup Mar 14, 2024
0279cc8
feat: lang support
sitepark-veltrup Mar 20, 2024
23acd44
chore: normalize composer.json
sitepark-veltrup Mar 20, 2024
e90d5f6
fix: add empty directories for tests
sitepark-veltrup Mar 20, 2024
c9a4b61
fix: resource base location
sitepark-veltrup Mar 22, 2024
747dca1
Update src/ResourceHierarchyLoader.php
sitepark-veltrup Apr 2, 2024
69be91c
feat: ResourceHierarchyWalker implementation
sitepark-veltrup Apr 4, 2024
a3da454
refactor: findRecursive replaced
sitepark-veltrup Apr 4, 2024
2e83a27
docs: add ResourceHierarchyWalker class doc
sitepark-veltrup Apr 4, 2024
1b67370
refactor: ResourceHierarchyLoader extends ResourceLoader
sitepark-veltrup Apr 4, 2024
3d55b08
Merge branch 'feature/find-in-hierarchy' into feature/resource-channel
sitepark-veltrup Apr 8, 2024
7f976a0
Merge branch 'main' into feature/resource-channel
sitepark-veltrup Apr 8, 2024
b5ad318
feat: allow string for ResourceHierarchyWalker::walk
sitepark-veltrup Apr 10, 2024
f0981a5
Update src/Loader/SiteKitLoader.php
sitepark-veltrup Apr 11, 2024
79d05cd
fix: phpstan error
sitepark-veltrup Apr 11, 2024
c91dac5
refactor: use shortened syntax
sitepark-veltrup Apr 11, 2024
3a3c266
refactor: make code easier to understand
sitepark-veltrup Apr 11, 2024
5d5f3c6
refactor: rename $resourceChannel to $resourceChannelFactory
sitepark-veltrup Apr 11, 2024
315944b
refactor: call $this->baseLocator->locate() in constructor
sitepark-veltrup Apr 11, 2024
235f390
refactor: simplify code
sitepark-veltrup Apr 11, 2024
b08052a
docs: fix doc
sitepark-veltrup Apr 11, 2024
7afc5df
refactor: rename ResourceChannel::preview to ResourceChannel:isPreview
sitepark-veltrup Apr 11, 2024
311d7a1
style: update newlines
sitepark-veltrup Apr 11, 2024
9bd0068
refactor: SiteKitResourceChannelFactory::findContextPhpFile()
sitepark-veltrup Apr 11, 2024
c127465
refactor: remove ResourceBaseLocator
sitepark-veltrup Apr 17, 2024
e666b51
refactor: ResourceLocation and ResourceLanguage
sitepark-veltrup Apr 18, 2024
584fee8
fix: phpcs fixes
sitepark-veltrup Apr 18, 2024
9194073
test: refactor resource creation
sitepark-veltrup Apr 18, 2024
3feb7f3
refactor: code review suggestion
sitepark-veltrup Apr 18, 2024
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
8 changes: 8 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
# Create a regex for a conventional commit.
convetional_commit_regex="^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z \-]+\))?!?: .+$"

# Accept Merge commits
merge_msg_regex="^Merge branch '.+'.+$"

# Get the commit message (the parameter we're given is just the path to the
# temporary file which holds the message).
commit_message=$(cat "$1")

if [[ "$commit_message" =~ $merge_msg_regex ]]; then
echo -e "\e[32mAccept Merge commits...\e[0m"
exit 0
fi

# Check the message, if we match, all good baby.
if [[ "$commit_message" =~ $convetional_commit_regex ]]; then
echo -e "\e[32mCommit message meets Conventional Commit standards...\e[0m"
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
],
"require": {
"php": ">=8.1 <8.4.0"
"php": ">=8.1 <8.4.0",
"ext-intl": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/Exception/InvalidResourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Atoolo\Resource\Exception;

use Atoolo\Resource\ResourceLocation;

/**
* This exception is used when a resource is invalid. This can have the
* following reasons:
Expand All @@ -14,19 +16,19 @@
class InvalidResourceException extends \RuntimeException
{
public function __construct(
private readonly string $location,
private readonly ResourceLocation $location,
string $message = "",
int $code = 0,
?\Throwable $previous = null
) {
parent::__construct(
$location . ': ' . $message,
$location->__toString() . ': ' . $message,
$code,
$previous
);
}

public function getLocation(): string
public function getLocation(): ResourceLocation
{
return $this->location;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Exception/ResourceNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@

namespace Atoolo\Resource\Exception;

use Atoolo\Resource\ResourceLocation;

/**
* This exception is used if no resource could be found via the specified
* location.
*/
class ResourceNotFoundException extends \RuntimeException
{
public function __construct(
private readonly string $location,
private readonly ResourceLocation $location,
string $message = "",
int $code = 0,
?\Throwable $previous = null
) {
parent::__construct(
$location . ': ' . $message,
$location->__toString() . ': ' . $message,
$code,
$previous
);
}

public function getLocation(): string
public function getLocation(): ResourceLocation
{
return $this->location;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Loader/CachedResourceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
use Atoolo\Resource\Exception\ResourceNotFoundException;
use Atoolo\Resource\Resource;
use Atoolo\Resource\ResourceLoader;
use Atoolo\Resource\ResourceLocation;

/**
* The CachedResourceLoader class is used to load resources
* from a given location and cache them for future use.
* The cache is stored in memory and is not persistent.
*/
class CachedResourceLoader implements ResourceLoader
{
Expand All @@ -28,20 +30,18 @@ public function __construct(
* @throws InvalidResourceException
* @throws ResourceNotFoundException
*/
public function load(string $location): Resource
public function load(ResourceLocation $location): Resource
{
if (isset($this->cache[$location])) {
return $this->cache[$location];
}

$resource = $this->resourceLoader->load($location);
$this->cache[$location] = $resource;
return $resource;
$key = $location->__toString();
return $this->cache[$key] ??= $this->resourceLoader->load(
$location
);
}

public function exists(string $location): bool
public function exists(ResourceLocation $location): bool
{
if (isset($this->cache[$location])) {
$key = $location->__toString();
if (isset($this->cache[$key])) {
return true;
}
return $this->resourceLoader->exists($location);
Expand Down
31 changes: 0 additions & 31 deletions src/Loader/ServerVarResourceBaseLocator.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Loader/SiteKit/ResourceStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ResourceStub
*/
public function init(array $data): void
{
$this->data['init'] = $data;
$this->data = array_merge($this->data, $data);
}

/**
Expand Down
Loading
Loading