getClass($uri); return $resource->hasType($this->getRootClass()); } /** * * @author Patrick Plichart, patrick@taotesting.com * return tao_models_classes_ClassService */ abstract protected function getClassService(); /** * * @author Patrick Plichart, patrick@taotesting.com * return core_kernel_classes_Class */ protected function getRootClass() { return $this->getClassService()->getRootClass(); } /** * * @param string uri * @throws common_Exception_NoContent * @throws common_exception_InvalidArgumentType * @return object */ public function get($uri) { if (!common_Utils::isUri($uri)) { throw new common_exception_InvalidArgumentType(); } if (!($this->isInScope($uri))) { throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class"); } $resource = $this->getResource($uri); $formater = new core_kernel_classes_ResourceFormatter(); return $formater->getResourceDescription($resource, false); } /** * * @author Patrick Plichart, patrick@taotesting.com * @return stdClass */ public function getAll() { $formater = new core_kernel_classes_ResourceFormatter(); $resources = []; foreach ($this->getRootClass()->getInstances(true) as $resource) { $resources[] = $formater->getResourceDescription($resource, false); } return $resources; } /** * * @author Patrick Plichart, patrick@taotesting.com * @param string $uri * @throws common_exception_InvalidArgumentType * @throws common_exception_PreConditionFailure * @throws common_exception_NoContent */ public function delete($uri) { if (!common_Utils::isUri($uri)) { throw new common_exception_InvalidArgumentType(); } if (!($this->isInScope($uri))) { throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class"); } $resource = $this->getResource($uri); // if the resource does not exist, indicate a not found exception if (count($resource->getRdfTriples()->sequence) == 0) { throw new common_exception_NoContent(); } $resource->delete(); } /** * * @author Patrick Plichart, patrick@taotesting.com */ public function deleteAll() { foreach ($this->getRootClass()->getInstances(true) as $resource) { $resource->delete(); } } /** * * @author Patrick Plichart, patrick@taotesting.com * @param string $label * @param string $type * @param array $propertiesValues * @return core_kernel_classes_Resource */ public function create($label = "", $type = null, $propertiesValues = []) { $type = (isset($type)) ? $this->getClass($type) : $this->getRootClass(); $resource = $this->getClassService()->createInstance($type, $label); $resource->setPropertiesValues($propertiesValues); return $resource; } /** * * @author Patrick Plichart, patrick@taotesting.com * @param string $uri * @param array $propertiesValues * @throws common_exception_InvalidArgumentType * @throws common_exception_PreConditionFailure * @throws common_exception_NoContent * @return core_kernel_classes_Resource */ public function update($uri, $propertiesValues = []) { if (!common_Utils::isUri($uri)) { throw new common_exception_InvalidArgumentType(); } if (!($this->isInScope($uri))) { throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class"); } $resource = $this->getResource($uri); // if the resource does not exist, indicate a not found exception if (count($resource->getRdfTriples()->sequence) == 0) { throw new common_exception_NoContent(); } foreach ($propertiesValues as $uri => $parameterValue) { $resource->editPropertyValues($this->getProperty($uri), $parameterValue); } return $resource; } }