Skip to content

Commit

Permalink
Merge pull request #116 from getherbie/2.x-develop
Browse files Browse the repository at this point in the history
2.x develop
  • Loading branch information
tbreuss committed Dec 28, 2022
2 parents f75df2b + ddba464 commit 61545d3
Show file tree
Hide file tree
Showing 125 changed files with 2,175 additions and 2,142 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"autoload": {
"psr-4": {
"herbie\\": "system",
"herbie\\sysplugin\\": "plugins"
"herbie\\sysplugins\\": "plugins"
},
"files": [
"system/functions.php"
Expand All @@ -47,7 +47,7 @@
"autoload-dev": {
"psr-4": {
"website\\site\\": "website/site",
"tests\\": "tests"
"herbie\\tests\\": "tests"
}
},
"require-dev": {
Expand Down
5 changes: 2 additions & 3 deletions plugins/dummy/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace herbie\sysplugin\dummy;
namespace herbie\sysplugins\dummy;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,8 +16,7 @@ final class DummyCommand extends Command
protected function configure(): void
{
$this
->setHelp('This command allows you to create a user...')
;
->setHelp('This command allows you to create a user...');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
40 changes: 21 additions & 19 deletions plugins/dummy/DummySysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace herbie\sysplugin\dummy;

use herbie\event\ContentRenderedEvent;
use herbie\event\LayoutRenderedEvent;
use herbie\event\PluginsInitializedEvent;
use herbie\event\RenderLayoutEvent;
use herbie\event\RenderSegmentEvent;
use herbie\event\ResponseEmittedEvent;
use herbie\event\ResponseGeneratedEvent;
use herbie\event\TranslatorInitializedEvent;
use herbie\event\TwigInitializedEvent;
namespace herbie\sysplugins\dummy;

use herbie\events\ContentRenderedEvent;
use herbie\events\LayoutRenderedEvent;
use herbie\events\PluginsInitializedEvent;
use herbie\events\RenderLayoutEvent;
use herbie\events\RenderSegmentEvent;
use herbie\events\ResponseEmittedEvent;
use herbie\events\ResponseGeneratedEvent;
use herbie\events\TranslatorInitializedEvent;
use herbie\events\TwigInitializedEvent;
use herbie\PluginInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -109,11 +109,6 @@ public function twigTests(): array
];
}

private function wrapHtmlBlock(string $class, string $content): string
{
return "<div class='$class' style='display:none'>" . $content . "</div>";
}

public function onRenderLayout(RenderLayoutEvent $event): void
{
$this->logger->debug(__METHOD__);
Expand All @@ -125,6 +120,11 @@ public function onRenderLayout(RenderLayoutEvent $event): void
$event->setContent($content);
}

private function wrapHtmlBlock(string $class, string $content): string
{
return "<div class='$class' style='display:none'>" . $content . "</div>";
}

public function onRenderSegment(RenderSegmentEvent $event): void
{
$this->logger->debug(__METHOD__);
Expand Down Expand Up @@ -171,9 +171,11 @@ public function onTwigInitialized(TwigInitializedEvent $event): void
public function onTwigInitializedAddFilter(TwigInitializedEvent $event): void
{
$this->logger->debug(__METHOD__);
$event->getEnvironment()->addFilter(new TwigFilter('dummy_dynamic', function (string $content): string {
return $content . 'Dummy Filter Dynamic';
}));
$event->getEnvironment()->addFilter(
new TwigFilter('dummy_dynamic', function (string $content): string {
return $content . 'Dummy Filter Dynamic';
})
);
}

public function appMiddleware(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
Expand Down
2 changes: 1 addition & 1 deletion plugins/dummy/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use herbie\sysplugin\dummy\DummySysPlugin;
use herbie\sysplugins\dummy\DummySysPlugin;

return [
'apiVersion' => 2,
Expand Down
89 changes: 45 additions & 44 deletions plugins/imagine/ImagineSysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

declare(strict_types=1);

namespace herbie\sysplugin\imagine;
namespace herbie\sysplugins\imagine;

use herbie\Alias;
use herbie\Config;
use herbie\Plugin;
use Imagine\Filter\Advanced\RelativeResize;
use Imagine\Filter\Basic\Resize;
use Imagine\Gd\Imagine;
use Imagine\Image\ImageInterface;
use Imagine\Image\Box;
use Imagine\Image\Color;
use Imagine\Image\ImageInterface;
use Imagine\Image\Point;
use Imagine\Filter\Advanced\RelativeResize;
use Imagine\Filter\Basic\Resize;
use InvalidArgumentException;
use Twig\Markup;

use function herbie\str_trailing_slash;
Expand Down Expand Up @@ -92,27 +93,16 @@ private function getTransparentOnePixelSrc(): string
{
// see http://png-pixel.com
return 'data:image/png;'
. 'base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
. 'base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
}

/**
* Gets the browser path for the image and filter to apply.
*/
public function imagineFilter(string $path, string $collection = 'default'): Markup
protected function buildHtmlAttributes(array $htmlOptions = []): string
{
$absolutePath = $this->alias->get('@media/' . $path);

if (!is_file($absolutePath)) {
$dataSrc = $this->getTransparentOnePixelSrc();
return new Markup($dataSrc, 'utf8');
$attributes = '';
foreach ($htmlOptions as $key => $value) {
$attributes .= ' ' . $key . '="' . $value . '"';
}

$sanitizedFilterSet = $this->sanitizeFilterName($collection);

return new Markup(
$this->basePath . $this->applyFilterSet($path, $sanitizedFilterSet),
'utf8'
);
return rtrim($attributes);
}

private function sanitizeFilterName(string $filterSet): string
Expand All @@ -125,18 +115,6 @@ private function sanitizeFilterName(string $filterSet): string
return $filterSet;
}

private function getImageSize(string $cachePath): array
{
if (!is_file($cachePath)) {
return [];
}
$size = getimagesize($cachePath);
if ($size === false) {
return [0, 0];
}
return [$size[0], $size[1]];
}

protected function applyFilterSet(string $relpath, string $filterSet): string
{
$path = $this->alias->get('@media/' . $relpath);
Expand Down Expand Up @@ -202,6 +180,38 @@ protected function resolveCachePath(string $path, string $filter): string
);
}

private function getImageSize(string $cachePath): array
{
if (!is_file($cachePath)) {
return [];
}
$size = getimagesize($cachePath);
if ($size === false) {
return [0, 0];
}
return [$size[0], $size[1]];
}

/**
* Gets the browser path for the image and filter to apply.
*/
public function imagineFilter(string $path, string $collection = 'default'): Markup
{
$absolutePath = $this->alias->get('@media/' . $path);

if (!is_file($absolutePath)) {
$dataSrc = $this->getTransparentOnePixelSrc();
return new Markup($dataSrc, 'utf8');
}

$sanitizedFilterSet = $this->sanitizeFilterName($collection);

return new Markup(
$this->basePath . $this->applyFilterSet($path, $sanitizedFilterSet),
'utf8'
);
}

protected function applyResizeFilter(ImageInterface $image, array $options): ImageInterface
{
// Defaults
Expand Down Expand Up @@ -302,7 +312,7 @@ protected function applyColorizeFilter(ImageInterface $image, array $options): I
protected function applyRotateFilter(ImageInterface $image, array $options): ImageInterface
{
if (isset($options['angle'])) {
$angle = (int) $options['angle'];
$angle = (int)$options['angle'];
$image->rotate($angle);
}
return $image;
Expand All @@ -326,7 +336,7 @@ protected function applyFlipVerticallyFilter(ImageInterface $image): ImageInterf
protected function applyUpscaleFilter(ImageInterface $image, array $options): ImageInterface
{
if (!isset($options['min'])) {
throw new \InvalidArgumentException('Missing min option.');
throw new InvalidArgumentException('Missing min option.');
}

[$width, $height] = $options['min'];
Expand Down Expand Up @@ -356,13 +366,4 @@ protected function applyRelativeResizeFilter(ImageInterface $image, array $optio
$filter = new RelativeResize($method, $parameter);
return $filter->apply($image);
}

protected function buildHtmlAttributes(array $htmlOptions = []): string
{
$attributes = '';
foreach ($htmlOptions as $key => $value) {
$attributes .= ' ' . $key . '="' . $value . '"';
}
return rtrim($attributes);
}
}
2 changes: 1 addition & 1 deletion plugins/imagine/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use herbie\sysplugin\imagine\ImagineSysPlugin;
use herbie\sysplugins\imagine\ImagineSysPlugin;

return [
'apiVersion' => 2,
Expand Down
4 changes: 2 additions & 2 deletions plugins/markdown/MarkdownSysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace herbie\sysplugin\markdown;
namespace herbie\sysplugins\markdown;

use herbie\Config;
use herbie\event\RenderSegmentEvent;
use herbie\events\RenderSegmentEvent;
use herbie\Plugin;
use Parsedown;
use ParsedownExtra;
Expand Down
2 changes: 1 addition & 1 deletion plugins/markdown/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use herbie\sysplugin\markdown\MarkdownSysPlugin;
use herbie\sysplugins\markdown\MarkdownSysPlugin;

return [
'apiVersion' => 2,
Expand Down
7 changes: 4 additions & 3 deletions plugins/rest/RestSysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace herbie\sysplugin\rest;
namespace herbie\sysplugins\rest;

use Doctrine\RST\Parser;
use herbie\Config;
use herbie\event\RenderSegmentEvent;
use herbie\events\RenderSegmentEvent;
use herbie\Plugin;

final class RestSysPlugin extends Plugin
Expand Down Expand Up @@ -61,7 +62,7 @@ public function parseRest(string $string): string
if (!$this->parserClassExists) {
return $string;
}
$parser = new \Doctrine\RST\Parser();
$parser = new Parser();
$document = $parser->parse($string);
return $document->render();
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rest/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use herbie\sysplugin\rest\RestSysPlugin;
use herbie\sysplugins\rest\RestSysPlugin;

return [
'apiVersion' => 2,
Expand Down
7 changes: 4 additions & 3 deletions plugins/textile/TextileSysPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

declare(strict_types=1);

namespace herbie\sysplugin\textile;
namespace herbie\sysplugins\textile;

use herbie\Config;
use herbie\event\RenderSegmentEvent;
use herbie\events\RenderSegmentEvent;
use herbie\Plugin;
use Netcarver\Textile\Parser;
use Psr\Log\LoggerInterface;
use Throwable;

final class TextileSysPlugin extends Plugin
{
Expand Down Expand Up @@ -67,7 +68,7 @@ public function parseTextile(string $value): string
try {
$parser = new Parser();
return $parser->parse($value);
} catch (\Throwable $t) {
} catch (Throwable $t) {
return $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/textile/config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use herbie\sysplugin\textile\TextileSysPlugin;
use herbie\sysplugins\textile\TextileSysPlugin;

return [
'apiVersion' => 2,
Expand Down

0 comments on commit 61545d3

Please sign in to comment.