This commit is contained in:
Dennis Eichhorn 2024-01-02 23:34:19 +00:00
parent b5944503d8
commit ea0b033e1c
61 changed files with 542 additions and 421 deletions

View File

@ -49,12 +49,24 @@ final class AffinityPropagation implements ClusteringInterface
private array $availabilityMatrix = []; private array $availabilityMatrix = [];
/**
* Original points used for clusters
*
* @var PointInterface[]
* @since 1.0.0
*/
private array $points = []; private array $points = [];
/** /**
* @param PointInterface[] $points * Create similarity matrix from points
*
* @param PointInterface[] $points Points to create the similarity matrix for
*
* @return array<int, array<int, int|float>>
*
* @since 1.0.0
*/ */
private function createSimilarityMatrix(array $points) private function createSimilarityMatrix(array $points) : array
{ {
$n = \count($points); $n = \count($points);
$coordinates = \count($points[0]->coordinates); $coordinates = \count($points[0]->coordinates);
@ -63,7 +75,6 @@ final class AffinityPropagation implements ClusteringInterface
$temp = []; $temp = [];
for ($i = 0; $i < $n - 1; ++$i) { for ($i = 0; $i < $n - 1; ++$i) {
for ($j = $i + 1; $j < $n; ++$j) { for ($j = $i + 1; $j < $n; ++$j) {
$sum = 0.0; $sum = 0.0;
for ($c = 0; $c < $coordinates; ++$c) { for ($c = 0; $c < $coordinates; ++$c) {
$sum += ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c)) * ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c)); $sum += ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c)) * ($points[$i]->getCoordinate($c) - $points[$j]->getCoordinate($c));
@ -71,7 +82,7 @@ final class AffinityPropagation implements ClusteringInterface
$similarityMatrix[$i][$j] = -$sum; $similarityMatrix[$i][$j] = -$sum;
$similarityMatrix[$j][$i] = -$sum; $similarityMatrix[$j][$i] = -$sum;
$temp[] = $similarityMatrix[$i][$j]; $temp[] = $similarityMatrix[$i][$j];
} }
} }
@ -89,14 +100,24 @@ final class AffinityPropagation implements ClusteringInterface
return $similarityMatrix; return $similarityMatrix;
} }
/**
* Generate clusters for points
*
* @param PointInterface[] $points Points to cluster
* @param int $iterations Iterations for cluster generation
*
* @return void
*
* @since 1.0.0
*/
public function generateClusters(array $points, int $iterations = 100) : void public function generateClusters(array $points, int $iterations = 100) : void
{ {
$this->points = $points; $this->points = $points;
$n = \count($points); $n = \count($points);
$this->similarityMatrix = $this->createSimilarityMatrix($points); $this->similarityMatrix = $this->createSimilarityMatrix($points);
$this->responsibilityMatrix = clone $this->similarityMatrix; $this->responsibilityMatrix = clone $this->similarityMatrix;
$this->availabilityMatrix = clone $this->similarityMatrix; $this->availabilityMatrix = clone $this->similarityMatrix;
for ($c = 0; $c < $iterations; ++$c) { for ($c = 0; $c < $iterations; ++$c) {
for ($i = 0; $i < $n; ++$i) { for ($i = 0; $i < $n; ++$i) {
@ -127,7 +148,7 @@ final class AffinityPropagation implements ClusteringInterface
$sum += \max(0.0, $this->responsibilityMatrix[$j][$k]); $sum += \max(0.0, $this->responsibilityMatrix[$j][$k]);
} }
for ($j = $j + 1; $j < $n; ++$j) { for ($j += 1; $j < $n; ++$j) {
$sum += \max(0.0, $this->responsibilityMatrix[$j][$k]); $sum += \max(0.0, $this->responsibilityMatrix[$j][$k]);
} }
@ -164,15 +185,25 @@ final class AffinityPropagation implements ClusteringInterface
} }
} }
private function findNearestGroup(array $similarityMatrix, int $point, int $clusterCount) : int /**
* Find the nearest group for a point
*
* @param array<int, array<int, int|float> $similarityMatrix Similarity matrix
* @param int $point Point id in the similarity matrix to compare
*
* @return int
*
* @since 1.0.0
*/
private function findNearestGroup(array $similarityMatrix, int $point) : int
{ {
$maxSim = \PHP_INT_MIN; $maxSim = \PHP_INT_MIN;
$group = 0; $group = 0;
foreach ($this->clusterCenters as $c => $_) { foreach ($this->clusterCenters as $c => $_) {
if ($similarityMatrix[$point][$c] > $maxSim) { if ($similarityMatrix[$point][$c] > $maxSim) {
$maxSim = $similarityMatrix[$point][$c]; $maxSim = $similarityMatrix[$point][$c];
$group = $c; $group = $c;
} }
} }
@ -192,7 +223,6 @@ final class AffinityPropagation implements ClusteringInterface
$c = $this->findNearestGroup( $c = $this->findNearestGroup(
$similarityMatrix, $similarityMatrix,
\count($points) - 1, \count($points) - 1,
\count($this->clusterCenters)
); );
return $this->clusterCenters[$c]; return $this->clusterCenters[$c];
@ -207,10 +237,9 @@ final class AffinityPropagation implements ClusteringInterface
return $this->clusters; return $this->clusters;
} }
$clusterCount = \count($this->clusterCenters);
$n = \count($this->points); $n = \count($this->points);
for ($i = 0; $i < $n; ++$i) { for ($i = 0; $i < $n; ++$i) {
$group = $this->findNearestGroup($this->points, $i, $clusterCount); $group = $this->findNearestGroup($this->points, $i);
$this->clusters[$group] = $this->points[$i]; $this->clusters[$group] = $this->points[$i];
} }

View File

@ -69,13 +69,12 @@ final class AgglomerativeClustering implements ClusteringInterface
}; };
$this->linkage = $linkage ?? function (array $a, array $b, array $distances) { $this->linkage = $linkage ?? function (array $a, array $b, array $distances) {
return AgglomerativeClustering::averageDistanceLinkage($a, $b, $distances); return self::averageDistanceLinkage($a, $b, $distances);
}; };
} }
/** /**
* Maximum/Complete-Linkage clustering * Maximum/Complete-Linkage clustering
*
*/ */
public static function maximumDistanceLinkage(array $setA, array $setB, array $distances) : float public static function maximumDistanceLinkage(array $setA, array $setB, array $distances) : float
{ {
@ -93,7 +92,6 @@ final class AgglomerativeClustering implements ClusteringInterface
/** /**
* Minimum/Single-Linkage clustering * Minimum/Single-Linkage clustering
*
*/ */
public static function minimumDistanceLinkage(array $setA, array $setB, array $distances) : float public static function minimumDistanceLinkage(array $setA, array $setB, array $distances) : float
{ {
@ -111,7 +109,6 @@ final class AgglomerativeClustering implements ClusteringInterface
/** /**
* Unweighted average linkage clustering (UPGMA) * Unweighted average linkage clustering (UPGMA)
*
*/ */
public static function averageDistanceLinkage(array $setA, array $setB, array $distances) : float public static function averageDistanceLinkage(array $setA, array $setB, array $distances) : float
{ {
@ -122,6 +119,4 @@ final class AgglomerativeClustering implements ClusteringInterface
return $distance / \count($setA) / \count($setB); return $distance / \count($setA) / \count($setB);
} }
} }

View File

@ -68,4 +68,4 @@ interface ClusteringInterface
// Not possible to interface due to different implementations // Not possible to interface due to different implementations
// public function generateClusters(...) : void // public function generateClusters(...) : void
} }

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace phpOMS\Algorithm\Clustering; namespace phpOMS\Algorithm\Clustering;
use phpOMS\Math\Topology\MetricsND;
/** /**
* Clustering points * Clustering points
* *

View File

@ -269,7 +269,7 @@ final class Kmeans implements ClusteringInterface
} }
foreach ($this->points as $point) { foreach ($this->points as $point) {
$c = $this->cluster($point); $c = $this->cluster($point);
$this->clusters[$c] = $point; $this->clusters[$c] = $point;
} }

View File

@ -57,7 +57,7 @@ class Job implements JobInterface
public string $name = ''; public string $name = '';
/** /**
* Cosntructor. * Constructor.
* *
* @param float $value Value of the job * @param float $value Value of the job
* @param \DateTime $start Start time of the job * @param \DateTime $start Start time of the job

View File

@ -49,7 +49,7 @@ class Item implements ItemInterface
public string $name = ''; public string $name = '';
/** /**
* Cosntructor. * Constructor.
* *
* @param float $value Value of the item * @param float $value Value of the item
* @param float $cost Cost of the item * @param float $cost Cost of the item

View File

@ -54,7 +54,7 @@ class Path
private array $expandedNodes = []; private array $expandedNodes = [];
/** /**
* Cosntructor. * Constructor.
* *
* @param Grid $grid Grid this path belongs to * @param Grid $grid Grid this path belongs to
* *

View File

@ -78,8 +78,8 @@ final class Elo
/** /**
* Calculate an approximated win probability based on elo points. * Calculate an approximated win probability based on elo points.
* *
* @param int $elo1 Elo of the player we want to calculate the win probability for * @param int $elo1 Elo of the player we want to calculate the win probability for
* @param int $elo2 Opponent elo * @param int $elo2 Opponent elo
* @param bool $canDraw Is a draw possible? * @param bool $canDraw Is a draw possible?
* *
* @return float * @return float

View File

@ -40,9 +40,13 @@ class TrueSkill
public const DEFAULT_DRAW_PROBABILITY = 0.1; public const DEFAULT_DRAW_PROBABILITY = 0.1;
private float $mu = 0.0; private float $mu = 0.0;
private float $sigma = 0.0; private float $sigma = 0.0;
private float $beta = 0.0; private float $beta = 0.0;
private float $tau = 0.0; private float $tau = 0.0;
private float $drawProbability = 0.0; private float $drawProbability = 0.0;
public function __construct( public function __construct(
@ -52,25 +56,25 @@ class TrueSkill
float $tau = null, float $tau = null,
float $drawProbability = null) float $drawProbability = null)
{ {
$this->mu = $mu ?? self::DEFAULT_MU; $this->mu = $mu ?? self::DEFAULT_MU;
$this->sigma = $sigma ?? self::DEFAULT_SIGMA; $this->sigma = $sigma ?? self::DEFAULT_SIGMA;
$this->beta = $beta ?? self::DEFAULT_BETA; $this->beta = $beta ?? self::DEFAULT_BETA;
$this->tau = $tau ?? self::DEFAULT_TAU; $this->tau = $tau ?? self::DEFAULT_TAU;
$this->drawProbability = $drawProbability ?? self::DEFAULT_DRAW_PROBABILITY; $this->drawProbability = $drawProbability ?? self::DEFAULT_DRAW_PROBABILITY;
} }
public function winProbability(array $team1, array $team2, float $drawMargin = 0.0) public function winProbability(array $team1, array $team2, float $drawMargin = 0.0)
{ {
$sigmaSum = 0.0; $sigmaSum = 0.0;
$mu1 = 0.0; $mu1 = 0.0;
foreach ($team1 as $player) { foreach ($team1 as $player) {
$mu1 += $player->mu; $mu1 += $player->mu;
$sigmaSum += $player->sigma * $player->sigma; $sigmaSum += $player->sigma * $player->sigma;
} }
$mu2 = 0.0; $mu2 = 0.0;
foreach ($team2 as $player) { foreach ($team2 as $player) {
$mu2 += $player->mu; $mu2 += $player->mu;
$sigmaSum += $player->sigma * $player->sigma; $sigmaSum += $player->sigma * $player->sigma;
} }

View File

@ -1,3 +1,5 @@
<?php <?php
// @todo implement address validation (google?) declare(strict_types=1);
// @todo implement address validation (google?)

View File

@ -20,6 +20,7 @@ use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod; use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest; use phpOMS\Message\Http\Rest;
use phpOMS\System\MimeType;
use phpOMS\Uri\HttpUri; use phpOMS\Uri\HttpUri;
/** /**
@ -192,7 +193,7 @@ final class DHLInternationalShipping implements ShippingInterface
$request = new HttpRequest(new HttpUri($uri)); $request = new HttpRequest(new HttpUri($uri));
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$request->header->set('Content-Type', 'application/json'); $request->header->set('Content-Type', MimeType::M_JSON);
$request->header->set('Accept', '*/*'); $request->header->set('Accept', '*/*');
$request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password));
@ -274,14 +275,18 @@ final class DHLInternationalShipping implements ShippingInterface
array $data array $data
) : array ) : array
{ {
} }
/**
* {@inheritdoc}
*/
public function cancel(string $shipment, array $packages = []) : bool public function cancel(string $shipment, array $packages = []) : bool
{ {
} }
/**
* {@inheritdoc}
*/
public function track(string $shipment) : array public function track(string $shipment) : array
{ {
$base = self::$ENV === 'live' ? self::LIVE_URL : self::SANDBOX2_URL; $base = self::$ENV === 'live' ? self::LIVE_URL : self::SANDBOX2_URL;
@ -302,7 +307,7 @@ final class DHLInternationalShipping implements ShippingInterface
$request = new HttpRequest($httpUri); $request = new HttpRequest($httpUri);
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$request->header->set('accept', 'application/json'); $request->header->set('accept', MimeType::M_JSON);
$request->header->set('dhl-api-key', $this->apiKey); $request->header->set('dhl-api-key', $this->apiKey);
$response = Rest::request($request); $response = Rest::request($request);
@ -311,7 +316,7 @@ final class DHLInternationalShipping implements ShippingInterface
} }
$shipments = $response->getDataArray('shipments') ?? []; $shipments = $response->getDataArray('shipments') ?? [];
$tracking = []; $tracking = [];
// @todo add general shipment status (not just for individual packages) // @todo add general shipment status (not just for individual packages)
@ -322,9 +327,9 @@ final class DHLInternationalShipping implements ShippingInterface
$activities = []; $activities = [];
foreach ($package['events'] as $activity) { foreach ($package['events'] as $activity) {
$activities[] = [ $activities[] = [
'date' => new \DateTime($activity['timestamp']), 'date' => new \DateTime($activity['timestamp']),
'description' => $activity['description'], 'description' => $activity['description'],
'location' => [ 'location' => [
'address' => [ 'address' => [
$activity['location']['address']['streetAddress'], $activity['location']['address']['streetAddress'],
$activity['location']['address']['addressLocality'], $activity['location']['address']['addressLocality'],
@ -339,7 +344,7 @@ final class DHLInternationalShipping implements ShippingInterface
'code' => $activity['statusCode'], 'code' => $activity['statusCode'],
'statusCode' => $activity['statusCode'], 'statusCode' => $activity['statusCode'],
'description' => $activity['status'], 'description' => $activity['status'],
] ],
]; ];
} }
@ -358,8 +363,8 @@ final class DHLInternationalShipping implements ShippingInterface
'by' => $package['details']['proofOfDelivery']['familyName'], 'by' => $package['details']['proofOfDelivery']['familyName'],
'signature' => $package['details']['proofOfDelivery']['signatureUrl'], 'signature' => $package['details']['proofOfDelivery']['signatureUrl'],
'location' => '', 'location' => '',
'date' => $package['details']['proofOfDelivery']['timestamp'] 'date' => $package['details']['proofOfDelivery']['timestamp'],
] ],
]; ];
$tracking[] = $packages; $tracking[] = $packages;
@ -379,10 +384,20 @@ final class DHLInternationalShipping implements ShippingInterface
*/ */
public function label(string $shipment) : array public function label(string $shipment) : array
{ {
return [];
} }
/**
* Finalize shipments (no further changes possible)
*
* @param string[] $shipment Shipments to finalize
*
* @return bool
*
* @since 1.0.0
*/
public function finalize(array $shipment = []) : bool public function finalize(array $shipment = []) : bool
{ {
return true;
} }
} }

