add method_exists extension
This commit is contained in:
bovenliggende
7bd059600d
commit
555557dcdd
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()
|
||||
->in(__DIR__)
|
||||
;
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
return $config->setRules([
|
||||
'@PHP73Migration' => true,
|
||||
'@PSR12' => true
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
25
CHANGELOG.md
25
CHANGELOG.md
@ -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/),
|
||||
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
|
||||
- another feature
|
||||
|
||||
### 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
|
||||
- add method_exists extension
|
@ -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.
|
37
README.en.md
37
README.en.md
@ -1,14 +1,21 @@
|
||||
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.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
|
||||
|
||||
- [Installation](#installation)
|
||||
- [How to use](#how-to-use)
|
||||
- [Changelog](#changelog)
|
||||
- [Contributing](#contributing)
|
||||
- [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).
|
||||
|
||||
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.
|
||||
|
||||
```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.
|
||||
|
||||
Activate the module in Shopadmin under "Extensions -> Modules".
|
||||
|
||||
## How to use
|
||||
|
||||
...
|
||||
Clear the TMP folder of your shop.
|
||||
|
||||
## 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
|
||||
|
||||
## License
|
||||
(status: 2022-07-30)
|
||||
(status: 2023-01-10)
|
||||
|
||||
Distributed under the GPLv3 license.
|
||||
|
||||
@ -65,8 +60,4 @@ Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
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.
|
||||
|
||||
## Further licences and terms of use
|
||||
|
||||
...
|
||||
For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code.
|
35
README.md
35
README.md
@ -1,14 +1,21 @@
|
||||
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.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
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Verwendung](#verwendung)
|
||||
- [Changelog](#changelog)
|
||||
- [Beitragen](#beitragen)
|
||||
- [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.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
```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.
|
||||
|
||||
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
|
||||
|
||||
## Verwendung
|
||||
|
||||
...
|
||||
Leeren Sie den TMP-Ordner Ihres Shops.
|
||||
|
||||
## Changelog
|
||||
|
||||
@ -56,7 +51,7 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Repositorie
|
||||
- Öffnen Sie einen Pull Request
|
||||
|
||||
## Lizenz
|
||||
(Stand: 06.05.2021)
|
||||
(Stand: 10.01.2023)
|
||||
|
||||
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.
|
||||
|
||||
## weitere Lizenzen und Nutzungsbedingungen
|
||||
|
||||
...
|
@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "d3/modulename",
|
||||
"description": "the module description",
|
||||
"type": "oxideshop-module",
|
||||
"name": "d3/oxid-twig-extensions",
|
||||
"description": "additonal extensions for the OXID Twig template renderer component",
|
||||
"type": "oxideshop-component",
|
||||
"keywords": [
|
||||
"oxid",
|
||||
"modules",
|
||||
"eShop",
|
||||
"twig",
|
||||
"template",
|
||||
"extensions",
|
||||
"d3"
|
||||
],
|
||||
"authors": [
|
||||
@ -24,30 +25,11 @@
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.3",
|
||||
"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"
|
||||
}
|
||||
"oxid-esales/oxideshop-ce": "^7.0.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"D3\\ThisModule\\": "../../../source/modules/d3/thismodule"
|
||||
"D3\\OxidTwigExtensions\\": "./src"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
70
metadata.php
70
metadata.php
@ -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³ 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'
|
||||
],
|
||||
];
|
10
phpstan.neon
10
phpstan.neon
@ -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#'
|
20
phpunit.xml
20
phpunit.xml
@ -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
Normal file
6
services.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
|
||||
D3\OxidTwigExtensions\MethodExistsExtension:
|
||||
tags: ['twig.extension']
|
50
src/MethodExistsExtension.php
Normal file
50
src/MethodExistsExtension.php
Normal file
@ -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);
|
||||
}
|
||||
}
|
Laden…
Verwijs in nieuw issue
Block a user