This commit is contained in:
Dennis Eichhorn 2024-01-27 05:43:22 +00:00
parent 4e1630a124
commit 67886a9dc8
21 changed files with 566 additions and 72 deletions

View File

@ -213,7 +213,7 @@ final class DHLInternationalShipping implements ShippingInterface
$status = AuthStatus::LIMIT_EXCEEDED;
break;
case 200:
$this->token = $response->getData('access_token') ?? '';
$this->token = $response->getDataString('access_token') ?? '';
$this->expire->setTimestamp($this->expire->getTimestamp() + ((int) $response->getData('expires_in')));
$status = AuthStatus::OK;
@ -275,6 +275,7 @@ final class DHLInternationalShipping implements ShippingInterface
array $data
) : array
{
return [];
}
/**
@ -282,6 +283,7 @@ final class DHLInternationalShipping implements ShippingInterface
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
@ -294,7 +296,7 @@ final class DHLInternationalShipping implements ShippingInterface
$httpUri = new HttpUri($uri);
$httpUri->addQuery('trackingnumber', $shipment);
$httpUri->addQuery('limit', 10);
$httpUri->addQuery('limit', '10');
// @todo implement: express, parcel-de, ecommerce, dgf, parcel-uk, post-de, sameday, freight, parcel-nl, parcel-pl, dsc, ecommerce-europe, svb
//$httpUri->addQuery('service', '');

View File

@ -507,7 +507,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$httpUri = new HttpUri($uri);
$httpUri->addQuery('trackingnumber', $shipment);
$httpUri->addQuery('limit', 10);
$httpUri->addQuery('limit', '10');
// @todo implement: express, parcel-de, ecommerce, dgf, parcel-uk, post-de, sameday, freight, parcel-nl, parcel-pl, dsc, ecommerce-europe, svb
//$httpUri->addQuery('service', '');

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\DHL;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -27,6 +29,86 @@ use phpOMS\Api\Shipping\ShippingInterface;
* @see Tracking: https://developer.dhl.com/api-reference/shipment-tracking#get-started-section/
* @since 1.0.0
*/
final class DHLParcelDEShipping implements ShippingInterface
final class DHLeCommerceShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\DPD;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -28,4 +30,84 @@ use phpOMS\Api\Shipping\ShippingInterface;
*/
final class DPDShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\Fedex;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -27,4 +29,84 @@ use phpOMS\Api\Shipping\ShippingInterface;
*/
final class FedexShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\RoyalMail;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -27,4 +29,84 @@ use phpOMS\Api\Shipping\ShippingInterface;
*/
final class RoyalMailShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -46,10 +46,10 @@ interface ShippingInterface
/**
* Create request for authentication using login and password
*
* @param string $login Login name/email
* @param string $password Password
* @param string $client Client id
* @param array $payload Other payload data
* @param string $login Login name/email
* @param string $password Password
* @param null|string $client Client id
* @param null|string $payload Other payload data
*
* @return int Returns auth status
*

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\TNT;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -27,4 +29,84 @@ use phpOMS\Api\Shipping\ShippingInterface;
*/
final class TNTShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -150,7 +150,6 @@ final class UPSShipping implements ShippingInterface
/**
* Refresh token expiration.
*
* @var \DateTime
* @since 1.0.0
*/
public function __construct()
@ -179,7 +178,11 @@ final class UPSShipping implements ShippingInterface
$request->setMethod(RequestMethod::POST);
$request->setData('grant_type', 'client_credentials');
$request->header->set('Content-Type', MimeType::M_POST);
$request->header->set('x-merchant-id', $client);
if ($client !== null) {
$request->header->set('x-merchant-id', $client);
}
$request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password));
$this->expire = new \DateTime('now');
@ -198,7 +201,7 @@ final class UPSShipping implements ShippingInterface
$status = AuthStatus::LIMIT_EXCEEDED;
break;
case 200:
$this->token = $response->getData('access_token') ?? '';
$this->token = $response->getDataString('access_token') ?? '';
$this->expire->setTimestamp($this->expire->getTimestamp() + ((int) $response->getData('expires_in')));
$status = AuthStatus::OK;
@ -276,8 +279,8 @@ final class UPSShipping implements ShippingInterface
$status = AuthStatus::LIMIT_EXCEEDED;
break;
case 200:
$this->token = $response->getData('access_token') ?? '';
$this->refreshToken = $response->getData('refresh_token') ?? '';
$this->token = $response->getDataString('access_token') ?? '';
$this->refreshToken = $response->getDataString('refresh_token') ?? '';
$this->expire->setTimestamp($this->expire->getTimestamp() + ((int) $response->getData('expires_in')));
$this->refreshExpire->setTimestamp($this->refreshExpire->getTimestamp() + ((int) $response->getData('refresh_token_expires_in')));
@ -330,8 +333,8 @@ final class UPSShipping implements ShippingInterface
$status = AuthStatus::LIMIT_EXCEEDED;
break;
case 200:
$this->token = $response->getData('access_token') ?? '';
$this->refreshToken = $response->getData('refresh_token') ?? '';
$this->token = $response->getDataString('access_token') ?? '';
$this->refreshToken = $response->getDataString('refresh_token') ?? '';
$this->expire->setTimestamp($this->expire->getTimestamp() + ((int) $response->getData('expires_in')));
$this->refreshExpire->setTimestamp($this->refreshExpire->getTimestamp() + ((int) $response->getData('refresh_token_expires_in')));
@ -398,7 +401,7 @@ final class UPSShipping implements ShippingInterface
return [];
}
$services = $response->getDataArray('services');
$services = $response->getDataArray('services') ?? [];
$transits = [];
foreach ($services as $service) {
@ -665,7 +668,7 @@ final class UPSShipping implements ShippingInterface
return false;
}
return ($response->getData('VoidShipmentResponse')['Response']['ResponseStatus']['Code'] ?? '0') === '1';
return ($response->getDataArray('VoidShipmentResponse')['Response']['ResponseStatus']['Code'] ?? '0') === '1';
}
/**

View File

@ -14,7 +14,9 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\Usps;
use phpOMS\Api\Shipping\AuthStatus;
use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
/**
* Shipment api.
@ -27,4 +29,84 @@ use phpOMS\Api\Shipping\ShippingInterface;
*/
final class UspsShipping implements ShippingInterface
{
/**
* {@inheritdoc}
*/
public function authLogin(
string $login, string $password,
?string $client = null,
?string $payload = null
) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function authRedirectLogin(
string $client,
?string $redirect = null,
array $payload = []
) : HttpRequest
{
return new HttpRequest();
}
/**
* {@inheritdoc}
*/
public function tokenFromRedirect(
string $login, string $password,
HttpRequest $redirect
) : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function authApiKey(string $key) : int
{
return AuthStatus::FAILED;
}
/**
* {@inheritdoc}
*/
public function refreshToken() : int
{
return 0;
}
/**
* {@inheritdoc}
*/
public function ship(
array $sender,
array $shipFrom,
array $receiver,
array $package,
array $data
) : array
{
return [];
}
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array
{
return [];
}
}