View File

@ -21,6 +21,7 @@ use phpOMS\Localization\ISO3166CharEnum;
use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod; use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest; use phpOMS\Message\Http\Rest;
use phpOMS\System\MimeType;
use phpOMS\Uri\HttpUri; use phpOMS\Uri\HttpUri;
/** /**
@ -258,7 +259,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$request = new HttpRequest(new HttpUri($uri)); $request = new HttpRequest(new HttpUri($uri));
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$request->header->set('Accept', 'application/json'); $request->header->set('Accept', MimeType::M_JSON);
$request->header->set('dhl-api-key', $key); $request->header->set('dhl-api-key', $key);
$response = Rest::request($request); $response = Rest::request($request);
@ -312,7 +313,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$request = new HttpRequest($httpUri); $request = new HttpRequest($httpUri);
$request->setMethod(RequestMethod::POST); $request->setMethod(RequestMethod::POST);
$request->header->set('Content-Type', 'application/json'); $request->header->set('Content-Type', MimeType::M_JSON);
$request->header->set('Accept-Language', 'en-US'); $request->header->set('Accept-Language', 'en-US');
$request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password));
@ -320,42 +321,42 @@ final class DHLParcelDEShipping implements ShippingInterface
$shipments = [ $shipments = [
[ [
'product' => 'V01PAK', // V53WPAK, V53WPAK 'product' => 'V01PAK', // V53WPAK, V53WPAK
'billingNumber' => $data['costcenter'], // @todo maybe dhl number, check 'billingNumber' => $data['costcenter'], // @todo maybe dhl number, check
'refNo' => $package['id'], 'refNo' => $package['id'],
'shipper' => [ 'shipper' => [
'name1' => $sender['name'], 'name1' => $sender['name'],
'addressStreet' => $sender['address'], 'addressStreet' => $sender['address'],
'additionalAddressInformation1' => $sender['address_addition'], 'additionalAddressInformation1' => $sender['address_addition'],
'postalCode' => $sender['zip'], 'postalCode' => $sender['zip'],
'city' => $sender['city'], 'city' => $sender['city'],
'country' => ISO3166CharEnum::getBy2Code($sender['country_code']), 'country' => ISO3166CharEnum::getBy2Code($sender['country_code']),
'email' => $sender['email'], 'email' => $sender['email'],
'phone' => $sender['phone'], 'phone' => $sender['phone'],
], ],
'consignee' => [ 'consignee' => [
'name1' => $receiver['name'], 'name1' => $receiver['name'],
'addressStreet' => $receiver['address'], 'addressStreet' => $receiver['address'],
'additionalAddressInformation1' => $receiver['address_addition'], 'additionalAddressInformation1' => $receiver['address_addition'],
'postalCode' => $receiver['zip'], 'postalCode' => $receiver['zip'],
'city' => $receiver['city'], 'city' => $receiver['city'],
'country' => ISO3166CharEnum::getBy2Code($receiver['country_code']), 'country' => ISO3166CharEnum::getBy2Code($receiver['country_code']),
'email' => $receiver['email'], 'email' => $receiver['email'],
'phone' => $receiver['phone'], 'phone' => $receiver['phone'],
], ],
'details' => [ 'details' => [
'dim' => [ 'dim' => [
'uom' => 'mm', 'uom' => 'mm',
'height' => $package['height'], 'height' => $package['height'],
'length' => $package['length'], 'length' => $package['length'],
'width' => $package['width'], 'width' => $package['width'],
], ],
'weight' => [ 'weight' => [
'uom' => 'g', 'uom' => 'g',
'value' => $package['weight'], 'value' => $package['weight'],
], ],
] ],
] ],
]; ];
$request->setData('shipments', $shipments); $request->setData('shipments', $shipments);
@ -368,23 +369,23 @@ final class DHLParcelDEShipping implements ShippingInterface
$result = $response->getDataArray('items') ?? []; $result = $response->getDataArray('items') ?? [];
$labelUri = new HttpUri($result[0]['label']['url']); $labelUri = new HttpUri($result[0]['label']['url']);
$label = $this->label($labelUri->getQuery('token')); $label = $this->label($labelUri->getQuery('token'));
return [ return [
'id' => $result[0]['shipmentNo'], 'id' => $result[0]['shipmentNo'],
'label' => [ 'label' => [
'code' => $result[0]['label']['format'], 'code' => $result[0]['label']['format'],
'url' => $result[0]['label']['url'], 'url' => $result[0]['label']['url'],
'data' => $label['data'], 'data' => $label['data'],
], ],
'packages' => [ 'packages' => [
'id' => $result[0]['shipmentNo'], 'id' => $result[0]['shipmentNo'],
'label' => [ 'label' => [
'code' => $result[0]['label']['format'], 'code' => $result[0]['label']['format'],
'url' => $result[0]['label']['url'], 'url' => $result[0]['label']['url'],
'data' => $label['data'], 'data' => $label['data'],
] ],
] ],
]; ];
} }
@ -445,23 +446,23 @@ final class DHLParcelDEShipping implements ShippingInterface
$result = $response->getDataArray('items') ?? []; $result = $response->getDataArray('items') ?? [];
$labelUri = new HttpUri($result[0]['label']['url']); $labelUri = new HttpUri($result[0]['label']['url']);
$label = $this->label($labelUri->getQuery('token')); $label = $this->label($labelUri->getQuery('token'));
return [ return [
'id' => $result[0]['shipmentNo'], 'id' => $result[0]['shipmentNo'],
'label' => [ 'label' => [
'code' => $result[0]['label']['format'], 'code' => $result[0]['label']['format'],
'url' => $result[0]['label']['url'], 'url' => $result[0]['label']['url'],
'data' => $label['data'], 'data' => $label['data'],
], ],
'packages' => [ 'packages' => [
'id' => $result[0]['shipmentNo'], 'id' => $result[0]['shipmentNo'],
'label' => [ 'label' => [
'code' => $result[0]['label']['format'], 'code' => $result[0]['label']['format'],
'url' => $result[0]['label']['url'], 'url' => $result[0]['label']['url'],
'data' => $label['data'], 'data' => $label['data'],
] ],
] ],
]; ];
} }
@ -484,7 +485,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$request = new HttpRequest($httpUri); $request = new HttpRequest($httpUri);
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$request->header->set('Content-Type', 'application/pdf'); $request->header->set('Content-Type', MimeType::M_PDF);
$response = Rest::request($request); $response = Rest::request($request);
if ($response->header->status !== 200) { if ($response->header->status !== 200) {
@ -519,7 +520,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$request = new HttpRequest($httpUri); $request = new HttpRequest($httpUri);
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$request->header->set('accept', 'application/json'); $request->header->set('accept', MimeType::M_JSON);
$request->header->set('dhl-api-key', $this->apiKey); $request->header->set('dhl-api-key', $this->apiKey);
$response = Rest::request($request); $response = Rest::request($request);
@ -528,7 +529,7 @@ final class DHLParcelDEShipping implements ShippingInterface
} }
$shipments = $response->getDataArray('shipments') ?? []; $shipments = $response->getDataArray('shipments') ?? [];
$tracking = []; $tracking = [];
// @todo add general shipment status (not just for individual packages) // @todo add general shipment status (not just for individual packages)
@ -539,9 +540,9 @@ final class DHLParcelDEShipping implements ShippingInterface
$activities = []; $activities = [];
foreach ($package['events'] as $activity) { foreach ($package['events'] as $activity) {
$activities[] = [ $activities[] = [
'date' => new \DateTime($activity['timestamp']), 'date' => new \DateTime($activity['timestamp']),
'description' => $activity['description'], 'description' => $activity['description'],
'location' => [ 'location' => [
'address' => [ 'address' => [
$activity['location']['address']['streetAddress'], $activity['location']['address']['streetAddress'],
$activity['location']['address']['addressLocality'], $activity['location']['address']['addressLocality'],
@ -556,7 +557,7 @@ final class DHLParcelDEShipping implements ShippingInterface
'code' => $activity['statusCode'], 'code' => $activity['statusCode'],
'statusCode' => $activity['statusCode'], 'statusCode' => $activity['statusCode'],
'description' => $activity['status'], 'description' => $activity['status'],
] ],
]; ];
} }
@ -575,8 +576,8 @@ final class DHLParcelDEShipping implements ShippingInterface
'by' => $package['details']['proofOfDelivery']['familyName'], 'by' => $package['details']['proofOfDelivery']['familyName'],
'signature' => $package['details']['proofOfDelivery']['signatureUrl'], 'signature' => $package['details']['proofOfDelivery']['signatureUrl'],
'location' => '', 'location' => '',
'date' => $package['details']['proofOfDelivery']['timestamp'] 'date' => $package['details']['proofOfDelivery']['timestamp'],
] ],
]; ];
$tracking[] = $packages; $tracking[] = $packages;
@ -615,10 +616,10 @@ final class DHLParcelDEShipping implements ShippingInterface
} }
return [ return [
'date' => $response->getDataDateTime('manifestDate'), 'date' => $response->getDataDateTime('manifestDate'),
'b64' => $response->getDataArray('manifest')['b64'], 'b64' => $response->getDataArray('manifest')['b64'],
'zpl2' => $response->getDataArray('manifest')['zpl2'], 'zpl2' => $response->getDataArray('manifest')['zpl2'],
'url' => $response->getDataArray('manifest')['url'], 'url' => $response->getDataArray('manifest')['url'],
'format' => $response->getDataArray('manifest')['printFormat'], 'format' => $response->getDataArray('manifest')['printFormat'],
]; ];
} }
@ -644,7 +645,7 @@ final class DHLParcelDEShipping implements ShippingInterface
$request = new HttpRequest($httpUri); $request = new HttpRequest($httpUri);
$request->setMethod(RequestMethod::POST); $request->setMethod(RequestMethod::POST);
$request->header->set('Content-Type', 'application/json'); $request->header->set('Content-Type', MimeType::M_JSON);
$request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password));
if (!empty($shipment)) { if (!empty($shipment)) {

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\DHL; namespace phpOMS\Api\Shipping\DHL;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -33,4 +29,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class DHLParcelDEShipping implements ShippingInterface final class DHLParcelDEShipping implements ShippingInterface
{ {
} }

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\DPD; namespace phpOMS\Api\Shipping\DPD;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -32,4 +28,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class DPDShipping implements ShippingInterface final class DPDShipping implements ShippingInterface
{ {
} }

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\Fedex; namespace phpOMS\Api\Shipping\Fedex;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class FedexShipping implements ShippingInterface final class FedexShipping implements ShippingInterface
{ {
} }

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\RoyalMail; namespace phpOMS\Api\Shipping\RoyalMail;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class RoyalMailShipping implements ShippingInterface final class RoyalMailShipping implements ShippingInterface
{ {
} }

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping; namespace phpOMS\Api\Shipping;
use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
/** /**
* Shipping interface. * Shipping interface.
@ -32,7 +31,7 @@ use phpOMS\Message\Http\HttpResponse;
* *
* @todo implement Sender, Receiver, Package, Transit, Tracking classes for better type hinting instead of arrays * @todo implement Sender, Receiver, Package, Transit, Tracking classes for better type hinting instead of arrays
* *
* @property string $ENV ('live' = live environment, 'test' or 'sandbox' = test environment) * @property string $ENV ('live' = live environment, 'test' or 'sandbox' = test environment)
* @property string $client * @property string $client
* @property string $token * @property string $token
* @property string $refreshToken * @property string $refreshToken
@ -93,7 +92,7 @@ interface ShippingInterface
* *
* @param string $login Login name/email * @param string $login Login name/email
* @param string $password Password * @param string $password Password
* @param HttpRequest $redirect Redirect request after the user successfully logged in. * @param HttpRequest $redirect redirect request after the user successfully logged in
* *
* @return int Returns auth status * @return int Returns auth status
* *
@ -131,7 +130,7 @@ interface ShippingInterface
* *
* @param array $sender Sender * @param array $sender Sender
* @param array $shipFrom Ship from location (sometimes sender != pickup location) * @param array $shipFrom Ship from location (sometimes sender != pickup location)
* @param array $recevier Receiver * @param array $receiver Receiver
* @param array $package Package * @param array $package Package
* @param array $data Shipping data * @param array $data Shipping data
* *
@ -150,7 +149,7 @@ interface ShippingInterface
/** /**
* Cancel shipment. * Cancel shipment.
* *
* @param string $shipment Shipment id * @param string $shipment Shipment id
* @param string[] $packages Packed ids (if a shipment consists of multiple packages) * @param string[] $packages Packed ids (if a shipment consists of multiple packages)
* *
* @return bool * @return bool

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\TNT; namespace phpOMS\Api\Shipping\TNT;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class TNTShipping implements ShippingInterface final class TNTShipping implements ShippingInterface
{ {
} }

View File

@ -20,6 +20,7 @@ use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod; use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest; use phpOMS\Message\Http\Rest;
use phpOMS\System\MimeType;
use phpOMS\Uri\HttpUri; use phpOMS\Uri\HttpUri;
/** /**
@ -177,7 +178,7 @@ final class UPSShipping implements ShippingInterface
$request = new HttpRequest(new HttpUri($uri)); $request = new HttpRequest(new HttpUri($uri));
$request->setMethod(RequestMethod::POST); $request->setMethod(RequestMethod::POST);
$request->setData('grant_type', 'client_credentials'); $request->setData('grant_type', 'client_credentials');
$request->header->set('Content-Type', 'application/x-www-form-urlencoded'); $request->header->set('Content-Type', MimeType::M_POST);
$request->header->set('x-merchant-id', $client); $request->header->set('x-merchant-id', $client);
$request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password));
@ -255,7 +256,7 @@ final class UPSShipping implements ShippingInterface
// Personally I don't see why a redirect is required or even helpful. Will try without it! // Personally I don't see why a redirect is required or even helpful. Will try without it!
$request->setData('grant_type', 'authorization_code'); $request->setData('grant_type', 'authorization_code');
$request->setData('code', $code); $request->setData('code', $code);
$request->header->set('Content-Type', 'application/x-www-form-urlencoded'); $request->header->set('Content-Type', MimeType::M_POST);
$request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($login . ':' . $password));
$this->expire = new \DateTime('now'); $this->expire = new \DateTime('now');
@ -306,7 +307,7 @@ final class UPSShipping implements ShippingInterface
$request = new HttpRequest(new HttpUri($uri)); $request = new HttpRequest(new HttpUri($uri));
$request->setMethod(RequestMethod::POST); $request->setMethod(RequestMethod::POST);
$request->header->set('Content-Type', 'application/x-www-form-urlencoded'); $request->header->set('Content-Type', MimeType::M_POST);
$request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password)); $request->header->set('Authorization', 'Basic ' . \base64_encode($this->login . ':' . $this->password));
$request->setData('grant_type', 'refresh_token'); $request->setData('grant_type', 'refresh_token');
@ -367,7 +368,7 @@ final class UPSShipping implements ShippingInterface
$request = new HttpRequest(new HttpUri($uri)); $request = new HttpRequest(new HttpUri($uri));
$request->setMethod(RequestMethod::POST); $request->setMethod(RequestMethod::POST);
$request->header->set('Content-Type', 'application/json'); $request->header->set('Content-Type', MimeType::M_JSON);
$request->header->set('Authorization', 'Bearer ' . $this->token); $request->header->set('Authorization', 'Bearer ' . $this->token);
$request->header->set('transId', ((string) \microtime(true)) . '-' . \bin2hex(\random_bytes(6))); $request->header->set('transId', ((string) \microtime(true)) . '-' . \bin2hex(\random_bytes(6)));
$request->header->set('transactionSrc', 'jingga'); $request->header->set('transactionSrc', 'jingga');
@ -402,10 +403,10 @@ final class UPSShipping implements ShippingInterface
foreach ($services as $service) { foreach ($services as $service) {
$transits[] = [ $transits[] = [
'serviceLevel' => $service['serviceLevel'], 'serviceLevel' => $service['serviceLevel'],
'deliveryDate' => new \DateTime($service['deliveryDaye']), 'deliveryDate' => new \DateTime($service['deliveryDaye']),
'deliveryDateFrom' => null, 'deliveryDateFrom' => null,
'deliveryDateTo' => null, 'deliveryDateTo' => null,
]; ];
} }
@ -440,9 +441,9 @@ final class UPSShipping implements ShippingInterface
'SubVersion' => '2205', 'SubVersion' => '2205',
], ],
'Shipment' => [ 'Shipment' => [
'Description' => $package['description'], 'Description' => $package['description'],
'DocumentsOnlyIndicator' => '0', 'DocumentsOnlyIndicator' => '0',
'Shipper' => [ 'Shipper' => [
'Name' => \substr($sender['name'], 0, 35), 'Name' => \substr($sender['name'], 0, 35),
'AttentionName' => \substr($sender['fao'], 0, 35), 'AttentionName' => \substr($sender['fao'], 0, 35),
'CompanyDisplayableName' => \substr($sender['name'], 0, 35), 'CompanyDisplayableName' => \substr($sender['name'], 0, 35),
@ -452,7 +453,7 @@ final class UPSShipping implements ShippingInterface
], ],
'ShipperNumber' => $sender['number'], 'ShipperNumber' => $sender['number'],
'EMailAddress' => \substr($sender['email'], 0, 50), 'EMailAddress' => \substr($sender['email'], 0, 50),
'Address' => [ 'Address' => [
'AddressLine' => \substr($sender['address'], 0, 35), 'AddressLine' => \substr($sender['address'], 0, 35),
'City' => \substr($sender['city'], 0, 30), 'City' => \substr($sender['city'], 0, 30),
'StateProvinceCode' => \substr($sender['state'], 0, 5), 'StateProvinceCode' => \substr($sender['state'], 0, 5),
@ -470,7 +471,7 @@ final class UPSShipping implements ShippingInterface
], ],
'ShipperNumber' => $receiver['number'], 'ShipperNumber' => $receiver['number'],
'EMailAddress' => \substr($receiver['email'], 0, 50), 'EMailAddress' => \substr($receiver['email'], 0, 50),
'Address' => [ 'Address' => [
'AddressLine' => \substr($receiver['address'], 0, 35), 'AddressLine' => \substr($receiver['address'], 0, 35),
'City' => \substr($receiver['city'], 0, 30), 'City' => \substr($receiver['city'], 0, 30),
'StateProvinceCode' => \substr($receiver['state'], 0, 5), 'StateProvinceCode' => \substr($receiver['state'], 0, 5),
@ -497,7 +498,7 @@ final class UPSShipping implements ShippingInterface
'CostCenter' => \substr($package['costcenter'], 0, 30), 'CostCenter' => \substr($package['costcenter'], 0, 30),
'PackageID' => \substr($package['id'], 0, 30), 'PackageID' => \substr($package['id'], 0, 30),
'PackageIDBarcodeIndicator' => '1', 'PackageIDBarcodeIndicator' => '1',
'Package' => [] 'Package' => [],
], ],
'LabelSpecification' => [ 'LabelSpecification' => [
'LabelImageFormat' => [ 'LabelImageFormat' => [
@ -507,13 +508,13 @@ final class UPSShipping implements ShippingInterface
'LabelStockSize' => [ 'LabelStockSize' => [
'Height' => $data['label_height'], 'Height' => $data['label_height'],
'Width' => $data['label_width'], 'Width' => $data['label_width'],
] ],
], ],
'ReceiptSpecification' => [ 'ReceiptSpecification' => [
'ImageFormat' => [ 'ImageFormat' => [
'Code' => $data['receipt_code'], 'Code' => $data['receipt_code'],
'Description' => \substr($data['receipt_description'], 0, 35), 'Description' => \substr($data['receipt_description'], 0, 35),
] ],
], ],
]; ];
@ -521,13 +522,13 @@ final class UPSShipping implements ShippingInterface
foreach ($package['packages'] as $p) { foreach ($package['packages'] as $p) {
$packages[] = [ $packages[] = [
'Description' => \substr($p['description'], 0, 35), 'Description' => \substr($p['description'], 0, 35),
'Packaging' => [ 'Packaging' => [
'Code' => $p['package_code'], 'Code' => $p['package_code'],
'Description' => $p['package_description'] 'Description' => $p['package_description'],
], ],
'Dimensions' => [ 'Dimensions' => [
'UnitOfMeasurement' => [ 'UnitOfMeasurement' => [
'Code' => $p['package_dim_unit'], // IN or CM or 00 or 01 'Code' => $p['package_dim_unit'], // IN or CM or 00 or 01
'Description' => \substr($p['package_dim_unit_description'], 0, 35), 'Description' => \substr($p['package_dim_unit_description'], 0, 35),
], ],
'Length' => $p['length'], 'Length' => $p['length'],
@ -547,7 +548,7 @@ final class UPSShipping implements ShippingInterface
'Description' => \substr($p['package_weight_unit_description'], 0, 35), 'Description' => \substr($p['package_weight_unit_description'], 0, 35),
], ],
'Weight' => $p['weight'], 'Weight' => $p['weight'],
] ],
]; ];
} }
@ -566,7 +567,7 @@ final class UPSShipping implements ShippingInterface
], ],
'ShipperNumber' => $shipFrom['number'], 'ShipperNumber' => $shipFrom['number'],
'EMailAddress' => \substr($shipFrom['email'], 0, 50), 'EMailAddress' => \substr($shipFrom['email'], 0, 50),
'Address' => [ 'Address' => [
'AddressLine' => \substr($shipFrom['address'], 0, 35), 'AddressLine' => \substr($shipFrom['address'], 0, 35),
'City' => \substr($shipFrom['city'], 0, 30), 'City' => \substr($shipFrom['city'], 0, 30),
'StateProvinceCode' => \substr($shipFrom['state'], 0, 5), 'StateProvinceCode' => \substr($shipFrom['state'], 0, 5),
@ -586,7 +587,7 @@ final class UPSShipping implements ShippingInterface
$result = $response->getDataArray('ShipmentResponse') ?? []; $result = $response->getDataArray('ShipmentResponse') ?? [];
$shipment = [ $shipment = [
'id' => $result['ShipmentResults']['ShipmentIdentificationNumber'] ?? '', 'id' => $result['ShipmentResults']['ShipmentIdentificationNumber'] ?? '',
'costs' => [ 'costs' => [
'service' => $result['ShipmentResults']['ShipmentCharges']['BaseServiceCharge']['MonetaryValue'] ?? null, 'service' => $result['ShipmentResults']['ShipmentCharges']['BaseServiceCharge']['MonetaryValue'] ?? null,
'transportation' => $result['ShipmentResults']['ShipmentCharges']['TransportationCharges']['MonetaryValue'] ?? null, 'transportation' => $result['ShipmentResults']['ShipmentCharges']['TransportationCharges']['MonetaryValue'] ?? null,
@ -598,38 +599,38 @@ final class UPSShipping implements ShippingInterface
'currency' => $result['ShipmentResults']['ShipmentCharges']['TotalCharges']['CurrencyCode'] ?? null, 'currency' => $result['ShipmentResults']['ShipmentCharges']['TotalCharges']['CurrencyCode'] ?? null,
], ],
'packages' => [], 'packages' => [],
'label' => [ 'label' => [
'code' => '', 'code' => '',
'url' => $result['ShipmentResults']['LabelURL'] ?? '', 'url' => $result['ShipmentResults']['LabelURL'] ?? '',
'barcode' => $result['ShipmentResults']['BarCodeImage'] ?? '', 'barcode' => $result['ShipmentResults']['BarCodeImage'] ?? '',
'local' => $result['ShipmentResults']['LocalLanguageLabelURL'] ?? '', 'local' => $result['ShipmentResults']['LocalLanguageLabelURL'] ?? '',
'data' => '', 'data' => '',
], ],
'receipt' => [ 'receipt' => [
'code' => '', 'code' => '',
'url' => $result['ShipmentResults']['ReceiptURL'] ?? '', 'url' => $result['ShipmentResults']['ReceiptURL'] ?? '',
'local' => $result['ShipmentResults']['LocalLanguageReceiptURL'] ?? '', 'local' => $result['ShipmentResults']['LocalLanguageReceiptURL'] ?? '',
'data' => '', 'data' => '',
] ],
// @todo dangerous goods paper image // @todo dangerous goods paper image
]; ];
$packages = []; $packages = [];
foreach ($result['ShipmentResults']['Packages'] as $package) { foreach ($result['ShipmentResults']['Packages'] as $package) {
$packages[] = [ $packages[] = [
'id' => $package['TrackingNumber'], 'id' => $package['TrackingNumber'],
'label' => [ 'label' => [
'code' => $package['ShippingLabel']['ImageFormat']['Code'], 'code' => $package['ShippingLabel']['ImageFormat']['Code'],
'url' => '', 'url' => '',
'barcode' => $package['PDF417'], 'barcode' => $package['PDF417'],
'image' => $package['ShippingLabel']['GraphicImage'], 'image' => $package['ShippingLabel']['GraphicImage'],
'browser' => $package['HTMLImage'], 'browser' => $package['HTMLImage'],
'data' => '', 'data' => '',
], ],
'receipt' => [ 'receipt' => [
'code' => $package['ShippingReceipt']['ImageFormat']['Code'], 'code' => $package['ShippingReceipt']['ImageFormat']['Code'],
'image' => $package['ShippingReceipt']['ImageFormat']['GraphicImage'], 'image' => $package['ShippingReceipt']['ImageFormat']['GraphicImage'],
] ],
]; ];
} }
@ -707,9 +708,9 @@ final class UPSShipping implements ShippingInterface
$activities = []; $activities = [];
foreach ($package['activity'] as $activity) { foreach ($package['activity'] as $activity) {
$activities[] = [ $activities[] = [
'date' => new \DateTime($activity['date'] . ' ' . $activity['time']), 'date' => new \DateTime($activity['date'] . ' ' . $activity['time']),
'description' => '', 'description' => '',
'location' => [ 'location' => [
'address' => [ 'address' => [
$activity['location']['address']['addressLine1'], $activity['location']['address']['addressLine1'],
$activity['location']['address']['addressLine2'], $activity['location']['address']['addressLine2'],
@ -725,7 +726,7 @@ final class UPSShipping implements ShippingInterface
'code' => $activity['status']['code'], 'code' => $activity['status']['code'],
'statusCode' => $activity['status']['statusCode'], 'statusCode' => $activity['status']['statusCode'],
'description' => $activity['status']['description'], 'description' => $activity['status']['description'],
] ],
]; ];
} }
@ -745,7 +746,7 @@ final class UPSShipping implements ShippingInterface
'signature' => $package['deliveryInformation']['signature'], 'signature' => $package['deliveryInformation']['signature'],
'location' => $package['deliveryInformation']['location'], 'location' => $package['deliveryInformation']['location'],
'date' => '', 'date' => '',
] ],
]; ];
} }

View File

@ -15,10 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Api\Shipping\Usps; namespace phpOMS\Api\Shipping\Usps;
use phpOMS\Api\Shipping\ShippingInterface; use phpOMS\Api\Shipping\ShippingInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\RequestMethod;
use phpOMS\Message\Http\Rest;
use phpOMS\Uri\HttpUri;
/** /**
* Shipment api. * Shipment api.
@ -31,4 +27,4 @@ use phpOMS\Uri\HttpUri;
*/ */
final class UspsShipping implements ShippingInterface final class UspsShipping implements ShippingInterface
{ {
} }

