Skip to content

Commit c52f9a4

Browse files
Merge pull request #129 from limosa-io/feature/internal-filter-parser
Replace external SCIM parser with internal implementation
2 parents 620ee28 + 88c6187 commit c52f9a4

26 files changed

+1064
-320
lines changed

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
"php": "^8.0",
1414
"illuminate/database": "^10.0|^11.0|^12.0",
1515
"illuminate/support": "^10.0|^11.0|^12.0",
16-
"illuminate/console": "^10.0|^11.0|^12.0",
17-
"tmilos/scim-schema": "^0.1.0",
18-
"tmilos/scim-filter-parser": "^1.3"
16+
"illuminate/console": "^10.0|^11.0|^12.0"
1917
},
2018
"classmap": [
2119
"database/migrations"

composer.lock

Lines changed: 3 additions & 196 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Attribute/Attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use ArieTimmerman\Laravel\SCIMServer\SCIM\Schema;
99
use Illuminate\Database\Eloquent\Builder;
1010
use Illuminate\Database\Eloquent\Model;
11-
use Tmilos\ScimFilterParser\Ast\AttributePath;
11+
use ArieTimmerman\Laravel\SCIMServer\Filter\Ast\AttributePath as FilterAttributePath;
1212
use Illuminate\Support\Str;
1313

1414
class Attribute
@@ -207,7 +207,7 @@ public function getSchema()
207207
}
208208
}
209209

210-
public function getNode(?AttributePath $attributePath)
210+
public function getNode(?FilterAttributePath $attributePath)
211211
{
212212
if (empty($attributePath)) {
213213
return $this;

src/Filter/Ast/AttributePath.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace ArieTimmerman\Laravel\SCIMServer\Filter\Ast;
4+
5+
class AttributePath extends Node
6+
{
7+
public ?string $schema = null;
8+
9+
/** @var string[] */
10+
public array $attributeNames = [];
11+
12+
public function __construct(?string $schema = null, array $attributeNames = [])
13+
{
14+
$this->schema = $schema;
15+
$this->attributeNames = array_values($attributeNames);
16+
}
17+
18+
public function add(string $attributeName): void
19+
{
20+
$this->attributeNames[] = $attributeName;
21+
}
22+
23+
public function __toString(): string
24+
{
25+
$path = implode('.', $this->attributeNames);
26+
27+
if ($this->schema !== null && $this->schema !== '') {
28+
return $this->schema . ':' . $path;
29+
}
30+
31+
return $path;
32+
}
33+
34+
public function dump(): array
35+
{
36+
return [
37+
'AttributePath' => (string) $this,
38+
];
39+
}
40+
41+
public function shift(): ?string
42+
{
43+
return array_shift($this->attributeNames);
44+
}
45+
46+
/**
47+
* @return string[]
48+
*/
49+
public function getAttributeNames(): array
50+
{
51+
return $this->attributeNames;
52+
}
53+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace ArieTimmerman\Laravel\SCIMServer\Filter\Ast;
4+
5+
class ComparisonExpression extends Factor
6+
{
7+
public AttributePath $attributePath;
8+
9+
public string $operator;
10+
11+
public mixed $compareValue;
12+
13+
public function __construct(AttributePath $attributePath, string $operator, mixed $compareValue = null)
14+
{
15+
$this->attributePath = $attributePath;
16+
$this->operator = strtolower($operator);
17+
$this->compareValue = $compareValue;
18+
}
19+
20+
public function __toString(): string
21+
{
22+
if ($this->operator === 'pr') {
23+
return sprintf('%s %s', $this->attributePath, $this->operator);
24+
}
25+
26+
$value = $this->compareValue;
27+
if ($value instanceof \DateTimeInterface) {
28+
$value = $value->format('Y-m-d\TH:i:s\Z');
29+
} elseif (is_string($value)) {
30+
$value = '"' . $value . '"';
31+
} elseif (is_bool($value)) {
32+
$value = $value ? 'true' : 'false';
33+
} elseif ($value === null) {
34+
$value = 'null';
35+
}
36+
37+
return sprintf('%s %s %s', $this->attributePath, $this->operator, $value);
38+
}
39+
40+
public function dump(): array
41+
{
42+
return [
43+
'ComparisonExpression' => (string) $this,
44+
];
45+
}
46+
}

0 commit comments

Comments
 (0)