Skip to content

Instantly share code, notes, and snippets.

View koertho's full-sized avatar

Thomas koertho

View GitHub Profile
@koertho
koertho / CustomPageController.php
Last active April 10, 2026 20:59
Contao 5 Page Controller with Layout. Use Custom Controller and Templates within the contao layout. Build with reusable trait. Example replace the main section of the template. You can also replace another section and activate the content composition and add article to other template sections.
<?php
namespace App\Controller\Page;
use Contao\CoreBundle\Controller\AbstractController;
use Contao\CoreBundle\DependencyInjection\Attribute\AsPage;
use Contao\PageModel;
use Symfony\Component\HttpFoundation\Request;
#[AsPage(type: 'custom_page',path: '/custom', contentComposition: false,)]
@koertho
koertho / CreateLocalCopyWithVfsController.php
Last active February 13, 2025 08:15
Create a local copy with absolute Path from a Contao VirtualFileSystem file.
namespace App\Controller;
use Contao\CoreBundle\Filesystem\VirtualFilesystemInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Filesystem\Filesystem;
class CreateLocalCopyWithVfsController
{
private readonly VirtualFilesystemInterface $filesStorage;
private readonly ParameterBagInterface $parameterBag;
@koertho
koertho / wsl_setup.md
Last active November 27, 2019 20:28
Windows WSL Setup

WSL Setup

Windows Linux subsystem setup.

Setup MySQL

sudo apt-get install mariadb-server
sudo service mysql start
sudo mysql_secure_installation
@koertho
koertho / testPrivateMethodsAndPropertiesWithPhpUnit.php
Created March 20, 2018 08:20
How to test private methods and set private properties with phpunit
<?php
// Test private methid
$reflectionClass = new \ReflectionClass(TestClass::class);
$testMethod = $reflectionClass->getMethod('testMethod');
$testMethod->setAccessible(true);
$testingClass = new TestClass();
@koertho
koertho / originalMethodWithMockTest.php
Last active March 14, 2018 10:24
Test original method without using the constructor in PHPUnit (usefull for Model or Module testing in Contao)
<?php
class ModelTest extends TestCase
{
public function getModelMock ()
{
// The key is the null value to setMethod (default is [] which mocks all methods).
$model = $this->getMockBuilder(FieldPaletteModel::class)->setMethods(null)->disableOriginalConstructor()->getMock();
}
}