View File

@ -138,6 +138,17 @@ final class Autoloader
$class = \ltrim($class, '\\'); $class = \ltrim($class, '\\');
$class = \strtr($class, '_\\', '//'); $class = \strtr($class, '_\\', '//');
if (self::$useClassMap) {
$nspacePos = \strpos($class, '/');
$subclass = $nspacePos === false ? '' : \substr($class, 0, $nspacePos);
if (isset(self::$classmap[$subclass])) {
$found[] = self::$classmap[$subclass] . $class . '.php';
return $found;
}
}
foreach (self::$paths as $path) { foreach (self::$paths as $path) {
if (\is_file($file = $path . $class . '.php')) { if (\is_file($file = $path . $class . '.php')) {
$found[] = $file; $found[] = $file;

View File

@ -137,7 +137,7 @@ final class Metrics
} }
/** /**
* Calculate the profitability of customers based on their purchase behaviour * Calculate the profitability of customers based on their purchase behavior
* *
* The basis for the calculation is the migration model using a markov chain * The basis for the calculation is the migration model using a markov chain
* *

View File

@ -37,7 +37,7 @@ final class ArticleCorrelationAffinity
private array $affinity = []; private array $affinity = [];
/** /**
* Item order behaviour (when are which items ordered) * Item order behavior (when are which items ordered)
* *
* In tearms of the pearson correlation these are our random variables * In tearms of the pearson correlation these are our random variables
* *

View File

@ -38,6 +38,13 @@ abstract class MapperType extends Enum
public const GET_RANDOM = 11; public const GET_RANDOM = 11;
// @IMPORTANT All read operations which use column names must have an ID < 12
// In the read mapper exists a line which checks for < COUNT_MODELS to decide if columns should be selected.
// The reason for this is that **pure** count, sum, ... don't want to select additional column names.
// By doing this we avoid loading all the unwanted columns coming from the `with()` relation.
// -------------------------------------------- //
public const COUNT_MODELS = 12; public const COUNT_MODELS = 12;
public const SUM_MODELS = 13; public const SUM_MODELS = 13;

View File

@ -536,9 +536,14 @@ final class ReadMapper extends DataMapperAbstract
public function getQuery(Builder $query = null, array $columns = []) : Builder public function getQuery(Builder $query = null, array $columns = []) : Builder
{ {
$query ??= $this->query ?? new Builder($this->db, true); $query ??= $this->query ?? new Builder($this->db, true);
$columns = empty($columns)
? (empty($this->columns) ? $this->mapper::COLUMNS : $this->columns) if (empty($columns) && $this->type < MapperType::COUNT_MODELS) {
: $columns; if (empty($this->columns)) {
$columns = $this->mapper::COLUMNS;
} else {
$columns = $this->columns;
}
}
foreach ($columns as $key => $values) { foreach ($columns as $key => $values) {
if (\is_string($values) || \is_int($values)) { if (\is_string($values) || \is_int($values)) {
@ -731,6 +736,7 @@ final class ReadMapper extends DataMapperAbstract
/** @var self $relMapper */ /** @var self $relMapper */
$relMapper = $this->createRelationMapper($rel['mapper']::reader(db: $this->db), $member); $relMapper = $this->createRelationMapper($rel['mapper']::reader(db: $this->db), $member);
$relMapper->depth = $this->depth + 1; $relMapper->depth = $this->depth + 1;
$relMapper->type = $this->type;
$query = $relMapper->getQuery( $query = $relMapper->getQuery(
$query, $query,
@ -846,7 +852,7 @@ final class ReadMapper extends DataMapperAbstract
} }
if (empty($value)) { if (empty($value)) {
// @todo find better solution. this was because of a bug with the sales billing list query depth = 4. The address was set (from the client, referral or creator) but then somehow there was a second address element which was all null and null cannot be asigned to a string variable (e.g. country). The problem with this solution is that if the model expects an initialization (e.g. at lest set the elements to null, '', 0 etc.) this is now not done. // @todo find better solution. this was because of a bug with the sales billing list query depth = 4. The address was set (from the client, referral or creator) but then somehow there was a second address element which was all null and null cannot be assigned to a string variable (e.g. country). The problem with this solution is that if the model expects an initialization (e.g. at lest set the elements to null, '', 0 etc.) this is now not done.
$value = $isPrivate ? $refProp->getValue($obj) : $obj->{$member}; $value = $isPrivate ? $refProp->getValue($obj) : $obj->{$member};
} }
} elseif (isset($this->mapper::BELONGS_TO[$def['internal']])) { } elseif (isset($this->mapper::BELONGS_TO[$def['internal']])) {
@ -912,10 +918,16 @@ final class ReadMapper extends DataMapperAbstract
// @todo How is this allowed? at the bottom we set $obj->hasMany = value. A has many should be always an array?! // @todo How is this allowed? at the bottom we set $obj->hasMany = value. A has many should be always an array?!
foreach ($this->mapper::HAS_MANY as $member => $def) { foreach ($this->mapper::HAS_MANY as $member => $def) {
if (!isset($this->with[$member])
|| !isset($def['column']) // @todo is this required? The code below indicates that this might be stupid
) {
continue;
}
$column = $def['mapper']::getColumnByMember($def['column'] ?? $member); $column = $def['mapper']::getColumnByMember($def['column'] ?? $member);
$alias = $column . '_d' . ($this->depth + 1); $alias = $column . '_d' . ($this->depth + 1);
if (!\array_key_exists($alias, $result) || !isset($def['column'])) { if (!\array_key_exists($alias, $result)) {
continue; continue;
} }
@ -1145,7 +1157,7 @@ final class ReadMapper extends DataMapperAbstract
->where($many['table'] . '.' . $many['self'], '=', $primaryKey); ->where($many['table'] . '.' . $many['self'], '=', $primaryKey);
// Cannot use join, because join only works on members and we don't have members for a relation table // Cannot use join, because join only works on members and we don't have members for a relation table
// This is why we need to create a "base" query which contians the join on table columns // This is why we need to create a "base" query which contains the join on table columns
$objectMapper->query($query); $objectMapper->query($query);
} }
@ -1162,12 +1174,12 @@ final class ReadMapper extends DataMapperAbstract
$refProp = $refClass->getProperty($member); $refProp = $refClass->getProperty($member);
$refProp->setValue($obj, !\is_array($objects) && ($many['conditional'] ?? false) === false $refProp->setValue($obj, !\is_array($objects) && ($many['conditional'] ?? false) === false
? [$many['mapper']::getObjectId($objects) => $objects] ? [$many['mapper']::getObjectId($objects) => $objects]
: $objects // if conditional === true the obj will be asigned (e.g. has many localizations but only one is loaded for the model) : $objects // if conditional === true the obj will be assigned (e.g. has many localizations but only one is loaded for the model)
); );
} else { } else {
$obj->{$member} = !\is_array($objects) && ($many['conditional'] ?? false) === false $obj->{$member} = !\is_array($objects) && ($many['conditional'] ?? false) === false
? [$many['mapper']::getObjectId($objects) => $objects] ? [$many['mapper']::getObjectId($objects) => $objects]
: $objects; // if conditional === true the obj will be asigned (e.g. has many localizations but only one is loaded for the model) : $objects; // if conditional === true the obj will be assigned (e.g. has many localizations but only one is loaded for the model)
} }
continue; continue;
@ -1244,7 +1256,7 @@ final class ReadMapper extends DataMapperAbstract
->where($many['table'] . '.' . $many['self'], '=', $primaryKey); ->where($many['table'] . '.' . $many['self'], '=', $primaryKey);
// Cannot use join, because join only works on members and we don't have members for a relation table // Cannot use join, because join only works on members and we don't have members for a relation table
// This is why we need to create a "base" query which contians the join on table columns // This is why we need to create a "base" query which contains the join on table columns
$objectMapper->query($query); $objectMapper->query($query);
} }

