Skip to content

Commit c0ca6b1

Browse files
committed
Merge branch 'sync'
2 parents 0686702 + dadec86 commit c0ca6b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+964
-608
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ parameters:
5555
count: 1
5656
path: src/Concept/Facade.php
5757

58-
-
59-
message: "#^Method Lkrms\\\\Contract\\\\IExtensible\\:\\:getMetaProperty\\(\\) has no return type specified\\.$#"
60-
count: 1
61-
path: src/Contract/IExtensible.php
62-
63-
-
64-
message: "#^Method Lkrms\\\\Contract\\\\IExtensible\\:\\:setMetaProperty\\(\\) has parameter \\$value with no type specified\\.$#"
65-
count: 1
66-
path: src/Contract/IExtensible.php
67-
6858
-
6959
message: "#^Method Lkrms\\\\Contract\\\\IPipe\\:\\:handle\\(\\) has parameter \\$pipeline with generic interface Lkrms\\\\Contract\\\\IPipeline but does not specify its types\\: TInput, TOutput, TArgument$#"
7060
count: 1
@@ -485,11 +475,6 @@ parameters:
485475
count: 1
486476
path: src/Sync/Contract/ISyncEntityProvider.php
487477

488-
-
489-
message: "#^Method Lkrms\\\\Sync\\\\Contract\\\\ISyncProvider\\:\\:getDefinition\\(\\) return type with generic interface Lkrms\\\\Sync\\\\Contract\\\\ISyncDefinition does not specify its types\\: TEntity, TProvider$#"
490-
count: 1
491-
path: src/Sync/Contract/ISyncProvider.php
492-
493478
-
494479
message: "#^Method Lkrms\\\\Sync\\\\Support\\\\SyncContext\\:\\:maybeApplyFilterPolicy\\(\\) has parameter \\$empty with no type specified\\.$#"
495480
count: 1

src/Concept/Provider.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Concept;
4+
5+
use Lkrms\Contract\IContainer;
6+
use Lkrms\Contract\IProvider;
7+
use Lkrms\Exception\MethodNotImplementedException;
8+
use Lkrms\Support\DateFormatter;
9+
use Lkrms\Utility\Env;
10+
11+
/**
12+
* Base class for providers
13+
*
14+
*/
15+
abstract class Provider implements IProvider
16+
{
17+
protected IContainer $App;
18+
19+
protected Env $Env;
20+
21+
private DateFormatter $DateFormatter;
22+
23+
/**
24+
* Creates a new provider object
25+
*/
26+
public function __construct(IContainer $app, Env $env)
27+
{
28+
$this->App = $app;
29+
$this->Env = $env;
30+
}
31+
32+
/**
33+
* Get a DateFormatter to work with the backend's date format and/or
34+
* timezone
35+
*
36+
* The {@see DateFormatter} returned will be cached for the lifetime of the
37+
* {@see Provider} instance.
38+
*/
39+
abstract protected function getDateFormatter(): DateFormatter;
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function description(): ?string
45+
{
46+
return null;
47+
}
48+
49+
/**
50+
* @inheritDoc
51+
*/
52+
public function checkHeartbeat(int $ttl = 300)
53+
{
54+
throw new MethodNotImplementedException(
55+
static::class,
56+
__FUNCTION__,
57+
IProvider::class
58+
);
59+
}
60+
61+
/**
62+
* @inheritDoc
63+
*/
64+
final public function app(): IContainer
65+
{
66+
return $this->App;
67+
}
68+
69+
/**
70+
* @inheritDoc
71+
*/
72+
final public function container(): IContainer
73+
{
74+
return $this->App;
75+
}
76+
77+
/**
78+
* @inheritDoc
79+
*/
80+
final public function env(): Env
81+
{
82+
return $this->Env;
83+
}
84+
85+
/**
86+
* @inheritDoc
87+
*/
88+
final public function dateFormatter(): DateFormatter
89+
{
90+
return $this->DateFormatter
91+
?? ($this->DateFormatter = $this->getDateFormatter());
92+
}
93+
}

src/Concern/HasNormaliser.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lkrms\Concern;
4+
5+
use Lkrms\Contract\ReturnsNormaliser;
6+
use Lkrms\Utility\Convert;
7+
use Closure;
8+
9+
/**
10+
* Implements ReturnsNormaliser
11+
*
12+
* @see ReturnsNormaliser
13+
*/
14+
trait HasNormaliser
15+
{
16+
/**
17+
* @var array<string,Closure(string $name, bool $greedy=, string...$hints): string>
18+
*/
19+
private static $_Normaliser = [];
20+
21+
public static function normaliser(): Closure
22+
{
23+
return
24+
fn(string $name): string =>
25+
Convert::toSnakeCase($name);
26+
}
27+
28+
final public static function normalise(string $name, bool $greedy = true, string ...$hints): string
29+
{
30+
$normaliser = self::$_Normaliser[static::class]
31+
?? (self::$_Normaliser[static::class] = static::normaliser());
32+
33+
return $normaliser($name, $greedy, ...$hints);
34+
}
35+
}

src/Concern/TConstructible.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,17 @@ final public static function construct(array $data, ?IContainer $container = nul
5151
*
5252
* See {@see TConstructible::construct()} for more information.
5353
*
54-
* @param iterable<mixed[]> $dataList
55-
* @param int $conformity One of the {@see ArrayKeyConformity} values. Use
56-
* `COMPLETE` or `PARTIAL` wherever possible to improve performance.
57-
* @phpstan-param ArrayKeyConformity::* $conformity
54+
* @param iterable<mixed[]> $list
55+
* @param ArrayKeyConformity::* $conformity Use `COMPLETE` or `PARTIAL`
56+
* wherever possible to improve performance.
5857
* @param IContainer|null $container Used to create each instance if set.
5958
* @param (IHierarchy&static)|null $parent If the class implements
6059
* {@see IHierarchy}, pass `$parent` to each instance via
6160
* {@see IHierarchy::setParent()}.
6261
* @return Generator<static>
6362
*/
6463
final public static function constructList(
65-
iterable $dataList,
64+
iterable $list,
6665
int $conformity = ArrayKeyConformity::NONE,
6766
?IContainer $container = null,
6867
$parent = null
@@ -72,7 +71,7 @@ final public static function constructList(
7271
}
7372

7473
$closure = null;
75-
foreach ($dataList as $key => $data) {
74+
foreach ($list as $key => $data) {
7675
if (!$closure) {
7776
/** @var Introspector<static,IntrospectionClass<static>> */
7877
$builder = Introspector::getService($container, static::class);

src/Concern/TIntrospector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait TIntrospector
2424
/**
2525
* @var array<string,TIntrospectionClass>
2626
*/
27-
private static $IntrospectionClasses = [];
27+
private static $_IntrospectionClasses = [];
2828

2929
/**
3030
* @param class-string<TClass> $class
@@ -73,8 +73,8 @@ private function __construct(string $class)
7373
{
7474
$_class = strtolower($class);
7575
$this->_Class =
76-
(self::$IntrospectionClasses[$_class] ?? null)
77-
?: (self::$IntrospectionClasses[$_class] =
76+
(self::$_IntrospectionClasses[$_class] ?? null)
77+
?: (self::$_IntrospectionClasses[$_class] =
7878
$this->getIntrospectionClass($class));
7979
}
8080
}

0 commit comments

Comments
 (0)