Skip to content

Commit

Permalink
Merge pull request #10 from lingoda/04-symfony5-service-requirements
Browse files Browse the repository at this point in the history
Fix Symfony5 services aliases and auto-wire problem
  • Loading branch information
jorisdugue committed Jun 23, 2020
2 parents 4abec14 + 94bcaaf commit 7a84265
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
31 changes: 19 additions & 12 deletions Controller/H5PController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Studit\H5PBundle\Controller;

use Studit\H5PBundle\Core\H5POptions;
use Studit\H5PBundle\Editor\LibraryStorage;
use Studit\H5PBundle\Entity\Content;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand All @@ -19,9 +21,14 @@ class H5PController extends AbstractController
{

protected $h5PIntegrations;
public function __construct(H5PIntegration $h5PIntegration)
{
protected $libraryStorage;

public function __construct(
H5PIntegration $h5PIntegration,
LibraryStorage $libraryStorage
) {
$this->h5PIntegrations = $h5PIntegration;
$this->libraryStorage = $libraryStorage;
}

/**
Expand All @@ -39,21 +46,21 @@ public function listAction()
* @param Content $content
* @return Response
*/
public function showAction(Content $content)
public function showAction(Content $content, \H5PCore $h5PCore, H5POptions $h5POptions)
{
$h5pIntegration = $this->get('studit_h5p.integration')->getGenericH5PIntegrationSettings();
$h5pIntegration = $this->h5PIntegrations->getGenericH5PIntegrationSettings();
$contentIdStr = 'cid-' . $content->getId();
$h5pIntegration['contents'][$contentIdStr] = $this->get('studit_h5p.integration')->getH5PContentIntegrationSettings($content);
$preloaded_dependencies = $this->get('studit_h5p.core')->loadContentDependencies($content->getId(), 'preloaded');
$files = $this->get('studit_h5p.core')->getDependenciesFiles($preloaded_dependencies, $this->get('studit_h5p.options')->getRelativeH5PPath());
$h5pIntegration['contents'][$contentIdStr] = $this->h5PIntegrations->getH5PContentIntegrationSettings($content);
$preloaded_dependencies = $h5PCore->loadContentDependencies($content->getId(), 'preloaded');
$files = $h5PCore->getDependenciesFiles($preloaded_dependencies, $h5POptions->getRelativeH5PPath());
if ($content->getLibrary()->isFrame()) {
$jsFilePaths = array_map(function ($asset) {
return $asset->path;
}, $files['scripts']);
$cssFilePaths = array_map(function ($asset) {
return $asset->path;
}, $files['styles']);
$coreAssets = $this->get('studit_h5p.integration')->getCoreAssets();
$coreAssets = $this->h5PIntegrations->getCoreAssets();
$h5pIntegration['core']['scripts'] = $coreAssets['scripts'];
$h5pIntegration['core']['styles'] = $coreAssets['styles'];
$h5pIntegration['contents'][$contentIdStr]['scripts'] = $jsFilePaths;
Expand Down Expand Up @@ -94,20 +101,20 @@ private function handleRequest(Request $request, Content $content = null)
//get data
$data = $form->getData();
//create h5p content
$contentId = $this->get('studit_h5p.library_storage')->storeLibraryData($data['library'], $data['parameters'], $content);
$contentId = $this->libraryStorage->storeLibraryData($data['library'], $data['parameters'], $content);
return $this->redirectToRoute('studit_h5p_h5p_show', ['content' => $contentId]);
}
$h5pIntegration = $this->h5PIntegrations->getEditorIntegrationSettings($content ? $content->getId() : null);
return $this->render('@StuditH5P/edit.html.twig', ['form' => $form->createView(), 'h5pIntegration' => $h5pIntegration, 'h5pCoreTranslations' => $this->get('studit_h5p.integration')->getTranslationFilePath()]);
return $this->render('@StuditH5P/edit.html.twig', ['form' => $form->createView(), 'h5pIntegration' => $h5pIntegration, 'h5pCoreTranslations' => $this->h5PIntegrations->getTranslationFilePath()]);
}
/**
* @Route("delete/{contentId}")
* @param integer $contentId
* @return RedirectResponse
*/
public function deleteAction($contentId)
public function deleteAction($contentId, \H5PStorage $h5PStorage)
{
$this->get('studit_h5p.storage')->deletePackage([
$h5PStorage->deletePackage([
'id' => $contentId,
'slug' => 'interactive-content'
]);
Expand Down
13 changes: 11 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ services:
studit_h5p.options:
class: Studit\H5PBundle\Core\H5POptions
arguments: [~, '%kernel.project_dir%', '@doctrine.orm.entity_manager']
Studit\H5PBundle\Core\H5POptions:
arguments: [~, '%kernel.project_dir%', '@doctrine.orm.entity_manager']
Studit\H5PBundle\Core\H5POptions: '@studit_h5p.options'

studit_h5p.editor_storage:
class: Studit\H5PBundle\Editor\EditorStorage
Expand All @@ -18,14 +17,17 @@ services:
studit_h5p.interface:
class: Studit\H5PBundle\Core\H5PSymfony
arguments: ['@studit_h5p.options', '@studit_h5p.editor_storage','@security.token_storage', '@doctrine.orm.entity_manager', '@session.flash_bag', '@security.authorization_checker', '@event_dispatcher', '@router.default']
Studit\H5PBundle\Core\H5PSymfony: '@studit_h5p.interface'

studit_h5p.core:
class: H5PCore
arguments: ['@studit_h5p.interface', ~, ~]
H5PCore: '@studit_h5p.core'

studit_h5p.editor_ajax:
class: Studit\H5PBundle\Editor\EditorAjax
arguments: ['@doctrine.orm.entity_manager', '@security.token_storage']
Studit\H5PBundle\Editor\EditorAjax: '@studit_h5p.editor_ajax'

studit_h5p.editor:
class: H5peditor
Expand All @@ -35,18 +37,22 @@ services:
studit_h5p.validator:
class: H5PValidator
arguments: ['@studit_h5p.interface', '@studit_h5p.core']
H5PValidator: '@studit_h5p.validator'

studit_h5p.storage:
class: H5PStorage
arguments: ['@studit_h5p.interface', '@studit_h5p.core']
H5PStorage: '@studit_h5p.storage'

studit_h5p.contentvalidator:
class: H5PContentValidator
arguments: ['@studit_h5p.interface', '@studit_h5p.core']
H5PContentValidator: '@studit_h5p.contentvalidator'

studit_h5p.export:
class: H5PExport
arguments: ['@studit_h5p.interface', '@studit_h5p.core']
H5PExport: '@studit_h5p.export'

studit_h5p.integration:
class: Studit\H5PBundle\Core\H5PIntegration
Expand All @@ -56,16 +62,19 @@ services:
studit_h5p.library_storage:
class: Studit\H5PBundle\Editor\LibraryStorage
arguments: ['@studit_h5p.core', '@studit_h5p.editor', '@doctrine.orm.entity_manager']
Studit\H5PBundle\Editor\LibraryStorage: '@studit_h5p.library_storage'

studit_h5p.twig.h5p_extension:
class: Studit\H5PBundle\Twig\H5PExtension
arguments: ['@studit_h5p.integration']
tags:
- { name: twig.extension }
Studit\H5PBundle\Twig\H5PExtension: '@studit_h5p.twig.h5p_extension'

studit_h5p.result_storage:
class: Studit\H5PBundle\Service\ResultService
arguments: ['@service_container']
Studit\H5PBundle\Service\ResultService: '@studit_h5p.result_storage'

Studit\H5PBundle\Command\H5pBundleIncludeAssetsCommand:
autowire: true
Expand Down

0 comments on commit 7a84265

Please sign in to comment.