DHL Modul v0.5 Shipping Label ok

This commit is contained in:
Kevin Adametz 2025-08-22 18:18:26 +02:00
parent 480fdc65ed
commit 8fdaa0ba1d
122 changed files with 17938 additions and 2239 deletions

View file

@ -0,0 +1,218 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser;
use Alban\LaravelCollectiveSpatieHtmlParser\Traits\AttributesUtils;
class FormAdapter
{
use AttributesUtils;
public function checkbox($name, $value = 1, $checked = null, $options = [])
{
$element = \Html::checkbox($name, $checked, $value);
return $this->mergeOptions($element, $options);
}
public function open(array $options = [])
{
$method = array_key_exists('method', $options) ? $options['method'] : 'POST';
$route = array_key_exists('route', $options) ? $options['route'] : '';
$files = array_key_exists('files', $options) ? $options['files'] : false;
unset($options['method'], $options['route'], $options['files']);
$form = \Html::getFacadeRoot();
if (is_array($route) && count($route)) {
$action = array_shift($route);
$form = $form->form($method, route($action, $route));
} elseif ($route != null && $route != [] && $route != '') {
$form = $form->form($method, route($route));
} else {
$form = $form->form($method);
}
if ($files) {
$form = $form->acceptsFiles();
}
return $this->mergeOptions($form, $options)->open();
}
public function label($name, $value = null, $options = [], $escape_html = true)
{
$element = \Html::label($value, $name);
return $this->mergeOptions($element, $options);
}
public function text($name, $value = null, $options = [])
{
$element = \Html::text($name, $value);
return $this->mergeOptions($element, $options);
}
public function password($name, $options = [])
{
$element = \Html::password($name);
return $this->mergeOptions($element, $options);
}
public function select(
$name,
$list = [],
$selected = null,
array $selectAttributes = [],
array $optionsAttributes = [],
array $optgroupsAttributes = []
) {
if (isset($selectAttributes['multiple']) || in_array('multiple', $selectAttributes)) {
$element = \Html::select($name, $list, $selected)->multiple();
} else {
$element = \Html::select($name, $list, $selected);
}
// $element = \Html::select($name, $list, $selected);
return $this->mergeOptions($element, $selectAttributes);
}
public function radio($name, $value = null, $checked = null, $options = [])
{
$element = \Html::radio($name, $checked, $value);
return $this->mergeOptions($element, $options);
}
public function submit($value = null, $options = [])
{
$element = \Html::submit($value);
return $this->mergeOptions($element, $options);
}
public function close()
{
\Html::endModel();
return \Html::form()->close();
}
public function input($type, $name, $value = null, $options = [])
{
$element = \Html::input($type, $name, $value);
return $this->mergeOptions($element, $options);
}
public function search($name, $value = null, $options = [])
{
return $this->input('search', $name, $value, $options);
}
public function model($model, array $options = [])
{
\Html::model($model);
return $this->open($options);
}
public function hidden($name, $value = null, $options = [])
{
$element = \Html::hidden($name, $value);
return $this->mergeOptions($element, $options);
}
public function email($name, $value = null, $options = [])
{
$element = \Html::email($name, $value);
return $this->mergeOptions($element, $options);
}
public function tel($name, $value = null, $options = [])
{
$element = \Html::tel($name, $value);
return $this->mergeOptions($element, $options);
}
public function number($name, $value = null, $options = [])
{
return $this->input('number', $name, $value, $options);
}
public function date($name, $value = null, $options = [])
{
$element = \Html::date($name, $value);
return $this->mergeOptions($element, $options);
}
public function datetime($name, $value = null, $options = [])
{
return $this->input('datetime', $name, $value, $options);
}
public function datetimeLocal($name, $value = null, $options = [])
{
return $this->input('datetime-local', $name, $value, $options);
}
public function time($name, $value = null, $options = [])
{
$element = \Html::time($name, $value);
return $this->mergeOptions($element, $options);
}
public function url($name, $value = null, $options = [])
{
return $this->input('url', $name, $value, $options);
}
public function file($name, $options = [])
{
$element = \Html::file($name);
return $this->mergeOptions($element, $options);
}
public function textarea($name, $value = null, $options = [])
{
$element = \Html::textarea($name, $value);
return $this->mergeOptions($element, $options);
}
public function reset($value, $attributes = [])
{
$element = \Html::reset($value);
return $this->mergeOptions($element, $attributes);
}
public function image($url, $name = null, $attributes = [])
{
$element = \Html::img($url, $name);
return $this->mergeOptions($element, $attributes);
}
public function color($name, $value = null, $options = [])
{
return $this->input('color', $name, $value, $options);
}
public function button($value = null, $options = [])
{
$element = \Html::button($value);
return $this->mergeOptions($element, $options);
}
}

View file

@ -0,0 +1,22 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser;
use Illuminate\Support\Facades\Facade;
/**
* @see \Collective\Html\HtmlBuilder
*/
class FormFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'form';
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser;
use Spatie\Html\Html;
class HtmlAdapter extends Html {}

View file

@ -0,0 +1,18 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser;
use Illuminate\Support\Facades\Facade;
class HtmlFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return 'html';
}
}

View file

@ -0,0 +1,46 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
class ServiceProvider extends BaseServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->registerFormAdpater();
$this->registerHtmlAdapter();
$this->app->alias('form', FormAdapter::class);
$this->app->alias('html', HtmlAdapter::class);
}
/**
* Register the HTML adapter instance.
*
* @return void
*/
protected function registerFormAdpater()
{
$this->app->singleton('form', function () {
return new FormAdapter();
});
}
/**
* Register the HTML adapter instance.
*
* @return void
*/
protected function registerHtmlAdapter()
{
$this->app->singleton('html', function () {
return new HtmlAdapter();
});
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Alban\LaravelCollectiveSpatieHtmlParser\Traits;
trait AttributesUtils
{
public function mergeOptions($element, $options = [])
{
$newElement = $element;
if (isset($options['class'])) {
$newElement = $newElement->addClass($options['class']);
unset($options['class']);
}
if (isset($options['placeholder'])) {
$newElement = $newElement->placeholder($options['placeholder']);
unset($options['placeholder']);
}
foreach ($options as $key => $value) {
if (!$value) {
continue;
}
if (is_numeric($key)) {
$newElement = $newElement->attribute($value, '');
continue;
}
$newElement = $newElement->attribute($key, $value);
}
return $newElement;
}
}