View File

@ -458,9 +458,11 @@ class Grammar extends GrammarAbstract
$expression .= '(' . \rtrim($this->compileWhereQuery($element['column']), ';') . ')'; $expression .= '(' . \rtrim($this->compileWhereQuery($element['column']), ';') . ')';
} }
// @todo on doesn't allow values as value (only table column names). This is bad and needs to be fixed! // @todo on doesn't allow string values as value (only table column names). This is bad and needs to be fixed!
// Other types such as int etc. are kind of possible
if (isset($element['value'])) { if (isset($element['value'])) {
$expression .= ' ' . \strtoupper($element['operator']) . ' ' . $this->compileSystem($element['value']); $expression .= ' ' . \strtoupper($element['operator']) . ' '
. (\is_string($element['value']) ? $this->compileSystem($element['value']) : $element['value']);
} else { } else {
$operator = $element['operator'] === '=' ? 'IS' : 'IS NOT'; $operator = $element['operator'] === '=' ? 'IS' : 'IS NOT';
$expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']); $expression .= ' ' . $operator . ' ' . $this->compileValue($query, $element['value']);

View File

@ -125,7 +125,7 @@ final class Kernel
/** /**
* Apply kernel matrix * Apply kernel matrix
* *
* @param string $inParth Image file path * @param string $inPath Image file path
* @param string $outPath Image output path * @param string $outPath Image output path
* @param array $kernel Kernel matrix * @param array $kernel Kernel matrix
* *

View File

@ -544,7 +544,7 @@ class Matrix implements \ArrayAccess, \Iterator
if ($mDim > 10 || $nDim > 10) { if ($mDim > 10 || $nDim > 10) {
// Standard transposed for iteration over rows -> higher cache hit // Standard transposed for iteration over rows -> higher cache hit
$transposedMatrixArr = array(); $transposedMatrixArr = [];
for ($k = 0; $k < $mDim; ++$k) { for ($k = 0; $k < $mDim; ++$k) {
for ($j = 0; $j < $nDim; ++$j) { for ($j = 0; $j < $nDim; ++$j) {
$transposedMatrixArr[$k][$j] = $matrixArr[$j][$k]; $transposedMatrixArr[$k][$j] = $matrixArr[$j][$k];

View File

@ -123,7 +123,6 @@ final class Vector extends Matrix
return $dotProduct / ($magnitude1 * $magnitude2); return $dotProduct / ($magnitude1 * $magnitude2);
} }
/** /**
* Calculate the eucledian dot product * Calculate the eucledian dot product
* *

View File

@ -131,7 +131,7 @@ final class Simplex
} }
} }
$this->b[$x] /= -$this->A[$x][$y]; $this->b[$x] /= -$this->A[$x][$y];
$this->A[$x][$y] = 1.0 / $this->A[$x][$y]; $this->A[$x][$y] = 1.0 / $this->A[$x][$y];
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
@ -142,7 +142,7 @@ final class Simplex
} }
} }
$this->b[$i] += $this->A[$i][$y] * $this->b[$x]; $this->b[$i] += $this->A[$i][$y] * $this->b[$x];
$this->A[$i][$y] *= $this->A[$x][$y]; $this->A[$i][$y] *= $this->A[$x][$y];
} }
} }
@ -153,7 +153,7 @@ final class Simplex
} }
} }
$this->v += $this->c[$y] * $this->b[$x]; $this->v += $this->c[$y] * $this->b[$x];
$this->c[$y] *= $this->A[$x][$y]; $this->c[$y] *= $this->A[$x][$y];
$temp = $this->basic[$x]; $temp = $this->basic[$x];
@ -329,7 +329,7 @@ final class Simplex
for ($k = 0; $k < $this->n; ++$k) { for ($k = 0; $k < $this->n; ++$k) {
if ($j === $this->nonbasic[$k]) { if ($j === $this->nonbasic[$k]) {
$this->c[$k] += $oldC[$j]; $this->c[$k] += $oldC[$j];
$ok = true; $ok = true;
break; break;
} }
} }
@ -357,10 +357,10 @@ final class Simplex
* Solve simplex problem * Solve simplex problem
* *
* @param array<int, array<int|float>> $A Bounding equations * @param array<int, array<int|float>> $A Bounding equations
* @param int[]|float[] $b Boundings for equations * @param int[]|float[] $b Boundings for equations
* @param int[]|float[] $c Equation to maximize * @param int[]|float[] $c Equation to maximize
* *
* @return array{0:array<int|float>, 1:float} * @return array<void>|array{0:array<int|float>, 1:float}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -374,6 +374,10 @@ final class Simplex
// @todo create minimize // @todo create minimize
$this->m = \count($A); $this->m = \count($A);
if ($this->m < 1) {
return [];
}
$this->n = \count(\reset($A)); $this->n = \count(\reset($A));
if ($this->initialize() === -1) { if ($this->initialize() === -1) {

View File

@ -215,6 +215,47 @@ abstract class RequestAbstract implements MessageInterface
: new \DateTime((string) $this->data[$key]); : new \DateTime((string) $this->data[$key]);
} }
/**
* Get data.
*
* @param string $key Data key
*
* @return null|\DateTime
*
* @since 1.0.0
*/
public function getDataDateTimeFromTimestamp(string $key) : ?\DateTime
{
$key = \mb_strtolower($key);
if (empty($this->data[$key] ?? null)) {
return null;
}
$dt = new \DateTime();
$dt->setTimestamp((int) $this->data[$key]);
return $dt;
}
/**
* Get data.
*
* @param string $key Data key
*
* @return null|int
*
* @since 1.0.0
*/
public function getDataTimestampFromDateTime(string $key) : ?int
{
$key = \mb_strtolower($key);
return empty($this->data[$key] ?? null)
? null
: \strtotime((string) $this->data[$key]);
}
/** /**
* Get data. * Get data.
* *

View File

@ -40,7 +40,7 @@ final class ModuleInfo
/** /**
* Info data. * Info data.
* *
* @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>}|array * @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>}|array
* @since 1.0.0 * @since 1.0.0
*/ */
private array $info = []; private array $info = [];
@ -86,7 +86,7 @@ final class ModuleInfo
$contents = \file_get_contents($this->path); $contents = \file_get_contents($this->path);
/** @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>} $info */ /** @var array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>} $info */
$info = \json_decode($contents === false ? '[]' : $contents, true); $info = \json_decode($contents === false ? '[]' : $contents, true);
$this->info = $info === false ? [] : $info; $this->info = $info === false ? [] : $info;
} }
@ -134,7 +134,7 @@ final class ModuleInfo
/** /**
* Get info data. * Get info data.
* *
* @return array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, description:string, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>}|array * @return array{name:array{id:int, internal:string, external:string}, category:string, vision:string, requirements:array, creator:array{name:string, website:string}, directory:string, dependencies:array<string, string>, providing:array<string, string>, load:array<int, array{pid:string[], type:int, for:string, file:string, from:string}>}|array
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -61,7 +61,7 @@ class Address extends Location
*/ */
public function toArray() : array public function toArray() : array
{ {
return \array_merge ( return \array_merge(
[ [
'name' => $this->name, 'name' => $this->name,
'fao' => $this->fao, 'fao' => $this->fao,

View File

@ -115,7 +115,7 @@ class SmartDateTime extends \DateTime
$yearNew = (int) $this->format('Y') + $y + $yearChange; $yearNew = (int) $this->format('Y') + $y + $yearChange;
$monthNew = (int) $this->format('m') + $m; $monthNew = (int) $this->format('m') + $m;
$monthNew = $monthNew < 0 $monthNew = $monthNew <= 0
? 12 + ($monthNew - 1) % 12 + 1 ? 12 + ($monthNew - 1) % 12 + 1
: ($monthNew - 1) % 12 + 1; : ($monthNew - 1) % 12 + 1;
@ -445,4 +445,32 @@ class SmartDateTime extends \DateTime
return \abs(($mod < 0 ? 12 + $mod : $mod) % 12) + 1; return \abs(($mod < 0 ? 12 + $mod : $mod) % 12) + 1;
} }
public static function formatDuration(int $duration) : string
{
$days = \floor($duration / (24 * 3600));
$hours = \floor(($duration % (24 * 3600)) / 3600);
$minutes = \floor(($duration % 3600) / 60);
$seconds = $duration % 60;
$result = '';
if ($days > 0) {
$result .= \sprintf('%02dd', $days);
}
if ($hours > 0) {
$result .= \sprintf('%02dh', $hours);
}
if ($minutes > 0) {
$result .= \sprintf('%02dm', $minutes);
}
if ($seconds > 0) {
$result .= \sprintf('%02ds', $seconds);
}
return \rtrim($result, ' ');
}
} }

View File

@ -111,8 +111,8 @@ class Node
{ {
return [ return [
'key' => $this->key, 'key' => $this->key,
0 => $this->left?->toArray(), 0 => $this->left?->toArray(),
1 => $this->right?->toArray(), 1 => $this->right?->toArray(),
]; ];
} }
} }

