Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Novalnet-Technic committed Mar 6, 2024
0 parents commit 2e282a0
Show file tree
Hide file tree
Showing 49 changed files with 9,967 additions and 0 deletions.
515 changes: 515 additions & 0 deletions Bootstrap.php

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Components/CSRFWhitelistAware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Novalnet payment plugin
*
* NOTICE OF LICENSE
*
* This source file is subject to Novalnet End User License Agreement
*
* DISCLAIMER
*
* If you wish to customize Novalnet payment extension for your needs, please contact [email protected] for more information.
*
* @author Novalnet AG
* @copyright Copyright (c) Novalnet
* @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz
* @link https://www.novalnet.de
*
* This free contribution made by request.
*
* If you have found this script useful a small
* recommendation as well as a comment on merchant
*
*/

namespace Shopware\Components;

if (!interface_exists('\Shopware\Components\CSRFWhitelistAware')) {
interface CSRFWhitelistAware
{
}
}
183 changes: 183 additions & 0 deletions Components/Classes/ArrayMapHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php
/**
* Novalnet payment plugin
*
* NOTICE OF LICENSE
*
* This source file is subject to the GNU General Public License
* that is bundled with this package in the file freeware_license_agreement.txt
*
* DISCLAIMER
*
* If you wish to customize Novalnet payment extension for your needs, please contact [email protected] for more information.
*
* @category Novalnet
* @package NovalPayment
* @copyright Copyright (c) Novalnet
* @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz GNU General Public License
*/

namespace Shopware\Plugins\NovalPayment\Components\Classes;

class ArrayMapHelper
{
/**
* @var array
*/
protected $_data = [];

/**
* @var array
*/
protected static $_underscoreCache = [];

/**
* @var array $data
*/
public function __construct(array $data = [])
{
$this->_data = $data;
}

/**
* To set array
*
* @param mixed $key
* @param mixed $value
* @return mixed
*/
public function setData($key, $value = null)
{
if ($key === (array)$key) {
$this->_data = $key;
} else {
$this->_data[$key] = $value;
}
return $this;
}

/**
* To get array data
*
* @param mixed $key
* @param mixed $index
* @return array
*/
public function getData($key = '', $index = null)
{
if ('' === $key) {
return $this->_data;
}

/* process a/b/c key as ['a']['b']['c'] */
if ($key !== null && strpos($key, '/') !== false) {
$data = $this->getDataByPath($key);
} else {
$data = $this->_getData($key);
}

if ($index !== null) {
if ($data === (array)$data) {
$data = isset($data[$index]) ? $data[$index] : null;
} elseif (is_string($data)) {
$data = explode(PHP_EOL, $data);
$data = isset($data[$index]) ? $data[$index] : null;
} elseif ($data instanceof \Shopware\Plugins\NovalPayment\Components\Classes\ArrayMapHelper) {
$data = $data->getData($index);
} else {
$data = null;
}
}
return $data;
}

/**
* To get data by path
*
* @param string $path
* @return mixed
*/
public function getDataByPath($path)
{
$keys = explode('/', (string)$path);

$data = $this->_data;
foreach ($keys as $key) {
if ((array)$data === $data && isset($data[$key])) {
$data = $data[$key];
} elseif ($data instanceof \Shopware\Plugins\NovalPayment\Components\Classes\ArrayMapHelper) {
$data = $data->getDataByKey($key);
} else {
return null;
}
}
return $data;
}

/**
* To get data by key
*
* @param string $key
* @return mixed
*/
public function getDataByKey($key)
{
return $this->_getData($key);
}

/**
* To get data
*
* @param string $key
* @return mixed
*/
protected function _getData($key)
{
if (isset($this->_data[$key])) {
return $this->_data[$key];
}
return null;
}

/**
* PHP magic method
*
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, $args)
{
switch (substr((string)$method, 0, 3)) {
case 'get':
$key = $this->_underscore(substr($method, 3));
$index = isset($args[0]) ? $args[0] : null;
return $this->getData($key, $index);
case 'set':
$key = $this->_underscore(substr($method, 3));
$value = isset($args[0]) ? $args[0] : null;
return $this->setData($key, $value);
case 'has':
$key = $this->_underscore(substr($method, 3));
return isset($this->_data[$key]);
}

throw new \Exception('undefined method call');
}

/**
* understore method
*
* @param string $name
* @return mixed
*/
protected function _underscore($name)
{
if (isset(self::$_underscoreCache[$name])) {
return self::$_underscoreCache[$name];
}
$result = strtolower(trim(preg_replace('/([A-Z]|[0-9]+)/', "_$1", $name), '_'));
self::$_underscoreCache[$name] = $result;
return $result;
}
}
Loading

0 comments on commit 2e282a0

Please sign in to comment.