From aae408c264729b1c24141a83221935c2caaaae2e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 11 Jun 2024 08:42:15 +0200 Subject: [PATCH] add isObject check --- CHANGELOG.md | 16 ++++++++++++++- services.yaml | 3 +++ src/IsObjectExtension.php | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/IsObjectExtension.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1036056..57e7caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.0.0.0...rel_1.x) +## [Unreleased](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.3.0.0...rel_1.x) + +## [1.3.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.2.0.0...1.3.0.0) - 2024-06-11 +### Added +- isObject check + +## [1.2.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.1.0.0...1.2.0.0) - 2024-06-07 +### Added +- Twig as dependency +- text, array, pcre functionality + +## [1.1.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.0.0.0...1.1.0.0) - 2024-05-07 +### Added +- module settings access +- shop settings access ## [1.0.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/releases/tag/1.0.0.0) - 2023-01-10 ### Added diff --git a/services.yaml b/services.yaml index 70e850a..5110f7f 100644 --- a/services.yaml +++ b/services.yaml @@ -11,6 +11,9 @@ services: D3\OxidTwigExtensions\ShopConfigurationExtension: tags: ['twig.extension'] + D3\OxidTwigExtensions\IsObjectExtension: + tags: ['twig.extension'] + # requires intl extension # Jasny\Twig\DateExtension: # tags: ['twig.extension'] diff --git a/src/IsObjectExtension.php b/src/IsObjectExtension.php new file mode 100644 index 0000000..4cb635b --- /dev/null +++ b/src/IsObjectExtension.php @@ -0,0 +1,41 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\OxidTwigExtensions; + +use InvalidArgumentException; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +class isObjectExtension extends AbstractExtension +{ + /** + * @return TwigFunction[] + */ + public function getFunctions(): array + { + return [new TwigFunction('is_object', [$this, 'twig_method_exists'], ['is_safe' => ['html']])]; + } + + /** + * @param object $entity + * + * @return bool + */ + public function twig_method_exists($entity): bool + { + return is_object($entity); + } +} \ No newline at end of file