Skip to content

Commit

Permalink
migrates tools (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Nov 16, 2023
1 parent 7bc96a6 commit c4763e6
Show file tree
Hide file tree
Showing 304 changed files with 3,096 additions and 5,299 deletions.
18 changes: 18 additions & 0 deletions docs/sections/application/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@ title: Application
---

# Application

## Components

### Context

### DataSource

### Tool

### Widget

### Importer

### Exporter

### Planned Task

### Template
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Claroline\BigBlueButtonBundle\Entity\Recording;
use Claroline\BigBlueButtonBundle\Manager\BBBManager;
use Claroline\CoreBundle\API\Serializer\Resource\AbstractResourceSerializer;
use Claroline\CoreBundle\Component\Context\AdministrationContext;
use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler;
use Claroline\CoreBundle\Manager\Tool\ToolManager;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand All @@ -33,33 +34,14 @@ class AdministrationController
{
use RequestDecoderTrait;

/** @var AuthorizationCheckerInterface */
private $authorization;
/** @var PlatformConfigurationHandler */
private $config;
/** @var ObjectManager */
private $om;
/** @var Crud */
private $crud;
/** @var ToolManager */
private $toolManager;
/** @var BBBManager */
private $bbbManager;

public function __construct(
AuthorizationCheckerInterface $authorization,
PlatformConfigurationHandler $config,
ObjectManager $om,
Crud $crud,
ToolManager $toolManager,
BBBManager $bbbManager
private readonly AuthorizationCheckerInterface $authorization,
private readonly PlatformConfigurationHandler $config,
private readonly ObjectManager $om,
private readonly Crud $crud,
private readonly ToolManager $toolManager,
private readonly BBBManager $bbbManager
) {
$this->authorization = $authorization;
$this->config = $config;
$this->om = $om;
$this->crud = $crud;
$this->toolManager = $toolManager;
$this->bbbManager = $bbbManager;
}

/**
Expand Down Expand Up @@ -153,9 +135,9 @@ public function deleteRecordingsAction(Request $request): JsonResponse
return new JsonResponse(null, 204);
}

private function checkAccess()
private function checkAccess(): void
{
$integrationTool = $this->toolManager->getAdminToolByName('integration');
$integrationTool = $this->toolManager->getOrderedTool('integration', AdministrationContext::getName());
if (is_null($integrationTool) || !$this->authorization->isGranted('OPEN', $integrationTool)) {
throw new AccessDeniedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

class ClarolineBigBlueButtonInstaller extends AdditionalInstaller
{
public function hasMigrations(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

class ClarolinePeerTubeInstaller extends AdditionalInstaller
{
public function hasMigrations(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

class ClarolineYouTubeInstaller extends AdditionalInstaller
{
public function hasMigrations(): bool
{
return true;
}
}
64 changes: 29 additions & 35 deletions src/main/app/API/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class Crud
use PermissionCheckerTrait;

/** @var string */
const COLLECTION_ADD = 'add';
public const COLLECTION_ADD = 'add';
/** @var string */
const COLLECTION_REMOVE = 'remove';
public const COLLECTION_REMOVE = 'remove';
/** @var string */
const PROPERTY_SET = 'set';
public const PROPERTY_SET = 'set';
// TODO : remove me. only for retro compatibility it should be always the case
// but I don't know if it will break things if I do it now
const THROW_EXCEPTION = 'throw_exception';
public const THROW_EXCEPTION = 'throw_exception';

const NO_PERMISSIONS = 'NO_PERMISSIONS';
const NO_VALIDATION = 'NO_VALIDATION';
public const NO_PERMISSIONS = 'NO_PERMISSIONS';
public const NO_VALIDATION = 'NO_VALIDATION';

/** @var ObjectManager */
private $om;
Expand Down Expand Up @@ -98,12 +98,12 @@ public function get(string $class, $id, string $idProp = 'id', ?array $options =
return $object;
}

public function find(string $class, $data)
public function find(string $class, $data): ?object
{
return $this->om->getObject($data, $class, $this->schema->getIdentifiers($class));
}

public function list(string $class, array $query = [], array $options = [])
public function list(string $class, array $query = [], array $options = []): array
{
$results = $this->finder->searchEntities($class, $query);

Expand All @@ -118,22 +118,22 @@ public function list(string $class, array $query = [], array $options = [])
* Creates a new entry for `class` and populates it with `data`.
*
* @param mixed $classOrObject - the class of the entity to create or an instance of the entity
* @param mixed $data - the serialized data of the object to create
* @param array $data - the serialized data of the object to create
* @param array $options - additional creation options
*
* @return object|array
*
* @throws InvalidDataException
*/
public function create($classOrObject, $data, array $options = [])
public function create(mixed $classOrObject, array $data = [], array $options = []): mixed
{
if (is_string($classOrObject)) {
// class name received
$class = $classOrObject;
$object = new $classOrObject();
} else {
// object instance received
$class = get_class($classOrObject);
$class = $this->getRealClass($classOrObject);
$object = $classOrObject;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ public function create($classOrObject, $data, array $options = [])
*
* @throws InvalidDataException
*/
public function update($classOrObject, $data, array $options = [])
public function update(mixed $classOrObject, array $data, array $options = []): mixed
{
if (is_string($classOrObject)) {
// class name received
Expand All @@ -192,7 +192,7 @@ public function update($classOrObject, $data, array $options = [])
$oldObject = $this->om->getObject($data, $class, $this->schema->getIdentifiers($class) ?? []) ?? new $class();
} else {
// object instance received
$class = get_class($classOrObject);
$class = $this->getRealClass($classOrObject);
$oldObject = $classOrObject;
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public function update($classOrObject, $data, array $options = [])
* @param object $object - the entity to delete
* @param array $options - additional delete options
*/
public function delete($object, array $options = [])
public function delete(mixed $object, array $options = []): void
{
if (!in_array(static::NO_PERMISSIONS, $options)) {
$this->checkPermission('DELETE', $object, [], true);
Expand All @@ -264,12 +264,12 @@ public function delete($object, array $options = [])
* @param array $data - the list of entries to delete
* @param array $options - additional delete options
*/
public function deleteBulk(array $data, array $options = [])
public function deleteBulk(array $data, array $options = []): void
{
$this->om->startFlushSuite();

foreach ($data as $el) {
//get the element
// get the element
$this->delete($el, $options);
}

Expand All @@ -285,7 +285,7 @@ public function deleteBulk(array $data, array $options = [])
*
* @return object
*/
public function copy($object, array $options = [], array $extra = [])
public function copy(mixed $object, array $options = [], array $extra = []): mixed
{
if (!in_array(static::NO_PERMISSIONS, $options)) {
$this->checkPermission('COPY', $object, [], true);
Expand All @@ -308,7 +308,7 @@ public function copy($object, array $options = [], array $extra = [])

$this->om->persist($new);

//first event is the pre one
// first event is the pre one
if ($this->dispatch('copy', 'pre', [$object, $options, $new, $extra])) {
if (!in_array(Options::FORCE_FLUSH, $options)) {
$this->om->flush();
Expand All @@ -327,16 +327,14 @@ public function copy($object, array $options = [], array $extra = [])
*
* @param array $data - the list of entries to copy
* @param array $options - additional copy options
*
* @return array
*/
public function copyBulk(array $data, array $options = [])
public function copyBulk(array $data, array $options = []): array
{
$this->om->startFlushSuite();
$copies = [];

foreach ($data as $el) {
//get the element
// get the element
$copies[] = $this->copy($el, $options);
}

Expand All @@ -357,7 +355,7 @@ public function copyBulk(array $data, array $options = [])
* @todo only flush once (do not flush for each collection element)
* @todo only dispatch lifecycle events once with the full collection in param
*/
public function patch($object, string $property, string $action, array $elements, array $options = [])
public function patch(mixed $object, string $property, string $action, array $elements, array $options = []): mixed
{
$methodName = $action.ucfirst(strtolower($property));

Expand Down Expand Up @@ -408,7 +406,7 @@ public function patch($object, string $property, string $action, array $elements
*
* @deprecated should use standard update instead
*/
public function replace($object, string $property, $data, array $options = [])
public function replace(mixed $object, string $property, mixed $data, array $options = []): mixed
{
$methodName = 'set'.ucfirst($property);

Expand All @@ -417,9 +415,9 @@ public function replace($object, string $property, $data, array $options = [])
}

if (!in_array(static::NO_PERMISSIONS, $options)) {
//add the options to pass on here
// add the options to pass on here
$this->checkPermission('PATCH', $object, [], true);
//we'll need to pass the $action and $data here aswell later
// we'll need to pass the $action and $data here aswell later
}

if ($this->dispatch('patch', 'pre', [$object, $options, $property, $data, self::PROPERTY_SET])) {
Expand All @@ -442,28 +440,24 @@ public function replace($object, string $property, $data, array $options = [])
* Validates `data` with the available validator for `class`.
*
* @param string $class - the class of the entity used for validation
* @param mixed $data - the serialized data to validate
* @param array $data - the serialized data to validate
* @param string $mode - the validation mode
* @param array $options - the validation options
*
* @return array
*/
public function validate($class, $data, $mode, array $options = [])
public function validate(mixed $class, array $data, string $mode, array $options = []): array
{
return $this->validator->validate($class, $data, $mode, true, $options);
}

/**
* We dispatch 2 events: a generic one and an other with a custom name.
* We dispatch 2 events: a generic one and another with a custom name.
* Listen to what you want. Both have their uses.
*
* @param string $action (create, copy, delete, patch, update)
* @param string $when (post, pre)
* @param array $args the event arguments
*
* @return bool
*/
public function dispatch($action, $when, array $args)
public function dispatch(string $action, string $when, array $args): bool
{
$className = $this->getRealClass($args[0]);

Expand Down Expand Up @@ -500,7 +494,7 @@ public static function getEventName(string $action, string $when, string $classN
return $name;
}

private function getRealClass($object)
private function getRealClass($object): string
{
return $this->om->getMetadataFactory()->getMetadataFor(get_class($object))->getName();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/app/Component/AbstractComponentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public function getComponent(string $componentName): ComponentInterface
{
$components = $this->getRegisteredComponents();
foreach ($components as $component) {
if ($component->getShortName() === $componentName) {
if ($component::getName() === $componentName) {
return $component;
}
}

throw new \Exception(sprintf('Component %s can not be found. Maybe its plugin is disabled or the component service does not have the correct tag.', $componentName));
throw new \Exception(sprintf('Component %s can not be found. Maybe its plugin is disabled or the component service does not have the correct tag (expected tag : %s).', $componentName, static::getServiceTag()));
}

abstract protected function getRegisteredComponents(): iterable;
Expand Down
2 changes: 1 addition & 1 deletion src/main/app/Component/ComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
*/
interface ComponentInterface
{
public static function getShortName(): string;
public static function getName(): string;
}
12 changes: 0 additions & 12 deletions src/main/app/Component/ConfigurableInterface.php

This file was deleted.

23 changes: 17 additions & 6 deletions src/main/app/Component/Context/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

namespace Claroline\AppBundle\Component\Context;

use Claroline\CoreBundle\Manager\Tool\ToolManager;
use Claroline\AppBundle\Component\Tool\ToolProvider;

abstract class AbstractContext implements ContextInterface
{
protected readonly ToolManager $toolManager;
protected readonly ToolProvider $toolProvider;

public function setToolManager(ToolManager $toolManager): void
public function setToolProvider(ToolProvider $toolProvider): void
{
$this->toolManager = $toolManager;
$this->toolProvider = $toolProvider;
}

public function getTools(?string $contextId): array
public function getTools(?ContextSubjectInterface $contextSubject): array
{
return $this->toolManager->getOrderedTools(static::getShortName(), $contextId);
return $this->toolProvider->getEnabledTools(static::getName(), $contextSubject);
}

public function getShortcuts(?ContextSubjectInterface $contextSubject): array
{
// only supported by Workspace context atm
return [];
}

public function getAdditionalData(?ContextSubjectInterface $contextSubject): array
{
return [];
}
}
Loading

0 comments on commit c4763e6

Please sign in to comment.