-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Helper; | ||
|
||
use Phalcon\Helper\Exception; | ||
|
||
/** | ||
* Phalcon\Helper\Arr | ||
* | ||
* Array helper methods | ||
*/ | ||
class Arr | ||
{ | ||
/** | ||
* Helper method to check an array for an element. If it exists it returns it, | ||
* if not, it returns the supplied default value | ||
*/ | ||
public static function get(var key, array collection, var defaultValue = null) -> var | ||
{ | ||
var value; | ||
|
||
if typeof !== "string" || true !== is_numeric(key) { | ||
throw new Exception("Key must be either string or numeric"); | ||
} | ||
|
||
if likely fetch value, collection[name] { | ||
return value; | ||
} | ||
|
||
return defaultValue; | ||
} | ||
|
||
/** | ||
* Helper method to add an element to an array with an optional key. Returns | ||
* the final array | ||
*/ | ||
public static function set(var value, array collection = [], var key = null) -> array | ||
{ | ||
if null === key { | ||
let collection[] = value; | ||
} else { | ||
let collection[key] = value; | ||
} | ||
|
||
return collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.txt | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Phalcon\Helper; | ||
|
||
/** | ||
* Phalcon\Helper\Tag\Exception | ||
* | ||
* Exceptions thrown in Phalcon\Helper will use this class | ||
* | ||
*/ | ||
class Exception extends \Phalcon\Exception | ||
{ | ||
|
||
} |