Skip to content

Instantly share code, notes, and snippets.

View wazum's full-sized avatar
😼
I may be slow to respond.

Wolfgang Klinger wazum

😼
I may be slow to respond.
View GitHub Profile
@wazum
wazum / cropVariantsInUserFunction.php
Created March 4, 2020 15:03
Create an image with a specific cropping variant in a TYPO3 user function or similar
<?php
$contentObjectRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$filesContent = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\FilesContentObject::class,
$contentObjectRenderer);
$filesConfiguration = [
'references' => '50', // this is a UID from sys_file_reference
'renderObj' => 'IMAGE',
'renderObj.' => [
'file' => '50', // this is the same UID as above
@wazum
wazum / aspect_ratio.php
Last active October 26, 2023 13:41
PHP Calculate aspect ratio from width and height
<?php
function getAspectRatio(int $width, int $height)
{
// search for greatest common divisor
$greatestCommonDivisor = static function($width, $height) use (&$greatestCommonDivisor) {
return ($width % $height) ? $greatestCommonDivisor($height, $width % $height) : $height;
};
$divisor = $greatestCommonDivisor($width, $height);
@wazum
wazum / MyBatchHandler.php
Created August 1, 2022 05:14
Symfony Batch Handler example
<?php
class MyBatchHandler implements BatchHandlerInterface
{
use BatchHandlerTrait;
public function __invoke(MyMessage $message, Acknowledger $ack = null)
{
return $this->handle($message, $ack);
}
@wazum
wazum / MyBatchHandler.php
Created July 30, 2022 12:27
My Batch Handler Solr example
<?php
$documents = [];
foreach ($jobs as [$job, $ack]) {
try {
$documents[] = $this->solrService->createDocument($job->something());
$ack->ack($job);
} catch (\Exception $e) {
$ack->nack($e);
}
@wazum
wazum / HandleMessageMiddleware.php
Created July 30, 2022 09:23
Symfony Handle Message Middleware AckStamp
<?php
/** @var AckStamp $ackStamp */
if ($batchHandler && $ackStamp = $envelope->last(AckStamp::class)) {
$ack = new Acknowledger(get_debug_type($batchHandler), static function (\Throwable $e = null, $result = null) use ($envelope, $ackStamp, $handlerDescriptor) {
if (null !== $e) {
$e = new HandlerFailedException($envelope, [$e]);
} else {
$envelope = $envelope->with(HandledStamp::fromDescriptor($handlerDescriptor, $result));
<?php
declare(strict_types=1);
namespace App\Something\Infrastructure\Doctrine\EventSubscriber;
use App\Something\Domain\Contracts\ContainsNullableEmbeddable;
use App\Something\Domain\Contracts\NullableEmbeddable as NullableEmbeddableInterface;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
<?php
declare(strict_types=1);
namespace App\Something\Domain\Entity;
/**
* @ORM\Entity
*/
class Person extends DomainEntity implements ContainsNullableEmbeddable
<?php
declare(strict_types=1);
namespace App\Something\Domain\ValueObject;
use Webmozart\Assert\Assert;
/**
* @Embeddable
<?php
declare(strict_types=1);
namespace App\Something\Domain\Contracts;
interface ContainsNullableEmbeddable
{
}
<?php
declare(strict_types=1);
namespace App\Something\Domain\Contracts;
interface NullableEmbeddable
{
}