View File

@ -734,9 +734,8 @@ class Directory extends FileAbstract implements DirectoryInterface
} }
$state = $this->copyNode($to, $overwrite); $state = $this->copyNode($to, $overwrite);
$state = $state && $this->deleteNode();
return $state; return $state && $this->deleteNode();
} }
/** /**

View File

@ -549,9 +549,8 @@ class File extends FileAbstract implements FileInterface
} }
$state = $this->copyNode($to, $overwrite); $state = $this->copyNode($to, $overwrite);
$state = $state && $this->deleteNode();
return $state; return $state && $this->deleteNode();
} }
/** /**

View File

@ -660,9 +660,8 @@ final class Directory extends FileAbstract implements DirectoryInterface
public function moveNode(string $to, bool $overwrite = false) : bool public function moveNode(string $to, bool $overwrite = false) : bool
{ {
$state = $this->copyNode($to, $overwrite); $state = $this->copyNode($to, $overwrite);
$state = $state && $this->deleteNode();
return $state; return $state && $this->deleteNode();
} }
/** /**

View File

@ -509,9 +509,8 @@ final class File extends FileAbstract implements FileInterface
public function moveNode(string $to, bool $overwrite = false) : bool public function moveNode(string $to, bool $overwrite = false) : bool
{ {
$state = $this->copyNode($to, $overwrite); $state = $this->copyNode($to, $overwrite);
$state = $state && $this->deleteNode();
return $state; return $state && $this->deleteNode();
} }
/** /**

View File

@ -213,7 +213,6 @@ final class SystemUtils
} }
$status = \proc_close($resource); $status = \proc_close($resource);
if ($status == -1) { if ($status == -1) {
throw new \Exception((string) $stderr); throw new \Exception((string) $stderr);
} }

View File

@ -383,9 +383,19 @@ final class HttpUri implements UriInterface
$this->query = \array_change_key_case($this->query, \CASE_LOWER); $this->query = \array_change_key_case($this->query, \CASE_LOWER);
} }
public function addQuery(string $key, mixed $value = null) /**
* Add query parameter
*
* @param string $key Parameter key
* @param mixed $value Value (null = omitted)
*
* @return void
*
* @since 1.0.0
*/
public function addQuery(string $key, mixed $value = null) : void
{ {
$key = \strtolower($key); $key = \strtolower($key);
$this->query[$key] = $value; $this->query[$key] = $value;
$toAdd = (empty($this->queryString) ? '?' : '&') $toAdd = (empty($this->queryString) ? '?' : '&')

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace phpOMS\Utils; namespace phpOMS\Utils;
use phpOMS\Math\Matrix\Exception\InvalidDimensionException;
/** /**
* Array utils. * Array utils.
* *

View File

@ -292,7 +292,7 @@ class Markdown
* @since 1.0.0 * @since 1.0.0
*/ */
private const CONTINUABLE = [ private const CONTINUABLE = [
'Code', 'Comment', 'FencedCode', 'List', 'Quote', 'Table', 'Math', 'Spoiler', 'Checkbox', 'Footnote', 'DefinitionList', 'Markup' 'Code', 'Comment', 'FencedCode', 'List', 'Quote', 'Table', 'Math', 'Spoiler', 'Checkbox', 'Footnote', 'DefinitionList', 'Markup',
]; ];
/** /**
@ -302,7 +302,7 @@ class Markdown
* @since 1.0.0 * @since 1.0.0
*/ */
private const COMPLETABLE = [ private const COMPLETABLE = [
'Math', 'Spoiler', 'Table', 'Checkbox', 'Footnote', 'Markup', 'Code', 'FencedCode', 'List' 'Math', 'Spoiler', 'Table', 'Checkbox', 'Footnote', 'Markup', 'Code', 'FencedCode', 'List',
]; ];
/** /**
@ -598,7 +598,7 @@ class Markdown
// Add footnotes // Add footnotes
if (isset($this->definitionData['Footnote'])) { if (isset($this->definitionData['Footnote'])) {
$element = $this->buildFootnoteElement(); $element = $this->buildFootnoteElement();
$html .= "\n" . $this->element($element); $html .= "\n" . $this->element($element);
} }
return $this->decodeToCTagFromHash($html); // Unescape the ToC tag return $this->decodeToCTagFromHash($html); // Unescape the ToC tag
@ -935,7 +935,7 @@ class Markdown
protected function inlineUrl(array $excerpt) : ?array protected function inlineUrl(array $excerpt) : ?array
{ {
if (!($this->options['links'] ?? true) if (!($this->options['links'] ?? true)
|| $this->urlsLinked !== true || !\str_starts_with($excerpt['text'], '://') || !$this->urlsLinked || !\str_starts_with($excerpt['text'], '://')
|| \strpos($excerpt['context'], 'http') === false || \strpos($excerpt['context'], 'http') === false
|| \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $excerpt['context'], $matches, \PREG_OFFSET_CAPTURE) !== 1 || \preg_match('/\bhttps?+:[\/]{2}[^\s<]+\b\/*+/ui', $excerpt['context'], $matches, \PREG_OFFSET_CAPTURE) !== 1
) { ) {
@ -1276,27 +1276,27 @@ class Markdown
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'span', 'name' => 'span',
'attributes' => [ 'attributes' => [
'class' => 'spoiler' 'class' => 'spoiler',
], ],
'elements' => [ 'elements' => [
[ [
'name' => 'input', 'name' => 'input',
'attributes' => [ 'attributes' => [
'type' => 'checkbox' 'type' => 'checkbox',
] ],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $matches[1], 'text' => $matches[1],
] ],
] ],
], ],
]; ];
} }
/** /**
* Handle keystrokes * Handle keystrokes
* *
* @param array{text:string, context:string, before:string} $excerpt Inline data * @param array{text:string, context:string, before:string} $excerpt Inline data
@ -1307,7 +1307,7 @@ class Markdown
*/ */
protected function inlineKeystrokes(array $excerpt) : ?array protected function inlineKeystrokes(array $excerpt) : ?array
{ {
if (!str_starts_with($excerpt['text'], '[[') if (!\str_starts_with($excerpt['text'], '[[')
|| \preg_match('/^(?<!\[)(?:\[\[([^\[\]]*|[\[\]])\]\])(?!\])/s', $excerpt['text'], $matches) !== 1 || \preg_match('/^(?<!\[)(?:\[\[([^\[\]]*|[\[\]])\]\])(?!\])/s', $excerpt['text'], $matches) !== 1
) { ) {
return null; return null;
@ -1354,61 +1354,61 @@ class Markdown
switch ($type) { switch ($type) {
case 'youtube': case 'youtube':
$element = 'iframe'; $element = 'iframe';
$attributes = [ $attributes = [
'src' => \preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url), 'src' => \preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url),
'frameborder' => '0', 'frameborder' => '0',
'allow' => 'autoplay', 'allow' => 'autoplay',
'allowfullscreen' => '', 'allowfullscreen' => '',
'sandbox' => 'allow-same-origin allow-scripts allow-forms' 'sandbox' => 'allow-same-origin allow-scripts allow-forms',
]; ];
break; break;
case 'vimeo': case 'vimeo':
$element = 'iframe'; $element = 'iframe';
$attributes = [ $attributes = [
'src' => \preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url), 'src' => \preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url),
'frameborder' => '0', 'frameborder' => '0',
'allow' => 'autoplay', 'allow' => 'autoplay',
'allowfullscreen' => '', 'allowfullscreen' => '',
'sandbox' => 'allow-same-origin allow-scripts allow-forms' 'sandbox' => 'allow-same-origin allow-scripts allow-forms',
]; ];
break; break;
case 'dailymotion': case 'dailymotion':
$element = 'iframe'; $element = 'iframe';
$attributes = [ $attributes = [
'src' => $url, 'src' => $url,
'frameborder' => '0', 'frameborder' => '0',
'allow' => 'autoplay', 'allow' => 'autoplay',
'allowfullscreen' => '', 'allowfullscreen' => '',
'sandbox' => 'allow-same-origin allow-scripts allow-forms' 'sandbox' => 'allow-same-origin allow-scripts allow-forms',
]; ];
break; break;
default: default:
$element = 'video'; $element = 'video';
$attributes = [ $attributes = [
'src' => UriFactory::build($url), 'src' => UriFactory::build($url),
'controls' => '' 'controls' => '',
]; ];
} }
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => $element, 'name' => $element,
'text' => $matches[1], 'text' => $matches[1],
'attributes' => $attributes 'attributes' => $attributes,
], ],
]; ];
} elseif ($audio) { } elseif ($audio) {
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'audio', 'name' => 'audio',
'text' => $matches[1], 'text' => $matches[1],
'attributes' => [ 'attributes' => [
'src' => UriFactory::build($url), 'src' => UriFactory::build($url),
'controls' => '' 'controls' => '',
] ],
], ],
]; ];
} }
@ -1448,16 +1448,16 @@ class Markdown
} }
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'div', 'name' => 'div',
'text' => '', 'text' => '',
'attributes' => [ 'attributes' => [
'id' => 'i' . \bin2hex(\random_bytes(4)), 'id' => 'i' . \bin2hex(\random_bytes(4)),
'class' => 'map', 'class' => 'map',
'data-lat' => $lat, 'data-lat' => $lat,
'data-lon' => $lon, 'data-lon' => $lon,
] ],
], ],
]; ];
} }
@ -1487,7 +1487,7 @@ class Markdown
$address = $matches[5]; $address = $matches[5];
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'div', 'name' => 'div',
//'text' => '', //'text' => '',
@ -1496,28 +1496,28 @@ class Markdown
], ],
'elements' => [ 'elements' => [
[ [
'name' => 'span', 'name' => 'span',
'text' => $name, 'text' => $name,
'attributes' => ['class' => 'addressWidget-name'], 'attributes' => ['class' => 'addressWidget-name'],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $address, 'text' => $address,
'attributes' => ['class' => 'addressWidget-address'], 'attributes' => ['class' => 'addressWidget-address'],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $zip, 'text' => $zip,
'attributes' => ['class' => 'addressWidget-zip'], 'attributes' => ['class' => 'addressWidget-zip'],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $city, 'text' => $city,
'attributes' => ['class' => 'addressWidget-city'], 'attributes' => ['class' => 'addressWidget-city'],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $country, 'text' => $country,
'attributes' => ['class' => 'addressWidget-country'], 'attributes' => ['class' => 'addressWidget-country'],
], ],
], ],
@ -1578,11 +1578,10 @@ class Markdown
case 'linkedin': case 'linkedin':
$src = 'Resources/icons/company/linkedin.svg'; $src = 'Resources/icons/company/linkedin.svg';
break; break;
} }
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'a', 'name' => 'a',
//'text' => '', //'text' => '',
@ -1592,17 +1591,17 @@ class Markdown
], ],
'elements' => [ 'elements' => [
[ [
'name' => 'img', 'name' => 'img',
'attributes' => [ 'attributes' => [
'class' => 'contactWidget-icon', 'class' => 'contactWidget-icon',
'src' => $src 'src' => $src,
], ],
], ],
[ [
'name' => 'span', 'name' => 'span',
'text' => $matches[2], 'text' => $matches[2],
'attributes' => ['class' => 'contactWidget-contact'], 'attributes' => ['class' => 'contactWidget-contact'],
] ],
], ],
], ],
@ -1638,14 +1637,14 @@ class Markdown
} }
return [ return [
'extent' => \strlen($matches[0]), 'extent' => \strlen($matches[0]),
'element' => [ 'element' => [
'name' => 'progress', 'name' => 'progress',
'text' => '', 'text' => '',
'attributes' => [ 'attributes' => [
'value' => $value, 'value' => $value,
'max' => '100', 'max' => '100',
] ],
], ],
]; ];
} }
@ -1789,7 +1788,7 @@ class Markdown
|| ($state && !\preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.{2,}?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $excerpt['text'])) || ($state && !\preg_match('/^(?<!\\\\)(?<!\\\\\()\\\\\((.{2,}?)(?<!\\\\\()\\\\\)(?!\\\\\))/s', $excerpt['text']))
) { ) {
return [ return [
'extent' => 2, 'extent' => 2,
'element' => [ 'element' => [
'rawHtml' => $excerpt['text'][1], 'rawHtml' => $excerpt['text'][1],
], ],
@ -1968,7 +1967,7 @@ class Markdown
], ],
]; ];
if (preg_match('/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', $block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE)) { if (\preg_match('/[ #]*{(' . $this->regexAttribute . '+)}[ ]*$/', $block['element']['handler']['argument'], $matches, \PREG_OFFSET_CAPTURE)) {
$attributeString = $matches[1][0]; $attributeString = $matches[1][0];
$block['element']['attributes'] = $this->parseAttributeData($attributeString); $block['element']['attributes'] = $this->parseAttributeData($attributeString);
@ -2038,8 +2037,7 @@ class Markdown
$matches[1] = \substr($matches[1], 0, -$contentIndent); $matches[1] = \substr($matches[1], 0, -$contentIndent);
$matches[3] = \str_repeat(' ', $contentIndent) . $matches[3]; $matches[3] = \str_repeat(' ', $contentIndent) . $matches[3];
} } elseif ($contentIndent === 0) {
elseif ($contentIndent === 0) {
$matches[1] .= ' '; $matches[1] .= ' ';
} }
@ -2108,7 +2106,6 @@ class Markdown
return null; return null;
} }
return [ return [
'element' => [ 'element' => [
'name' => 'blockquote', 'name' => 'blockquote',
@ -2690,7 +2687,7 @@ class Markdown
'element' => [ 'element' => [
'name' => 'details', 'name' => 'details',
'element' => [ 'element' => [
'text' => '', 'text' => '',
'elements' => [ 'elements' => [
[ [
'name' => 'summary', 'name' => 'summary',
@ -2699,9 +2696,9 @@ class Markdown
[ [
'name' => 'span', // @todo check if without span possible 'name' => 'span', // @todo check if without span possible
'text' => '', 'text' => '',
] ],
], ],
] ],
], ],
]; ];
} }
@ -3153,8 +3150,12 @@ class Markdown
// - [Header3](#Header3) // - [Header3](#Header3)
// - [Header2-2](#Header2-2) // - [Header2-2](#Header2-2)
// ... // ...
$this->contentsListString .= \str_repeat(' ', $this->firstHeadLevel - 1 > $level ? 1 : $level - ($this->firstHeadLevel - 1)) $this->contentsListString .= \str_repeat(
. ' - ' . '[' . $text . '](#' . $id . ')' . \PHP_EOL; ' ',
$this->firstHeadLevel - 1 > $level
? 1
: $level - ($this->firstHeadLevel - 1)
) . ' - [' . $text . '](#' . $id . ")\n";
} }
/** /**
@ -3179,15 +3180,17 @@ class Markdown
$newStr = $str; $newStr = $str;
if ($count = $this->anchorDuplicates[$str]) { if (($count = $this->anchorDuplicates[$str]) === 0) {
$newStr .= '-' . $count; return $newStr;
}
// increment until conversion doesn't produce new duplicates anymore $newStr .= '-' . $count;
if (isset($this->anchorDuplicates[$newStr])) {
$newStr = $this->incrementAnchorId($str); // increment until conversion doesn't produce new duplicates anymore
} else { if (isset($this->anchorDuplicates[$newStr])) {
$this->anchorDuplicates[$newStr] = 0; $newStr = $this->incrementAnchorId($str);
} } else {
$this->anchorDuplicates[$newStr] = 0;
} }
return $newStr; return $newStr;
@ -3491,7 +3494,7 @@ class Markdown
'attributes' => ['href' => '#fn:' . $name, 'class' => 'footnote-ref'], 'attributes' => ['href' => '#fn:' . $name, 'class' => 'footnote-ref'],
'text' => $this->definitionData['Footnote'][$name]['number'], 'text' => $this->definitionData['Footnote'][$name]['number'],
], ],
] ],
]; ];
} }
@ -3559,8 +3562,7 @@ class Markdown
return $inline; return $inline;
} }
foreach ($this->definitionData['Abbreviation'] as $abbreviation => $meaning) foreach ($this->definitionData['Abbreviation'] as $abbreviation => $meaning) {
{
$this->currentAbreviation = $abbreviation; $this->currentAbreviation = $abbreviation;
$this->currentMeaning = $meaning; $this->currentMeaning = $meaning;
@ -4725,7 +4727,7 @@ class Markdown
/** /**
* Sanitize url in attribute * Sanitize url in attribute
* *
* @param array $element Element to sanitize * @param array $element Element to sanitize
* @param string $attribute Attribute to sanitize * @param string $attribute Attribute to sanitize
* *
* @return array * @return array

View File

@ -288,9 +288,7 @@ final class StringUtils
} }
} }
$result = \rtrim($result, $delim); return \rtrim($result, $delim);
return $result;
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* PHP Version 8.1 * PHP Version 8.1
* *
* @package Karaka * @package Jingga
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 2.0 * @license OMS License 2.0
* @version 1.0.0 * @version 1.0.0

View File

@ -29,20 +29,20 @@ final class AprioriTest extends \PHPUnit\Framework\TestCase
{ {
self::assertEquals( self::assertEquals(
[ [
'theta' => 2, 'theta' => 2,
'epsilon' => 2, 'epsilon' => 2,
'epsilon:theta' => 0, 'epsilon:theta' => 0,
'beta' => 4, 'beta' => 4,
'beta:theta' => 2, 'beta:theta' => 2,
'beta:epsilon' => 2, 'beta:epsilon' => 2,
'beta:epsilon:theta' => 0, 'beta:epsilon:theta' => 0,
'alpha' => 4, 'alpha' => 4,
'alpha:theta' => 2, 'alpha:theta' => 2,
'alpha:epsilon' => 2, 'alpha:epsilon' => 2,
'alpha:epsilon:theta' => 0, 'alpha:epsilon:theta' => 0,
'alpha:beta' => 4, 'alpha:beta' => 4,
'alpha:beta:theta' => 2, 'alpha:beta:theta' => 2,
'alpha:beta:epsilon' => 2, 'alpha:beta:epsilon' => 2,
'alpha:beta:epsilon:theta' => 0, 'alpha:beta:epsilon:theta' => 0,
], ],
Apriori::apriori([ Apriori::apriori([
@ -55,20 +55,20 @@ final class AprioriTest extends \PHPUnit\Framework\TestCase
self::assertEquals( self::assertEquals(
[ [
'4' => 5, '4' => 5,
'3' => 3, '3' => 3,
'3:4' => 3, '3:4' => 3,
'2' => 5, '2' => 5,
'2:4' => 4, '2:4' => 4,
'2:3' => 2, '2:3' => 2,
'2:3:4' => 2, '2:3:4' => 2,
'1' => 3, '1' => 3,
'1:4' => 2, '1:4' => 2,
'1:3' => 1, '1:3' => 1,
'1:3:4' => 1, '1:3:4' => 1,
'1:2' => 3, '1:2' => 3,
'1:2:4' => 2, '1:2:4' => 2,
'1:2:3' => 1, '1:2:3' => 1,
'1:2:3:4' => 1, '1:2:3:4' => 1,
], ],
Apriori::apriori([ Apriori::apriori([

View File

@ -31,8 +31,7 @@ final class DependencyResolverTest extends \PHPUnit\Framework\TestCase
*/ */
public function testResolveCircular() : void public function testResolveCircular() : void
{ {
self::assertEquals( self::assertNull(
null,
DependencyResolver::resolve([0 => [1, 2], 1 => [0, 2], 2 => []]) DependencyResolver::resolve([0 => [1, 2], 1 => [0, 2], 2 => []])
); );
} }

