add method_exists extension

Cette révision appartient à :
Daniel Seifert 2023-01-10 14:20:00 +01:00
Parent 7bd059600d
révision 555557dcdd
Signé par: DanielS
ID de la clé GPG: 8A7C4C6ED1915C6F
11 fichiers modifiés avec 94 ajouts et 217 suppressions

Voir le fichier

@ -1,13 +0,0 @@
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP73Migration' => true,
'@PSR12' => true
])
->setFinder($finder)
;

Voir le fichier

@ -4,27 +4,8 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.d3data.de/D3Public/MyModule/compare/1.1.0.0...rel_1.x) ## [Unreleased](https://git.d3data.de/D3Public/oxid_twig_extensions/compare/1.0.0.0...rel_1.x)
## [1.1.0.0](https://git.d3data.de/D3Public/MyModule/compare/1.0.0.0...1.1.0.0) - 2022-07-26 ## [1.0.0.0](https://git.d3data.de/D3Public/oxid_twig_extensions/releases/tag/1.0.0.0) - 2023-01-10
### Added ### Added
- another feature - add method_exists extension
### Changed
- changed old code
### Deprecated
- ...
### Removed
- ...
### Fixed
- ...
### Security
- ...
## [1.0.0.0](https://git.d3data.de/D3Public/MyModule/releases/tag/1.0.0.0) - 2022-07-25
### Added
- implemented features

Voir le fichier

@ -1,11 +0,0 @@
# phpstan
Install the dev packages manually, then run `./vendor/bin/phpstan -c./vendor/d3/oxtotp/phpstan.neon` from the projects root directory
Analysis configuration is set in `phpstan.neon` file.
# php-cs-fixer
install the dev packages manually, then run `...` from the projects root directory
Fixer configuration is set in `.php-cs-fixer.php` file.

Voir le fichier

