Skip to content

Commit 573f85b

Browse files
committed
Close #104
1 parent 91796e4 commit 573f85b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Schema/SchemaProvider.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,19 @@ public function __construct(SchemaFactoryInterface $factory, ContainerInterface
8484
throw new InvalidArgumentException(T::t('Resource type is not set for Schema \'%s\'.', [static::class]));
8585
}
8686

87-
$isOk = (is_string($this->selfSubUrl) === true && empty($this->selfSubUrl) === false);
88-
if ($isOk === false) {
89-
throw new InvalidArgumentException(T::t('\'Self\' sub-url is not set for Schema \'%s\'.', [static::class]));
87+
if ($this->selfSubUrl === null) {
88+
$this->selfSubUrl = '/' . $this->resourceType . '/';
89+
} else {
90+
$isOk =
91+
is_string($this->selfSubUrl) === true &&
92+
empty($this->selfSubUrl) === false &&
93+
$this->selfSubUrl[0] === '/' &&
94+
$this->selfSubUrl[strlen($this->selfSubUrl) - 1] == '/';
95+
96+
if ($isOk === false) {
97+
$message = T::t('\'Self\' sub-url set incorrectly for Schema \'%s\'.', [static::class]);
98+
throw new InvalidArgumentException($message);
99+
}
90100
}
91101

92102
$this->factory = $factory;

tests/Data/CommentSchema.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class CommentSchema extends DevSchemaProvider
2828
*/
2929
protected $resourceType = 'comments';
3030

31-
/**
32-
* @inheritdoc
33-
*/
34-
protected $selfSubUrl = '/comments/';
35-
3631
/**
3732
* @inheritdoc
3833
*/

0 commit comments

Comments
 (0)