View File

@ -14,7 +14,6 @@
"name": "Jingga", "name": "Jingga",
"website": "jingga.app" "website": "jingga.app"
}, },
"description": "The administration module.",
"directory": "Admin", "directory": "Admin",
"providing": { "providing": {
"Navigation": "*", "Navigation": "*",

View File

@ -14,7 +14,6 @@
"name": "Jingga", "name": "Jingga",
"website": "jingga.app" "website": "jingga.app"
}, },
"description": "The administration module.",
"directory": "Admin", "directory": "Admin",
"providing": { "providing": {
"Navigation": "*" "Navigation": "*"

View File

@ -14,8 +14,6 @@ declare(strict_types=1);
namespace phpOMS\tests\Business\Recommendation; namespace phpOMS\tests\Business\Recommendation;
use phpOMS\Business\Recommendation\BayesianPersonalizedRanking;
/** /**
* @testdox phpOMS\tests\Business\Recommendation\BayesianPersonalizedRankingTest: Article affinity/correlation * @testdox phpOMS\tests\Business\Recommendation\BayesianPersonalizedRankingTest: Article affinity/correlation
* *

View File

@ -25,23 +25,23 @@ class BaseModelMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const COLUMNS = [ public const COLUMNS = [
'test_base_id' => ['name' => 'test_base_id', 'type' => 'int', 'internal' => 'id'], 'test_base_id' => ['name' => 'test_base_id', 'type' => 'int', 'internal' => 'id'],
'test_base_string' => ['name' => 'test_base_string', 'type' => 'string', 'internal' => 'string', 'autocomplete' => true], 'test_base_string' => ['name' => 'test_base_string', 'type' => 'string', 'internal' => 'string', 'autocomplete' => true],
'test_base_compress' => ['name' => 'test_base_compress', 'type' => 'compress', 'internal' => 'compress',], 'test_base_compress' => ['name' => 'test_base_compress', 'type' => 'compress', 'internal' => 'compress',],
'test_base_pstring' => ['name' => 'test_base_pstring', 'type' => 'pstring', 'internal' => 'pstring', 'private' => true], 'test_base_pstring' => ['name' => 'test_base_pstring', 'type' => 'pstring', 'internal' => 'pstring', 'private' => true],
'test_base_int' => ['name' => 'test_base_int', 'type' => 'int', 'internal' => 'int'], 'test_base_int' => ['name' => 'test_base_int', 'type' => 'int', 'internal' => 'int'],
'test_base_bool' => ['name' => 'test_base_bool', 'type' => 'bool', 'internal' => 'bool'], 'test_base_bool' => ['name' => 'test_base_bool', 'type' => 'bool', 'internal' => 'bool'],
'test_base_null' => ['name' => 'test_base_null', 'type' => 'int', 'internal' => 'null'], 'test_base_null' => ['name' => 'test_base_null', 'type' => 'int', 'internal' => 'null'],
'test_base_float' => ['name' => 'test_base_float', 'type' => 'float', 'internal' => 'float'], 'test_base_float' => ['name' => 'test_base_float', 'type' => 'float', 'internal' => 'float'],
'test_base_json' => ['name' => 'test_base_json', 'type' => 'Json', 'internal' => 'json'], 'test_base_json' => ['name' => 'test_base_json', 'type' => 'Json', 'internal' => 'json'],
'test_base_json_serializable' => ['name' => 'test_base_json_serializable', 'type' => 'Json', 'internal' => 'jsonSerializable'], 'test_base_json_serializable' => ['name' => 'test_base_json_serializable', 'type' => 'Json', 'internal' => 'jsonSerializable'],
'test_base_serializable' => ['name' => 'test_base_serializable', 'type' => 'Serializable', 'internal' => 'serializable'], 'test_base_serializable' => ['name' => 'test_base_serializable', 'type' => 'Serializable', 'internal' => 'serializable'],
'test_base_datetime' => ['name' => 'test_base_datetime', 'type' => 'DateTime', 'internal' => 'datetime'], 'test_base_datetime' => ['name' => 'test_base_datetime', 'type' => 'DateTime', 'internal' => 'datetime'],
'test_base_datetime_null' => ['name' => 'test_base_datetime_null', 'type' => 'DateTime', 'internal' => 'datetime_null'], 'test_base_datetime_null' => ['name' => 'test_base_datetime_null', 'type' => 'DateTime', 'internal' => 'datetime_null'],
'test_base_owns_one_self' => ['name' => 'test_base_owns_one_self', 'type' => 'int', 'internal' => 'ownsOneSelf'], 'test_base_owns_one_self' => ['name' => 'test_base_owns_one_self', 'type' => 'int', 'internal' => 'ownsOneSelf'],
'test_base_belongs_to_one' => ['name' => 'test_base_belongs_to_one', 'type' => 'int', 'internal' => 'belongsToOne'], 'test_base_belongs_to_one' => ['name' => 'test_base_belongs_to_one', 'type' => 'int', 'internal' => 'belongsToOne'],
'test_base_owns_onep_self' => ['name' => 'test_base_owns_onep_self', 'type' => 'int', 'internal' => 'ownsOneSelfPrivate', 'private' => true], 'test_base_owns_onep_self' => ['name' => 'test_base_owns_onep_self', 'type' => 'int', 'internal' => 'ownsOneSelfPrivate', 'private' => true],
'test_base_belongs_top_one' => ['name' => 'test_base_belongs_top_one', 'type' => 'int', 'internal' => 'belongsToOnePrivate', 'private' => true], 'test_base_belongs_top_one' => ['name' => 'test_base_belongs_top_one', 'type' => 'int', 'internal' => 'belongsToOnePrivate', 'private' => true],
]; ];
/** /**
@ -112,7 +112,7 @@ class BaseModelMapper extends DataMapperFactory
'table' => 'test_has_many_rel_relationsp', 'table' => 'test_has_many_rel_relationsp',
'external' => 'test_has_many_rel_relationsp_src', 'external' => 'test_has_many_rel_relationsp_src',
'self' => 'test_has_many_rel_relationsp_dest', 'self' => 'test_has_many_rel_relationsp_dest',
'private' => true 'private' => true,
], ],
]; ];

View File

@ -32,7 +32,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
[ [
[11.333333, 3.333333, 0.0, 11.666667, 0.0], [11.333333, 3.333333, 0.0, 11.666667, 0.0],
21.333333 21.333333,
], ],
$simplex->solve( $simplex->solve(
[ [
@ -53,7 +53,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
[ [
[1.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0, 0.0],
5.0 5.0,
], ],
$simplex->solve( $simplex->solve(
[ [
@ -73,7 +73,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase
self::assertEquals( self::assertEquals(
[ [
[-2, -2, -2, -2, -2], [-2, -2, -2, -2, -2],
\INF \INF,
], ],
$simplex->solve( $simplex->solve(
[ [
@ -92,7 +92,7 @@ final class SimplexTest extends \PHPUnit\Framework\TestCase
self::assertEqualsWithDelta( self::assertEqualsWithDelta(
[ [
[-1, -1, -1, -1], [-1, -1, -1, -1],
\INF \INF,
], ],
$simplex->solve( $simplex->solve(
[ [

View File

@ -128,8 +128,8 @@ final class RequestAbstractTest extends \PHPUnit\Framework\TestCase
public function testDataBoolInputOutput() : void public function testDataBoolInputOutput() : void
{ {
$this->request->setData('asdf', 1); $this->request->setData('asdf', 1);
self::assertEquals(true, $this->request->getDataBool('asdf')); self::assertTrue($this->request->getDataBool('asdf'));
self::assertEquals(true, $this->request->getData('asdf', 'bool')); self::assertTrue($this->request->getData('asdf', 'bool'));
} }
/** /**
@ -163,10 +163,10 @@ final class RequestAbstractTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInvalidDataTypeInputOutput() : void public function testInvalidDataTypeInputOutput() : void
{ {
self::assertEquals(null, $this->request->getDataString('a')); self::assertNull($this->request->getDataString('a'));
self::assertEquals(null, $this->request->getDataBool('a')); self::assertNull($this->request->getDataBool('a'));
self::assertEquals(null, $this->request->getDataInt('a')); self::assertNull($this->request->getDataInt('a'));
self::assertEquals(null, $this->request->getDataFloat('a')); self::assertNull($this->request->getDataFloat('a'));
self::assertEquals(null, $this->request->getDataDateTime('a')); self::assertNull($this->request->getDataDateTime('a'));
} }
} }

View File

@ -104,8 +104,8 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase
public function testDataBoolInputOutput() : void public function testDataBoolInputOutput() : void
{ {
$this->response->set('asdf', 1); $this->response->set('asdf', 1);
self::assertEquals(true, $this->response->getDataBool('asdf')); self::assertTrue($this->response->getDataBool('asdf'));
self::assertEquals(true, $this->response->getData('asdf', 'bool')); self::assertTrue($this->response->getData('asdf', 'bool'));
} }
/** /**
@ -154,10 +154,10 @@ final class ResponseAbstractTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInvalidDataTypeInputOutput() : void public function testInvalidDataTypeInputOutput() : void
{ {
self::assertEquals(null, $this->response->getDataString('a')); self::assertNull($this->response->getDataString('a'));
self::assertEquals(null, $this->response->getDataBool('a')); self::assertNull($this->response->getDataBool('a'));
self::assertEquals(null, $this->response->getDataInt('a')); self::assertNull($this->response->getDataInt('a'));
self::assertEquals(null, $this->response->getDataFloat('a')); self::assertNull($this->response->getDataFloat('a'));
self::assertEquals(null, $this->response->getDataDateTime('a')); self::assertNull($this->response->getDataDateTime('a'));
} }
} }

View File

@ -14,7 +14,6 @@
"name": "Jingga", "name": "Jingga",
"website": "jingga.app" "website": "jingga.app"
}, },
"description": "The administration module.",
"directory": "Admin", "directory": "Admin",
"dependencies": [], "dependencies": [],
"providing": { "providing": {

View File

@ -41,31 +41,31 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase
self::assertEquals( self::assertEquals(
[ [
'key' => 'D', 'key' => 'D',
0 => [ 0 => [
'key' => 'A', 'key' => 'A',
0 => null, 0 => null,
1 => null 1 => null,
], ],
1 => [ 1 => [
'key' => 'I', 'key' => 'I',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'N', 'key' => 'N',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'O', 'key' => 'O',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'S', 'key' => 'S',
0 => [ 0 => [
'key' => 'R', 'key' => 'R',
0 => null, 0 => null,
1 => null 1 => null,
], ],
1 => [ 1 => [
'key' => 'U', 'key' => 'U',
0 => null, 0 => null,
1 => null 1 => null,
], ],
], ],
], ],
@ -112,32 +112,32 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase
self::assertEquals( self::assertEquals(
[ [
'key' => 'D', 'key' => 'D',
0 => [ 0 => [
'key' => 'A', 'key' => 'A',
0 => null, 0 => null,
1 => null 1 => null,
], ],
1 => [ 1 => [
'key' => 'N', 'key' => 'N',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'O', 'key' => 'O',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'U', 'key' => 'U',
0 => [ 0 => [
'key' => 'R', 'key' => 'R',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'T', 'key' => 'T',
0 => null, 0 => null,
1 => null 1 => null,
] ],
], ],
1 => [ 1 => [
'key' => 'Z', 'key' => 'Z',
0 => null, 0 => null,
1 => null 1 => null,
], ],
], ],
], ],

View File

@ -26,7 +26,7 @@ final class DocumentWriterTest extends \PHPUnit\Framework\TestCase
{ {
public function testParsing() : void public function testParsing() : void
{ {
$doc = IOFactory::load(__DIR__ . '/data/Word.docx'); $doc = IOFactory::load(__DIR__ . '/data/Word.docx');
$writer = new DocumentWriter($doc); $writer = new DocumentWriter($doc);
$pdf = $writer->toPdfString(__DIR__ . '/data/WordMpdf.pdf'); $pdf = $writer->toPdfString(__DIR__ . '/data/WordMpdf.pdf');

View File

@ -47,7 +47,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testSafeMode() : void public function testSafeMode() : void
{ {
$parser = new Markdown(); $parser = new Markdown();
$parser->safeMode = true; $parser->safeMode = true;
self::assertEquals( self::assertEquals(
@ -60,8 +60,8 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
{ {
$parser = new Markdown([ $parser = new Markdown([
'tables' => [ 'tables' => [
'tablespan' => true 'tablespan' => true,
] ],
]); ]);
self::assertEquals( self::assertEquals(
@ -73,7 +73,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testMap() : void public function testMap() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'map' => true 'map' => true,
]); ]);
self::assertLessThan(9, self::assertLessThan(9,
@ -87,7 +87,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testContact() : void public function testContact() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'contact' => true 'contact' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -99,7 +99,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testTypographer() : void public function testTypographer() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'typographer' => true 'typographer' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -111,7 +111,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testAddress() : void public function testAddress() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'address' => true 'address' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -123,7 +123,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testProgress() : void public function testProgress() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'progress' => true 'progress' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -135,7 +135,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testEmbed() : void public function testEmbed() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'embeding' => true 'embeding' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -147,7 +147,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testMath() : void public function testMath() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'math' => true 'math' => true,
]); ]);
self::assertEquals( self::assertEquals(
@ -159,7 +159,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testTOC() : void public function testTOC() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'toc' => true 'toc' => true,
]); ]);
$parser->text(\file_get_contents(__DIR__ . '/manualdata/toc.md')); $parser->text(\file_get_contents(__DIR__ . '/manualdata/toc.md'));
@ -172,7 +172,7 @@ final class MarkdownTest extends \PHPUnit\Framework\TestCase
public function testSpoiler() : void public function testSpoiler() : void
{ {
$parser = new Markdown([ $parser = new Markdown([
'spoiler' => true 'spoiler' => true,
]); ]);
self::assertEquals( self::assertEquals(

View File

@ -16,8 +16,8 @@ namespace phpOMS\tests\Utils\Parser\Presentation;
include_once __DIR__ . '/../../../Autoloader.php'; include_once __DIR__ . '/../../../Autoloader.php';
use phpOMS\Utils\Parser\Presentation\PresentationWriter;
use PhpOffice\PhpPresentation\IOFactory; use PhpOffice\PhpPresentation\IOFactory;
use phpOMS\Utils\Parser\Presentation\PresentationWriter;
/** /**
* @internal * @internal
@ -31,7 +31,7 @@ final class PresentationWriterTest extends \PHPUnit\Framework\TestCase
$writer = new PresentationWriter($presentation); $writer = new PresentationWriter($presentation);
self::assertTrue( self::assertTrue(
abs(\strlen(\file_get_contents(__DIR__ . '/data/Powerpoint.html')) \abs(\strlen(\file_get_contents(__DIR__ . '/data/Powerpoint.html'))
- \strlen($writer->renderHtml())) < 100 - \strlen($writer->renderHtml())) < 100
); );
} }

View File

@ -26,7 +26,7 @@ final class SpreadsheetWriterTest extends \PHPUnit\Framework\TestCase
{ {
public function testParsing() : void public function testParsing() : void
{ {
$sheet = IOFactory::load(__DIR__ . '/data/Excel.xlsx'); $sheet = IOFactory::load(__DIR__ . '/data/Excel.xlsx');
$writer = new SpreadsheetWriter($sheet); $writer = new SpreadsheetWriter($sheet);
$pdf = $writer->toPdfString(__DIR__ . '/data/ExcelMpdf.pdf'); $pdf = $writer->toPdfString(__DIR__ . '/data/ExcelMpdf.pdf');