@ -1,14 +1,21 @@
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md) [![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md) [![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
# D³ Modulname for OXID eShop # D³ Twig extensions for OXID eShop
Insert short description here additional extensions that can be used in the shop's Twig templates:
- method_exists - Checks whether the method of an object exists.
```
{% if method_exists(entity, 'getCreatedBy') %}
({{ entity.createdBy.name }})
{% endif %}
```
## Table of content ## Table of content
- [Installation](#installation) - [Installation](#installation)
- [How to use](#how-to-use)
- [Changelog](#changelog) - [Changelog](#changelog)
- [Contributing](#contributing) - [Contributing](#contributing)
- [License](#license) - [License](#license)
@ -18,27 +25,15 @@ Insert short description here
This package requires an OXID eShop installed with Composer in a version defined in the [composer.json](composer.json). This package requires an OXID eShop installed with Composer in a version defined in the [composer.json](composer.json).
Please enter the following section in the `composer.json` of your project:
```
"extra": {
...
}
```
Open a command line and navigate to the root directory of the shop (parent directory of source and vendor). Execute the following command. Adapt the path details to your installation environment. Open a command line and navigate to the root directory of the shop (parent directory of source and vendor). Execute the following command. Adapt the path details to your installation environment.
```bash ```bash
php composer require d3/modulename:^2.0 php composer require d3/oxid-twig-extensions:^1.0
``` ```
If necessary, please confirm that you allow `package-name` to execute code. If necessary, please confirm that you allow `package-name` to execute code.
Activate the module in Shopadmin under "Extensions -> Modules". Clear the TMP folder of your shop.
## How to use
...
## Changelog ## Changelog
@ -55,7 +50,7 @@ If you have a suggestion that would make this better, please fork the repo and c
- Open a Pull Request - Open a Pull Request
## License ## License
(status: 2022-07-30) (status: 2023-01-10)
Distributed under the GPLv3 license. Distributed under the GPLv3 license.
@ -66,7 +61,3 @@ This software is distributed under the GNU GENERAL PUBLIC LICENSE version 3.
``` ```
For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code. For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code.
## Further licences and terms of use
...

Voir le fichier

@ -1,14 +1,21 @@
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md) [![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md) [![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
# D³ Modulname für OXID eShop # D³ Twig Extensions für OXID eShop
Hier Kurzbeschreibung einfügen zusätzliche Erweiterungen, die in den Twig-Templates des Shops verwendet werden können:
- method_exists - Prüft, ob die Methode eines Objekts existiert.
```
{% if method_exists(entity, 'getCreatedBy') %}
({{ entity.createdBy.name }})
{% endif %}
```
## Inhaltsverzeichnis ## Inhaltsverzeichnis
- [Installation](#installation) - [Installation](#installation)
- [Verwendung](#verwendung)
- [Changelog](#changelog) - [Changelog](#changelog)
- [Beitragen](#beitragen) - [Beitragen](#beitragen)
- [Lizenz](#lizenz) - [Lizenz](#lizenz)
@ -18,28 +25,16 @@ Hier Kurzbeschreibung einfügen
Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer in der [composer.json](composer.json) definierten Version. Dieses Paket erfordert einen mit Composer installierten OXID eShop in einer in der [composer.json](composer.json) definierten Version.
Bitte tragen Sie den folgenden Abschnitt in die `composer.json` Ihres Projektes ein:
```
"extra": {
...
}
```
Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an. Öffnen Sie eine Kommandozeile und navigieren Sie zum Stammverzeichnis des Shops (Elternverzeichnis von source und vendor). Führen Sie den folgenden Befehl aus. Passen Sie die Pfadangaben an Ihre Installationsumgebung an.
```bash ```bash
php composer require d3/modulename:^2.0 php composer require d3/oxid-twig-extensions:^1.0
``` ```
Sofern nötig, bestätigen Sie bitte, dass Sie `package-name` erlauben, Code auszuführen. Sofern nötig, bestätigen Sie bitte, dass Sie `package-name` erlauben, Code auszuführen.
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module". Leeren Sie den TMP-Ordner Ihres Shops.
## Verwendung
...
## Changelog ## Changelog
@ -56,7 +51,7 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Repositorie
- Öffnen Sie einen Pull Request - Öffnen Sie einen Pull Request
## Lizenz ## Lizenz
(Stand: 06.05.2021) (Stand: 10.01.2023)
Vertrieben unter der GPLv3 Lizenz. Vertrieben unter der GPLv3 Lizenz.
@ -67,7 +62,3 @@ Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben.
``` ```
Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde. Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde.
## weitere Lizenzen und Nutzungsbedingungen
...

Voir le fichier

@ -1,11 +1,12 @@
{ {
"name": "d3/modulename", "name": "d3/oxid-twig-extensions",
"description": "the module description", "description": "additonal extensions for the OXID Twig template renderer component",
"type": "oxideshop-module", "type": "oxideshop-component",
"keywords": [ "keywords": [
"oxid", "oxid",
"modules", "twig",
"eShop", "template",
"extensions",
"d3" "d3"
], ],
"authors": [ "authors": [
@ -24,30 +25,11 @@
"GPL-3.0-or-later" "GPL-3.0-or-later"
], ],
"require": { "require": {
"php": ">=7.3", "oxid-esales/oxideshop-ce": "^7.0.0"
"oxid-esales/oxideshop-ce": "6.8 - 6.10"
},
"require-dev": {
"php": "^7.4",
"phpunit/phpunit" : "^9.5",
"friendsofphp/php-cs-fixer": "^3.9",
"phpstan/phpstan": "^1.8"
},
"extra": {
"oxideshop": {
"blacklist-filter": [
"*.md",
"composer.json",
".php-cs-fixer.php",
"*.xml",
"*.neon"
],
"target-directory": "d3/thismodule"
}
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"D3\\ThisModule\\": "../../../source/modules/d3/thismodule" "D3\\OxidTwigExtensions\\": "./src"
} }
} }
} }

Voir le fichier

@ -1,70 +0,0 @@
<?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);
$sMetadataVersion = '2.1';
$sModuleId = 'd3moduleid';
$logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em">';
/**
* Module information
*/
$aModule = [
'id' => $sModuleId,
'title' => $logo.' Module Name',
'description' => [
'de' => '',
'en' => '',
],
'thumbnail' => 'image-file.png',
'version' => '1.0.0.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
'controllers' => [
// 'd3ControllerAlias' => D3\ThisModule\Application\Controller\Admin\d3Controller::class,
],
'extend' => [
// \OxidEsales\Eshop\Core\ShopControl::class => \D3\ThisModule\Modules\Core\ShopControl_MyModule::class
],
'events' => [
// 'onActivate' => '\D3\ThisModule\Setup\Events::onActivate',
// 'onDeactivate' => '\D3\ThisModule\Setup\Events::onDeactivate',
],
'templates' => [
// 'd3TemplateAlias.tpl' => 'd3/thismodule/Application/views/admin/tpl/d3Template.tpl',
// 'flow_theme' => [
// 'd3FlowTemplateAlias.tpl' => 'd3/thismodule/Application/views/tpl/d3FlowTheme.tpl',
// ],
],
'settings' => [
// [
// 'group' => $sModuleId.'_headline',
// 'name' => $sModuleId.'_name',
// 'type' => 'bool',
// 'value' => false,
// ],
],
'blocks' => [
// [
// 'template' => 'layout/footer.tpl',
// 'block' => 'footer_main',
// 'file' => 'Application/views/blocks/layout/footer_main_mymodule.tpl'
// ]
],
'smartyPluginDirectories' => [
// 'Core/Smarty/Plugin'
],
];

Voir le fichier

@ -1,10 +0,0 @@
parameters:
scanFiles:
- IntelliSenseHelper.php
- ../../oxid-esales/oxideshop-ce/source/oxfunctions.php
- ../../oxid-esales/oxideshop-ce/source/overridablefunctions.php
level: 9
phpVersion: 70100
checkMissingIterableValueType: false
ignoreErrors:
- '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'

Voir le fichier

@ -1,20 +0,0 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<testsuite name="myModule">
<directory>./Tests</directory>
</testsuite>
<logging/>
</phpunit>

6
services.yaml Fichier normal
Voir le fichier

@ -0,0 +1,6 @@
services:
_defaults:
autowire: true
D3\OxidTwigExtensions\MethodExistsExtension:
tags: ['twig.extension']

50
src/MethodExistsExtension.php Fichier normal
Voir le fichier

@ -0,0 +1,50 @@
<?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 MethodExistsExtension extends AbstractExtension
{
/**
* @return TwigFunction[]
*/
public function getFunctions(): array
{
return [new TwigFunction('method_exists', [$this, 'twig_method_exists'], ['is_safe' => ['html']])];
}
/**
* @param object $entity
* @param string $method
*
* @return bool
*/
public function twig_method_exists($entity, string $method ): bool
{
if (!is_object($entity)) {
throw new InvalidArgumentException('Given entity is not of type object, got: '.get_class($entity));
}
if (empty($method)) {
throw new InvalidArgumentException('Method name empty');
}
return method_exists($entity, $method);
}
}