Skip to content

Commit

Permalink
Merge branch 'release/v0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Oct 18, 2023
2 parents e1a2afb + 304610f commit 8aa1e1d
Show file tree
Hide file tree
Showing 54 changed files with 34 additions and 48 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.4.0 (2023-10-18)
* Refactored main interface methods
* Refactored package file structure

## v0.3.9 (2023-09-26)
* Converted phpstan doc comments to generic

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ Direct value sanitisation can be achieved quickly and painlessly:
use DecodeLabs\Lucid;

// This ensures the value is a string
$myString = Lucid::make('This is a string', 'string');
$myString = Lucid::cast('string', 'This is a string');

// This is nullable
$notAString = Lucid::make(null, '?string');
$notAString = Lucid::cast('?string', null);

// These are constraints - throws an exception
$myString = Lucid::make('My very long piece of text', 'string', [
$myString = Lucid::cast('string', 'My very long piece of text', [
'maxLength' => 10,
'maxWords' => 4
]);

// Creates an instance of Carbon (DateTime)
$myDate = Lucid::make('tomorrow', 'date', [
$myDate = Lucid::cast('date','tomorrow', [
'min' => 'yesterday',
'max' => '+3 days'
]);
Expand All @@ -69,7 +69,7 @@ if(!$result->isValid()) {
Or conversely if you just need a yes or no answer, use <code>is()</code>:

```php
if(!Lucid::is('not a number', 'float')) {
if(!Lucid::is('float', 'not a number')) {
// do something
}
```
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"name": "decodelabs/lucid",
"description": "Flexible and expansive sanitisation and validation framework",
"type": "library",
"keywords": ["validation", "sanitisation", "input"],
"keywords": [ "validation", "sanitisation", "input" ],
"license": "MIT",
"authors": [{
"name": "Tom Wright",
"email": "[email protected]"
}],
"authors": [ {
"name": "Tom Wright",
"email": "[email protected]"
} ],
"require": {
"php": "^8.0",

"decodelabs/archetype": "^0.2",
"decodelabs/coercion": "^0.2.2",
"decodelabs/dictum": "^0.5",
"decodelabs/exceptional": "^0.4",
"decodelabs/lucid-support": "^0.2.1",
"decodelabs/lucid-support": "^0.3",
"decodelabs/veneer": "^0.10.10",

"nesbot/carbon": "^2.25"
Expand All @@ -31,16 +31,15 @@
},
"autoload": {
"psr-4": {
"DecodeLabs\\Archetype\\": "src/Archetype/",
"DecodeLabs\\Lucid\\": "src/Lucid/"
"DecodeLabs\\Lucid\\": "src/"
},
"files": [
"src/global.php"
"src/Context.php"
]
},
"extra": {
"branch-alias": {
"dev-develop": "0.3.x-dev"
"dev-develop": "0.4.x-dev"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

declare(strict_types=1);

namespace DecodeLabs\Archetype\Resolver;
namespace DecodeLabs\Lucid;

use DecodeLabs\Archetype\Resolver;
use DecodeLabs\Lucid\Constraint;

class LucidConstraint implements Resolver
class ConstraintResolver implements Resolver
{
/**
* Get mapped interface
Expand Down
10 changes: 10 additions & 0 deletions src/Lucid/Context.php → src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

namespace DecodeLabs\Lucid;

use DecodeLabs\Archetype;
use DecodeLabs\Lucid;
use DecodeLabs\Lucid\Provider\DirectContext;
use DecodeLabs\Lucid\Provider\DirectContextTrait;
use DecodeLabs\Lucid\Sanitizer\ValueContainer;
use DecodeLabs\Veneer;

/**
* @template TValue
Expand All @@ -25,3 +28,10 @@ public function newSanitizer(mixed $value): Sanitizer
return new ValueContainer($value);
}
}


// Veneer
Veneer::register(Context::class, Lucid::class);

// Load Archetype Constraint Resolver
Archetype::register(new ConstraintResolver());
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions src/global.php

This file was deleted.

8 changes: 4 additions & 4 deletions stubs/DecodeLabs/Lucid.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class Lucid implements Proxy
public static function newSanitizer(mixed $value): Ref0 {
return static::$instance->newSanitizer(...func_get_args());
}
public static function make(mixed $value, string $type, Ref1|array|null $setup = NULL): mixed {
return static::$instance->make(...func_get_args());
public static function cast(string $type, mixed $value, Ref1|array|null $setup = NULL): mixed {
return static::$instance->cast(...func_get_args());
}
public static function validate(mixed $value, string $type, Ref1|array|null $setup = NULL): Ref2 {
public static function validate(string $type, mixed $value, Ref1|array|null $setup = NULL): Ref2 {
return static::$instance->validate(...func_get_args());
}
public static function is(mixed $value, string $type, Ref1|array|null $setup = NULL): bool {
public static function is(string $type, mixed $value, Ref1|array|null $setup = NULL): bool {
return static::$instance->is(...func_get_args());
}
public static function sanitize(mixed $value): Ref0 {
Expand Down

0 comments on commit 8aa1e1d

Please sign in to comment.