mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 13:28:39 +00:00
Extend functionality based on module needs
This commit is contained in:
parent
84d64ed53f
commit
4e66128ea4
|
|
@ -138,6 +138,18 @@ final class InfoManager
|
||||||
return $this->info;
|
return $this->info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get info data.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getId() : int
|
||||||
|
{
|
||||||
|
return $this->info['name']['id'] ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get info data.
|
* Get info data.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -151,20 +151,21 @@ final class ArrayUtils
|
||||||
*
|
*
|
||||||
* @param mixed $needle Needle for search
|
* @param mixed $needle Needle for search
|
||||||
* @param array $haystack Haystack for search
|
* @param array $haystack Haystack for search
|
||||||
|
* @param mixed $key Key that has to match (optional)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function inArrayRecursive($needle, array $haystack) : bool
|
public static function inArrayRecursive($needle, array $haystack, $key = null) : bool
|
||||||
{
|
{
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
foreach ($haystack as $item) {
|
foreach ($haystack as $k => $item) {
|
||||||
if ($item === $needle) {
|
if ($item === $needle && ($key === null || $key === $k)) {
|
||||||
return true;
|
return true;
|
||||||
} elseif (\is_array($item)) {
|
} elseif (\is_array($item)) {
|
||||||
$found = self::inArrayRecursive($needle, $item);
|
$found = self::inArrayRecursive($needle, $item, $key);
|
||||||
|
|
||||||
if ($found) {
|
if ($found) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
$jarray = \json_decode(file_get_contents(__DIR__ . '/info-test.json'), true);
|
$jarray = \json_decode(file_get_contents(__DIR__ . '/info-test.json'), true);
|
||||||
|
|
||||||
self::assertEquals($jarray, $info->get());
|
self::assertEquals($jarray, $info->get());
|
||||||
|
self::assertEquals($jarray['name']['id'], $info->getId());
|
||||||
self::assertEquals($jarray['name']['internal'], $info->getInternalName());
|
self::assertEquals($jarray['name']['internal'], $info->getInternalName());
|
||||||
self::assertEquals($jarray['name']['external'], $info->getExternalName());
|
self::assertEquals($jarray['name']['external'], $info->getExternalName());
|
||||||
self::assertEquals($jarray['category'], $info->getCategory());
|
self::assertEquals($jarray['category'], $info->getCategory());
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ class ArrayUtilsTest extends \PHPUnit\Framework\TestCase
|
||||||
];
|
];
|
||||||
|
|
||||||
self::assertTrue(ArrayUtils::inArrayRecursive('aba', $expected));
|
self::assertTrue(ArrayUtils::inArrayRecursive('aba', $expected));
|
||||||
|
self::assertTrue(ArrayUtils::inArrayRecursive('2a', $expected));
|
||||||
|
self::assertTrue(ArrayUtils::inArrayRecursive('2a', $expected, 2));
|
||||||
|
self::assertFalse(ArrayUtils::inArrayRecursive('2a', $expected, 3));
|
||||||
self::assertFalse(ArrayUtils::inArrayRecursive('aba', ArrayUtils::unsetArray('a/ab', $expected, '/')));
|
self::assertFalse(ArrayUtils::inArrayRecursive('aba', ArrayUtils::unsetArray('a/ab', $expected, '/')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user