add isObject check

This commit is contained in:
Daniel Seifert 2024-06-11 08:42:15 +02:00
bovenliggende ea9002dff1
commit aae408c264
3 gewijzigde bestanden met toevoegingen van 59 en 1 verwijderingen

Bestand weergeven

@ -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

Bestand weergeven

@ -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']

41
src/IsObjectExtension.php Normal file
Bestand weergeven

@ -0,0 +1,41 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @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);
}
}