Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dextermb committed Jul 15, 2018
1 parent 429857b commit 2079061
Show file tree
Hide file tree
Showing 16 changed files with 1,459 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea/
.code/
vendor/

.env
.DS_Store

composer.lock
index.php
36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "ninetynine/url",
"description": "A package which offers a helper to build URLs",
"minimum-stability": "dev",
"type": "library",
"license": "LGPL-3.0",
"keywords": [
"helpers",
"php"
],
"homepage": "https://github.com/ninetynine/url",
"support": {
"issues": "https://github.com/ninetynine/url/issues",
"source": "https://github.com/ninetynine/url"
},
"authors": [
{
"name": "Dexter Marks-Barber",
"email": "dexter@marks-barber.co.uk",
"role": "Maintainer"
}
],
"require": {
"php": "^7.0.0"
},
"autoload": {
"psr-4": {
"NinetyNine\\Url\\": "src/NinetyNine/Url"
}
},
"extra": {
"branch-alias": {
"dev-master": "0.x-dev"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace NinetyNine\Url\Exceptions;

class InvalidArrayElementException extends \Exception
{

}
7 changes: 7 additions & 0 deletions src/NinetyNine/Url/Exceptions/InvalidArrayException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace NinetyNine\Url\Exceptions;

class InvalidArrayException extends \Exception
{

}
7 changes: 7 additions & 0 deletions src/NinetyNine/Url/Exceptions/InvalidProtocolException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace NinetyNine\Url\Exceptions;

class InvalidProtocolException extends \Exception
{

}
68 changes: 68 additions & 0 deletions src/NinetyNine/Url/Helpers/Methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
namespace NinetyNine\Url\Helpers;

use NinetyNine\Url\Exceptions\InvalidArrayException;

class Methods
{
/**
* Check if an array is associative or not
*
* @param array $array
* @return bool
*/
public static function isAssociative(array $array)
{
return !empty($array) && array_keys($array) !== range(0, count($array) - 1);
}

/**
* Check if an array is associative or not and throw
*
* @param array $array
* @throws InvalidArrayException
* @return void
*/
public static function isAssociativeVolatile(array $array)
{
if (!static::isAssociative($array)) {
throw new InvalidArrayException;
}
}

/**
* Flattern an array
*
* @param array $array
* @param array $tmp
* @return array
*/
public static function flattern(array $array, &$tmp = [])
{
foreach ($array as $element) {
if (!is_array($element)) {
$tmp[] = $element;

continue;
}

$tmp = static::flattern($element, $tmp);
}

return $tmp;
}

/**
* Remove an array element
*
* @param string|int $key
* @param array $array
* @return array
*/
public static function remove($key, array &$array)
{
unset($array[ $key ]);

return $array;
}
}
Loading

0 comments on commit 2079061

Please sign in to comment.