-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #149
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 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
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
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
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,39 @@ | ||
<?php | ||
|
||
namespace BaoPham\DynamoDb; | ||
|
||
/** | ||
* Class H | ||
* | ||
* Short for "Helper". | ||
* We often get breaking changes from Laravel Helpers, so to ensure this won't happen again, we port the helpers here. | ||
* | ||
* @package BaoPham\DynamoDb | ||
*/ | ||
// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps | ||
class H | ||
{ | ||
public static function array_first($array, callable $callback = null, $default = null) | ||
{ | ||
if (is_null($callback)) { | ||
if (empty($array)) { | ||
return static::value($default); | ||
} | ||
foreach ($array as $item) { | ||
return $item; | ||
} | ||
} | ||
foreach ($array as $key => $value) { | ||
if (call_user_func($callback, $value, $key)) { | ||
return $value; | ||
} | ||
} | ||
return static::value($default); | ||
} | ||
|
||
public static function value($value) | ||
{ | ||
return $value instanceof \Closure ? $value() : $value; | ||
} | ||
} | ||
// phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps |