Submit
Path:
~
/
/
proc
/
self
/
root
/
opt
/
psa
/
admin
/
plib
/
modules
/
rest-api
/
vendor
/
jms
/
serializer
/
src
/
Ordering
/
File Content:
CustomPropertyOrderingStrategy.php
<?php declare (strict_types=1); namespace PleskRestApi\JMS\Serializer\Ordering; final class CustomPropertyOrderingStrategy implements PropertyOrderingInterface { /** @var int[] property => weight */ private $ordering; /** * @param int[] $ordering property => weight */ public function __construct(array $ordering) { $this->ordering = $ordering; } /** * {@inheritdoc} */ public function order(array $properties) : array { $currentSorting = $properties ? \array_combine(\array_keys($properties), \range(1, \count($properties))) : []; \uksort($properties, function ($a, $b) use($currentSorting) { $existsA = isset($this->ordering[$a]); $existsB = isset($this->ordering[$b]); if (!$existsA && !$existsB) { return $currentSorting[$a] - $currentSorting[$b]; } if (!$existsA) { return 1; } if (!$existsB) { return -1; } return $this->ordering[$a] < $this->ordering[$b] ? -1 : 1; }); return $properties; } }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
AlphabeticalPropertyOrderingStrategy.php
480 bytes
0644
CustomPropertyOrderingStrategy.php
1158 bytes
0644
IdenticalPropertyOrderingStrategy.php
299 bytes
0644
PropertyOrderingInterface.php
371 bytes
0644
N4ST4R_ID | Naxtarrr