Skip to content

Commit

Permalink
fields() renamed to getFields().
Browse files Browse the repository at this point in the history
New PHPCode::dump().
  • Loading branch information
claudio-silva committed Jan 20, 2017
1 parent d7f26ba commit fd00c8a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ function call_method ($ref, $self = null)
function pluck ($flds)
{
return is_array ($flds)
? function ($e) use ($flds) { return fields ($e, $flds); }
? function ($e) use ($flds) { return getFields ($e, $flds); }
: function ($e) use ($flds) { return getField ($e, $flds); };
}
2 changes: 1 addition & 1 deletion src/mixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function setField (&$data, $key, $value)
* @return array A map of keys to extracted values or an empty array if $target is null.
* @throws InvalidArgumentException If the target is not an array, object or null.
*/
function fields ($target, array $keys)
function getFields ($target, array $keys)
{
if (is_array ($target))
return array_only ($target, $keys);
Expand Down
20 changes: 17 additions & 3 deletions src/php-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class PhpCode
* @param callable $errorHandler Optional error-handling code.
* @param bool $reset True if the error status should be cleared so that later code does not intercept the
* previous error.
* @return mixed The return value from the callable argument or the error handler.
* @return mixed The return value from the callable argument or the error handler.
*
* @throws ErrorException
* @throws Exception
* @throws Throwable
*/
static function catchErrorsOn ($wrappedCode, $errorHandler = null, $reset = true)
{
Expand Down Expand Up @@ -88,6 +88,18 @@ static function compile ($_exp, $_vars = '')
'</code>');
}

/**
* Serializes a value to PHP source code.
*
* @param mixed $value
* @param int $indent Text indentation level; it will be multiplied by 2.
* @return string
*/
static function dump ($value, $indent = 0)
{
return ltrim (str_indent (preg_replace ('/^array \((.*)\)/ms', '[$1]', var_export ($value, true)), $indent));
}

/**
* Tries to evaluate a constant value expressed as a string.
*
Expand Down Expand Up @@ -133,6 +145,8 @@ static function evaluate ($_exp, array $_vars = [])
*
* @param string $filename
* @return mixed|null The value returned from the executed code, or `null` if no `return` is called.
* @throws Exception
* @throws Throwable
*/
static function exec ($filename)
{
Expand Down Expand Up @@ -191,7 +205,7 @@ static function validate ($code, &$output = 0)
return false; // Unbalanced braces would break the eval below
ob_start (); // Catch potential parse error messages
$code = eval ('if(0){' . $code . '}'); // Put $code in a dead code sandbox to prevent its execution
if (func_num_args() > 1)
if (func_num_args () > 1)
$output = ob_get_clean ();
else
ob_end_clean ();
Expand Down
2 changes: 1 addition & 1 deletion src/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ function simplePluralize ($num, $thing)
* Indents a (possibly multiline) string.
*
* @param string $str
* @param int $level The indentation level.
* @param int $level The indentation level; it will be multiplied by 2.
* @param string $indent A pattern to be output at the start of each line, repeated $level times.
* @return string
*/
Expand Down

0 comments on commit fd00c8a

Please sign in to comment.