-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
model/Metadata/ServiceProvider/MetadataServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoAdvancedSearch\model\Metadata\ServiceProvider; | ||
|
||
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface; | ||
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use function Symfony\Component\DependencyInjection\Loader\Configurator\param; | ||
|
||
class MetadataServiceProvider implements ContainerServiceProviderInterface | ||
{ | ||
public function __invoke(ContainerConfigurator $configurator): void | ||
{ | ||
$this->setParameters($configurator); | ||
|
||
$services = $configurator->services(); | ||
|
||
$services->set(PropertyAllowedSpecification::class, PropertyAllowedSpecification::class) | ||
->args( | ||
[ | ||
param(PropertyAllowedSpecification::CONFIG_BLACK_LIST) | ||
] | ||
)->public(); | ||
} | ||
|
||
private function setParameters(ContainerConfigurator $configurator): void | ||
{ | ||
$parameters = $configurator->parameters(); | ||
$parameters->set( | ||
PropertyAllowedSpecification::CONFIG_BLACK_LIST, | ||
array_filter( | ||
explode( | ||
',', | ||
(string)getenv(PropertyAllowedSpecification::CONFIG_BLACK_LIST) | ||
) | ||
) | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
model/Metadata/Specification/PropertyAllowedSpecification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoAdvancedSearch\model\Metadata\Specification; | ||
|
||
class PropertyAllowedSpecification | ||
{ | ||
public const CONFIG_BLACK_LIST = 'ADVANCED_SEARCH_METADATA_BLACK_LIST'; | ||
|
||
private const SYSTEM_PROPERTIES = [ | ||
'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel', | ||
'http://www.w3.org/2000/01/rdf-schema#comment', | ||
'http://www.w3.org/2000/01/rdf-schema#isDefinedBy', | ||
'http://www.w3.org/2000/01/rdf-schema#seeAlso', | ||
'http://www.w3.org/1999/02/22-rdf-syntax-ns#value', | ||
'http://www.tao.lu/Ontologies/TAOTest.rdf#TestModel', | ||
'http://www.tao.lu/Ontologies/TAOTest.rdf#TestTestModel', | ||
'http://www.tao.lu/Ontologies/generis.rdf#userDefLg', | ||
]; | ||
|
||
/** @var array */ | ||
private $blackListUris; | ||
|
||
public function __construct(array $blackListUris = []) | ||
{ | ||
$this->blackListUris = array_merge($blackListUris, self::SYSTEM_PROPERTIES); | ||
} | ||
|
||
public function isSatisfiedBy(string $propertyUri): bool | ||
{ | ||
return !in_array($propertyUri, $this->blackListUris, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
tests/Unit/Metadata/Specification/PropertyAllowedSpecificationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoAdvancedSearch\tests\Unit\model\Metadata\Normalizer; | ||
|
||
use oat\generis\test\TestCase; | ||
use oat\taoAdvancedSearch\model\Metadata\Specification\PropertyAllowedSpecification; | ||
|
||
class PropertyAllowedSpecificationTest extends TestCase | ||
{ | ||
private const PROPERTY_FORBIDDEN = 'forbidden'; | ||
|
||
/** @var PropertyAllowedSpecification */ | ||
private $subject; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->subject = new PropertyAllowedSpecification( | ||
[ | ||
self::PROPERTY_FORBIDDEN, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider getDataProvider | ||
*/ | ||
public function testIsSatisfiedBy(bool $expected, string $property): void | ||
{ | ||
$this->assertSame($expected, $this->subject->isSatisfiedBy($property)); | ||
} | ||
|
||
public function getDataProvider(): array | ||
{ | ||
return [ | ||
'with allowed properties' => [ | ||
true, | ||
'anyUriHere' | ||
], | ||
'with not allowed properties' => [ | ||
false, | ||
self::PROPERTY_FORBIDDEN | ||
], | ||
'with not allowed system properties' => [ | ||
false, | ||
'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel' | ||
], | ||
]; | ||
} | ||
} |