Skip to content

Commit 2079061

Browse files
committed
Initial commit
1 parent 429857b commit 2079061

File tree

16 files changed

+1459
-0
lines changed

16 files changed

+1459
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.idea/
2+
.code/
3+
vendor/
4+
5+
.env
6+
.DS_Store
7+
8+
composer.lock
9+
index.php

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "ninetynine/url",
3+
"description": "A package which offers a helper to build URLs",
4+
"minimum-stability": "dev",
5+
"type": "library",
6+
"license": "LGPL-3.0",
7+
"keywords": [
8+
"helpers",
9+
"php"
10+
],
11+
"homepage": "https://github.com/ninetynine/url",
12+
"support": {
13+
"issues": "https://github.com/ninetynine/url/issues",
14+
"source": "https://github.com/ninetynine/url"
15+
},
16+
"authors": [
17+
{
18+
"name": "Dexter Marks-Barber",
19+
"email": "[email protected]",
20+
"role": "Maintainer"
21+
}
22+
],
23+
"require": {
24+
"php": "^7.0.0"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"NinetyNine\\Url\\": "src/NinetyNine/Url"
29+
}
30+
},
31+
"extra": {
32+
"branch-alias": {
33+
"dev-master": "0.x-dev"
34+
}
35+
}
36+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace NinetyNine\Url\Exceptions;
3+
4+
class InvalidArrayElementException extends \Exception
5+
{
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace NinetyNine\Url\Exceptions;
3+
4+
class InvalidArrayException extends \Exception
5+
{
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace NinetyNine\Url\Exceptions;
3+
4+
class InvalidProtocolException extends \Exception
5+
{
6+
7+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
namespace NinetyNine\Url\Helpers;
3+
4+
use NinetyNine\Url\Exceptions\InvalidArrayException;
5+
6+
class Methods
7+
{
8+
/**
9+
* Check if an array is associative or not
10+
*
11+
* @param array $array
12+
* @return bool
13+
*/
14+
public static function isAssociative(array $array)
15+
{
16+
return !empty($array) && array_keys($array) !== range(0, count($array) - 1);
17+
}
18+
19+
/**
20+
* Check if an array is associative or not and throw
21+
*
22+
* @param array $array
23+
* @throws InvalidArrayException
24+
* @return void
25+
*/
26+
public static function isAssociativeVolatile(array $array)
27+
{
28+
if (!static::isAssociative($array)) {
29+
throw new InvalidArrayException;
30+
}
31+
}
32+
33+
/**
34+
* Flattern an array
35+
*
36+
* @param array $array
37+
* @param array $tmp
38+
* @return array
39+
*/
40+
public static function flattern(array $array, &$tmp = [])
41+
{
42+
foreach ($array as $element) {
43+
if (!is_array($element)) {
44+
$tmp[] = $element;
45+
46+
continue;
47+
}
48+
49+
$tmp = static::flattern($element, $tmp);
50+
}
51+
52+
return $tmp;
53+
}
54+
55+
/**
56+
* Remove an array element
57+
*
58+
* @param string|int $key
59+
* @param array $array
60+
* @return array
61+
*/
62+
public static function remove($key, array &$array)
63+
{
64+
unset($array[ $key ]);
65+
66+
return $array;
67+
}
68+
}

0 commit comments

Comments
 (0)