Skip to content

Commit

Permalink
Merge pull request #56 from jorisdugue/v3
Browse files Browse the repository at this point in the history
feat(chore): v3
  • Loading branch information
jorisdugue authored Nov 9, 2024
2 parents a2ac3f1 + 2de2597 commit 78aa9f1
Show file tree
Hide file tree
Showing 39 changed files with 897 additions and 708 deletions.
50 changes: 41 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
name: CI
name: "CI Tests"

on: [push]
on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest

test:
runs-on: 'ubuntu-20.04'
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3']
symfony: ['6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*', '7.1.*']
composer-flags: ['--prefer-stable']
extensions: ['curl, iconv, mbstring, pdo, pdo_sqlite, sqlite, zip']
include:
- php: '8.2'
symfony: '6.0.*'
composer-flags: '--prefer-stable --prefer-lowest'
extensions: 'curl, iconv, mbstring, pdo, pdo_sqlite, sqlite, zip'
exclude:
- php: '8.2'
symfony: '6.0.*'
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
- name: Checkout Code
uses: actions/checkout@v4
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-symfony-${{ matrix.symfony }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
memory_limit: -1
php-version: ${{ matrix.php }}
tools: composer:v2, flex
extensions: ${{ matrix.extensions }}
coverage: none
- name: Install dependencies
run: composer update ${{ matrix.composer-flags }} --prefer-dist --no-suggest
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Run PHPUnit
run: vendor/bin/phpunit

13 changes: 13 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "CI Tests"

on: [push, pull_request]
jobs:
build-lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
with:
memory_limit: -1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ public/index.php
composer.lock
.DS_Store
.thumbs
.phpunit.cache
2 changes: 1 addition & 1 deletion Command/H5pBundleCleanUpFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class H5pBundleCleanUpFilesCommand extends Command
/**
* @var H5POptions $h5POptions
*/
private $h5POptions;
private H5POptions $h5POptions;

public function __construct(H5POptions $h5POptions)
{
Expand Down
19 changes: 9 additions & 10 deletions Command/H5pBundleIncludeAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
namespace Studit\H5PBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\KernelInterface;

class H5pBundleIncludeAssetsCommand extends Command
{
protected static $defaultName = 'h5p-bundle:IncludeAssetsCommand';
/** KernelInterface $appKernel */
private $appKernel;
private KernelInterface $appKernel;

/**
* @param KernelInterface $appKernel
Expand All @@ -26,7 +23,7 @@ public function __construct(KernelInterface $appKernel)
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setDescription(
Expand All @@ -39,16 +36,18 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->includeAssets($input->getOption('copy') ?? false);
return 0;
return Command::SUCCESS;
}

private function includeAssets(bool $copy): void
{
$projectDir = $this->appKernel->getProjectDir();

//get dir of vendor H5P
$fromDir = $projectDir . "/vendor/h5p/";

$fromDir = $this->appKernel->getProjectDir() . "/vendor/h5p/";
//call service
$toDir = $this->appKernel->getProjectDir() . '/public/bundles/studith5p/h5p/';
$toDir = $projectDir . '/public/bundles/studith5p/h5p/';

$coreSubDir = "h5p-core/";
$coreDirs = ["fonts", "images", "js", "styles"];
Expand All @@ -59,7 +58,7 @@ private function includeAssets(bool $copy): void
$this->createFiles($fromDir, $toDir, $editorSubDir, $editorDirs, $copy);
}

private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
private function createFiles(string $fromDir, string $toDir, string $subDir, array $subDirs, bool $copy): void
{
foreach ($subDirs as $dir) {
$src = $fromDir . $subDir . $dir;
Expand All @@ -71,7 +70,7 @@ private function createFiles($fromDir, $toDir, $subDir, $subDirs, $copy)
}
}

private function recurseCopy($src, $dst)
private function recurseCopy(string $src, string $dst): void
{
$dir = opendir($src);
// Restrict the permission to 0750 not upper
Expand Down
70 changes: 38 additions & 32 deletions Controller/H5PAJAXController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Attribute\Route;

/**
* @Route("/h5p/ajax")
*/
#[Route('/h5p/ajax')]
class H5PAJAXController extends AbstractController
{
protected $h5peditor;
protected $serviceh5poptions;
protected \H5peditor $h5peditor;
protected H5POptions $serviceh5poptions;

public function __construct(\H5peditor $h5peditor, H5POptions $h5poption)
{
$this->h5peditor = $h5peditor;
$this->serviceh5poptions = $h5poption;
}

#[Route('/libraries/')]

/**
* Callback that lists all h5p libraries.
*
* @Route("/libraries/")
* @param Request $request
* @param Request $request Current request
* @return JsonResponse
*/
public function librariesCallback(Request $request): JsonResponse
Expand All @@ -37,6 +36,7 @@ public function librariesCallback(Request $request): JsonResponse
if ($request->get('machineName')) {
return $this->libraryCallback($request);
}

//get editor
$editor = $this->h5peditor;
$editor->ajax->action(\H5PEditorEndpoints::LIBRARIES);
Expand All @@ -47,9 +47,11 @@ public function librariesCallback(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/content-type-cache/')]

/**
* Callback that returns the content type cache
* @Route("/content-type-cache/")
* Callback that returns the content type cache.
* @return JsonResponse
*/
public function contentTypeCacheCallback(): JsonResponse
{
Expand All @@ -63,15 +65,16 @@ public function contentTypeCacheCallback(): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/content-hub-metadata-cache')]

/**
* Callback that return the content hub metadata cache
* @Route("/content-hub-metadata-cache")
* @param Request $request
* Callback that return the content hub metadata cache.
* @param Request $request Current Request
* @return JsonResponse
*/
public function contentHubMetadataCache(Request $request): JsonResponse
{
$locale = $request->getLocale() != null ? $request->getLocale() : 'en';
$locale = $request->getLocale() !== null ? $request->getLocale() : 'en';
ob_start();

$editor = $this->h5peditor;
Expand All @@ -83,11 +86,11 @@ public function contentHubMetadataCache(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/translations/')]

/**
* Callback for translations
*
* Callback for translations.
* @param Request $request
* @Route("/translations/")
*
* @return JsonResponse
*/
Expand All @@ -105,13 +108,13 @@ public function TranslationsCallback(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/library-install/')]

/**
* Callback Install library from external file
*
* @param Request $request
* Callback Install library from external file.
* @param Request $request Current request
*
* @return JsonResponse
* @Route("/library-install/")
*/
public function libraryInstallCallback(Request $request): JsonResponse
{
Expand All @@ -131,9 +134,9 @@ public function libraryInstallCallback(Request $request): JsonResponse
}

/**
* Callback that returns data for a given library
* Callback that returns data for a given library.
*
* @param Request $request
* @param Request $request Current Request
* @return JsonResponse
*/
private function libraryCallback(Request $request): JsonResponse
Expand All @@ -142,7 +145,7 @@ private function libraryCallback(Request $request): JsonResponse

//$machineName, $majorVersion, $minorVersion, $languageCode, $prefix = '', $fileDir = '', $defaultLanguage
$editor = $this->h5peditor;
$locale = $request->getLocale() != null ? $request->getLocale() : 'en';
$locale = $request->getLocale() !== null ? $request->getLocale() : 'en';
$editor->ajax->action(
\H5PEditorEndpoints::SINGLE_LIBRARY,
$request->get('machineName'),
Expand All @@ -160,14 +163,15 @@ private function libraryCallback(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/library-upload/')]

/**
* Callback for uploading a library
* Callback for uploading a library.
*
* @param Request $request
* @param Request $request Current Request
*
* @return JsonResponse
* @throws Exception
* @Route("/library-upload/")
*/
public function libraryUploadCallback(Request $request): JsonResponse
{
Expand Down Expand Up @@ -195,19 +199,20 @@ public function libraryUploadCallback(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/files/')]

/**
* Callback for file uploads.
*
* @param Request $request
* @param Request $request Current request
* @return JsonResponse
* @Route("/files/")
*/
public function filesCallback(Request $request): JsonResponse
{
ob_start();

$editor = $this->h5peditor;
$id = $request->get('id') != null ? $request->get('id') : $request->get('contentId');
$id = $request->get('id') !== null ? $request->get('id') : $request->get('contentId');
$editor->ajax->action(
\H5PEditorEndpoints::FILES,
$request->get('token', 1),
Expand All @@ -220,12 +225,13 @@ public function filesCallback(Request $request): JsonResponse
return $this->json(json_decode($output, true));
}

#[Route('/filter/')]

/**
* Callback for filtering.
*
* @param Request $request
* @param Request $request Current request
* @return JsonResponse
* @Route("/filter/")
*/
public function filterCallback(Request $request): JsonResponse
{
Expand Down
Loading

0 comments on commit 78aa9f1

Please sign in to comment.