-
Notifications
You must be signed in to change notification settings - Fork 10
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
21 changed files
with
1,613 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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\generis\model\Context; | ||
|
||
use InvalidArgumentException; | ||
|
||
abstract class AbstractContext implements ContextInterface | ||
{ | ||
protected $parameters = []; | ||
|
||
public function __construct(array $parameters) | ||
{ | ||
foreach ($parameters as $parameter => $parameterValue) { | ||
$this->setParameter($parameter, $parameterValue); | ||
} | ||
} | ||
|
||
public function getParameter(string $parameter, $default = null) | ||
{ | ||
$this->checkParameterSupport($parameter); | ||
|
||
return $this->parameters[$parameter] ?? $default; | ||
} | ||
|
||
public function setParameter(string $parameter, $parameterValue): void | ||
{ | ||
$this->checkParameterSupport($parameter); | ||
$this->validateParameter($parameter, $parameterValue); | ||
|
||
$this->parameters[$parameter] = $parameterValue; | ||
} | ||
|
||
abstract protected function getSupportedParameters(): array; | ||
|
||
/** | ||
* @param mixed $parameterValue | ||
*/ | ||
abstract protected function validateParameter(string $parameter, $parameterValue): void; | ||
|
||
private function checkParameterSupport(string $parameter): void | ||
{ | ||
if (!in_array($parameter, $this->getSupportedParameters(), true)) { | ||
throw new InvalidArgumentException( | ||
sprintf( | ||
'Context parameter %s is not supported.', | ||
$parameter | ||
) | ||
); | ||
} | ||
} | ||
} |
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,38 @@ | ||
<?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\generis\model\Context; | ||
|
||
interface ContextInterface | ||
{ | ||
/** | ||
* @param mixed $default | ||
* | ||
* @return mixed | ||
*/ | ||
public function getParameter(string $parameter, $default = null); | ||
|
||
/** | ||
* @param mixed $parameterValue | ||
*/ | ||
public function setParameter(string $parameter, $parameterValue): void; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,27 +18,27 @@ | |
* Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg (under the project TAO & TAO2); | ||
* 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung (under the project TAO-TRANSFER); | ||
* 2009-2012 (update and modification) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV); | ||
* 2017 (update and modification) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* 2017-2021 (update and modification) Open Assessment Technologies SA. | ||
*/ | ||
|
||
use oat\generis\model\data\event\ClassDeletedEvent; | ||
use oat\generis\model\data\event\ResourceCreated; | ||
use oat\generis\model\OntologyRdf; | ||
use oat\generis\model\resource\ResourceCollection; | ||
use oat\oatbox\event\EventManager; | ||
use oat\oatbox\event\EventManagerAwareTrait; | ||
use oat\generis\model\data\event\ResourceCreated; | ||
use oat\generis\model\resource\ResourceCollection; | ||
use oat\generis\model\resource\Repository\ClassRepository; | ||
use oat\generis\model\resource\Context\ResourceRepositoryContext; | ||
use oat\generis\model\resource\Contract\ResourceRepositoryInterface; | ||
|
||
/** | ||
* The class of rdfs:classes. It implements basic tests like isSubClassOf(Class | ||
* instances, properties and subclasses retrieval, but also enable to edit it | ||
* setSubClassOf setProperty, etc. | ||
* | ||
* | ||
* @author [email protected] | ||
* @package generis | ||
* | ||
* @see http://www.w3.org/RDF/ | ||
* @see http://www.w3.org/TR/rdf-schema/ | ||
* | ||
*/ | ||
class core_kernel_classes_Class extends core_kernel_classes_Resource | ||
{ | ||
|
@@ -425,22 +425,30 @@ public function deleteInstances($resources, $deleteReference = false) | |
} | ||
|
||
/** | ||
* Short description of method delete | ||
* @deprecated Use \oat\generis\model\resource\Repository\ClassRepository::delete() instead | ||
* | ||
* @access public | ||
* @author Jerome Bogaerts, <[email protected]> | ||
* @param boolean deleteReference | ||
* @return boolean | ||
* | ||
* @param bool deleteReference | ||
* | ||
* @return bool | ||
*/ | ||
public function delete($deleteReference = false) | ||
{ | ||
$delete = (bool)$this->getImplementation()->delete($this, $deleteReference); | ||
|
||
if ($delete) { | ||
$this->getEventManager()->trigger(new ClassDeletedEvent($this)); | ||
try { | ||
$this->getClassRepository()->delete( | ||
new ResourceRepositoryContext( | ||
[ | ||
ResourceRepositoryContext::PARAM_CLASS => $this, | ||
ResourceRepositoryContext::PARAM_DELETE_REFERENCE => $deleteReference, | ||
] | ||
) | ||
); | ||
|
||
return true; | ||
} catch (Throwable $exception) { | ||
return false; | ||
} | ||
|
||
return $delete; | ||
} | ||
|
||
/** | ||
|
@@ -458,4 +466,9 @@ public function exists() | |
// we know that the class exists. | ||
return (bool) (count($this->getParentClasses(false)) > 0); | ||
} | ||
|
||
private function getClassRepository(): ResourceRepositoryInterface | ||
{ | ||
return $this->getServiceManager()->getContainer()->get(ClassRepository::class); | ||
} | ||
} |
Oops, something went wrong.