View File

@ -40,7 +40,7 @@ class BaseStringL11n implements \JsonSerializable
*/
public string $name = '';
// @todo this feels like $name and $type accomplish the same thing
// @todo Karaka/phpOMS#357 this feels like $name and $type accomplish the same thing
// maybe we can always use $type and remove $name.
// This would require some smart mapper adjustment where the name is part of the l11n model,
// maybe use the path definition in the mapper which is used by arrays (e.g. type/name)

View File

@ -322,7 +322,7 @@ trait ISO3166Trait
case 'g8':
return [
self::_USA, self::_GBR, self::_FRA, self::_DEU, self::_ITA,
self::_CAN, self::_RUS, self::_JAP,
self::_CAN, self::_RUS, self::_JPN,
];
case 'p5':
return [

View File

@ -251,9 +251,11 @@ abstract class RequestAbstract implements MessageInterface
{
$key = \mb_strtolower($key);
return empty($this->data[$key] ?? null)
$timestamp = empty($this->data[$key] ?? null)
? null
: \strtotime((string) $this->data[$key]);
: (int) \strtotime((string) $this->data[$key]);
return $timestamp === false ? null : $timestamp;
}
/**

View File

@ -249,7 +249,7 @@ class BinarySearchTree
$temp = null;
if ($node->left === null) {
$temp = $node->right->root;
$temp = $node->right?->root;
if ($temp === null) {
return;
}

View File

@ -119,7 +119,7 @@ final class Argument implements UriInterface
/**
* Uri query.
*
* @var array<int, string>
* @var array<int|string, null|string>
* @since 1.0.0
*/
private array $query = [];

View File

@ -121,7 +121,7 @@ final class HttpUri implements UriInterface
/**
* Uri query.
*
* @var array<string, string>
* @var array<int|string, null|string>
* @since 1.0.0
*/
private array $query = [];
@ -386,14 +386,14 @@ final class HttpUri implements UriInterface
/**
* Add query parameter
*
* @param string $key Parameter key
* @param mixed $value Value (null = omitted)
* @param string $key Parameter key
* @param null|string $value Value (null = omitted)
*
* @return void
*
* @since 1.0.0
*/
public function addQuery(string $key, mixed $value = null) : void
public function addQuery(string $key, ?string $value = null) : void
{
$key = \strtolower($key);
$this->query[$key] = $value;

View File

@ -29,7 +29,7 @@ final class UriFactory
/**
* Dynamic query elements.
*
* @var string[]
* @var array<string, null|string>
* @since 1.0.0
*/
private static array $uri = [];
@ -105,15 +105,15 @@ final class UriFactory
/**
* Set global query replacements.
*
* @param string $key Replacement key
* @param string $value Replacement value
* @param bool $overwrite Overwrite if already exists
* @param string $key Replacement key
* @param null|string $value Replacement value
* @param bool $overwrite Overwrite if already exists
*
* @return bool
*
* @since 1.0.0
*/
public static function setQuery(string $key, string $value, bool $overwrite = false) : bool
public static function setQuery(string $key, ?string $value, bool $overwrite = false) : bool
{
if ($overwrite || !isset(self::$uri[$key])) {
self::$uri[$key] = $value;

View File

@ -173,7 +173,7 @@ interface UriInterface
/**
* Get query array.
*
* @return string[]
* @return array<int|string, null|string>
*
* @since 1.0.0
*/

View File

@ -530,9 +530,9 @@ class Markdown
$this->blockTypes['['][] = 'Checkbox';
}
// Embeding
if ($this->options['embeding'] ?? false) {
$this->inlineTypes['['][] = 'Embeding';
// Embedding
if ($this->options['embedding'] ?? false) {
$this->inlineTypes['['][] = 'Embedding';
}
// Map
@ -649,19 +649,17 @@ class Markdown
*/
public function contentsList($typeReturn = 'html') : string
{
if (\strtolower($typeReturn) === 'html') {
$result = '';
if (!empty($this->contentsListString)) {
// Parses the ToC list in markdown to HTML
$result = $this->body($this->contentsListString);
}
return $result;
} elseif (\strtolower($typeReturn) === 'json') {
if (\strtolower($typeReturn) === 'json') {
return \json_encode($this->contentsListArray);
}
return $this->contentsList('html');
$result = '';
if (!empty($this->contentsListString)) {
// Parses the ToC list in markdown to HTML
$result = $this->body($this->contentsListString);
}
return $result;
}
/**
@ -1323,7 +1321,7 @@ class Markdown
}
/**
* Handle embeding
* Handle embedding
*
* @param array{text:string, context:string, before:string} $excerpt Inline data
*
@ -1331,9 +1329,9 @@ class Markdown
*
* @since 1.0.0
*/
protected function inlineEmbeding(array $excerpt) : ?array
protected function inlineEmbedding(array $excerpt) : ?array
{
if (!($this->options['embeding'] ?? false)
if (!($this->options['embedding'] ?? false)
|| !(\str_starts_with($excerpt['text'], '[video') || \str_starts_with($excerpt['text'], '[audio'))
|| (!($video = (\preg_match('/\[video.*src="([^"]*)".*\]/', $excerpt['text'], $matches) === 1))
&& !($audio = (\preg_match('/\[audio.*src="([^"]*)".*\]/', $excerpt['text'], $matches) === 1)))
@ -1785,7 +1783,7 @@ class Markdown
$state = $this->options['math'] ?? false;
if (!$state
|| ($state && !\preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.{2,}?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $excerpt['text']))
|| !\preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.{2,}?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $excerpt['text'])
) {
return [
'extent' => 2,
@ -1882,14 +1880,12 @@ class Markdown
return null;
}
$text = \substr($line['body'], 4);
return [
'element' => [
'name' => 'pre',
'element' => [
'name' => 'code',
'text' => $text,
'text' => \substr($line['body'], 4),
],
],
];
@ -3176,22 +3172,19 @@ class Markdown
$this->initBlacklist();
}
$this->anchorDuplicates[$str] = isset($this->anchorDuplicates[$str]) ? ++$this->anchorDuplicates[$str] : 0;
do {
$this->anchorDuplicates[$str] = isset($this->anchorDuplicates[$str]) ? ++$this->anchorDuplicates[$str] : 0;
$newStr = $str;
$newStr = $str;
if (($count = $this->anchorDuplicates[$str]) === 0) {
return $newStr;
}
if (($count = $this->anchorDuplicates[$str]) === 0) {
return $newStr;
}
$newStr .= '-' . $count;
$newStr .= '-' . $count;
} while(isset($this->anchorDuplicates[$newStr]));
// increment until conversion doesn't produce new duplicates anymore
if (isset($this->anchorDuplicates[$newStr])) {
$newStr = $this->incrementAnchorId($str);
} else {
$this->anchorDuplicates[$newStr] = 0;
}
$this->anchorDuplicates[$newStr] = 0;
return $newStr;
}
@ -4475,7 +4468,7 @@ class Markdown
}
/**
* Handle element recursiveley
* Handle element recursively
*
* @param string|\Closure $closure Closure for handling element
* @param array $element Element to handle
@ -4500,7 +4493,7 @@ class Markdown
}
/**
* Handle element recursiveley
* Handle element recursively
*
* @param string|\Closure $closure Closure for handling element
* @param array $element Element to handle
@ -4536,7 +4529,7 @@ class Markdown
protected function element(array $element) : string
{
if ($this->safeMode) {
$element = $this->sanitiseElement($element);
$element = $this->sanitizeElement($element);
}
// identity map if element has no handler
@ -4691,7 +4684,7 @@ class Markdown
*
* @since 1.0.0
*/
protected function sanitiseElement(array $element) : array
protected function sanitizeElement(array $element) : array
{
static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/';
static $safeUrlNameToAtt = [

View File

@ -206,8 +206,10 @@ class Cron extends SchedulerAbstract
$elements = \array_merge($elements, $interval);
$elements[] = \trim(\substr($line, $len = (\strlen(\implode(' ', $interval)) + 1), $comment - $len - 1));
$jobs[] = $job = CronJob::createWith($elements);
$job->setStatus($line[0] === '#' ? TaskStatus::INACTIVE : TaskStatus::ACTIVE);
$job = CronJob::createWith($elements);
$job->status = $line[0] === '#' ? TaskStatus::INACTIVE : TaskStatus::ACTIVE;
$jobs[] = $job;
}
$line = \fgets($fp);

View File

@ -45,7 +45,7 @@ class Schedule extends TaskAbstract
*/
$job = new self($jobData[1], $jobData[8], $jobData[7]);
$job->setStatus((int) $jobData[3]);
$job->status = (int) $jobData[3];
if (DateTime::isValid($jobData[2])) {
$job->setNextRunTime(new \DateTime($jobData[2]));