| Server IP : 54.94.228.101 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/anahkiasen/underscore-php/src/ |
Upload File : |
<?php
namespace Underscore;
/**
* Various helpers relatives to methods.
*/
class Method
{
/**
* A list of methods to automatically defer to PHP.
*
* @type array
*/
public static $defer = [
'trim',
'count',
'round',
'ceil',
'floor',
'substr',
'str_pad' => 'pad',
'ucfirst',
'lcfirst',
'ucwords',
'strtolower',
'strtoupper',
];
/**
* A list of methods where the subject
* isn't to be added to the arguments.
*
* @type array
*/
protected static $subjectless = [
'fill',
];
/**
* A list of methods that are allowed
* to break the chain.
*
* @type array
*/
protected static $breakers = [
'get',
'sum',
'count',
'fromJSON',
'toJSON',
'fromXML',
'fromCSV',
'toCSV',
];
/**
* Unchainable methods.
*
* @type array
*/
protected static $unchainable = [
'Arrays::range',
'Arrays::repeat',
];
/**
* A cache for better findInClasses performances.
*
* @type array
*/
protected static $findCache = [];
////////////////////////////////////////////////////////////////////
////////////////////////////// HELPERS /////////////////////////////
////////////////////////////////////////////////////////////////////
/**
* Get the Methods class from the Type class.
*
* @param string $class The Type class
*
* @return string The Methods class
*/
public static function getMethodsFromType($class)
{
return str_replace('Types', 'Methods', $class.'Methods');
}
/**
* Whether a native method requires a subject or not.
*
* @param string $method The function
*
* @return bool
*/
public static function isSubjectless($method)
{
return in_array($method, static::$subjectless, true);
}
/**
* Whether a method should not be chained.
*
* @param string $class The class
* @param string $method The method
*
* @return bool
*/
public static function isUnchainable($class, $method)
{
$class = str_replace('Underscore\Types\\', null, $class);
return in_array($class.'::'.$method, static::$unchainable, true);
}
/**
* Whether a method is a breaker.
*
* @param string $method The method
*
* @return bool
*/
public static function isBreaker($method)
{
return in_array($method, static::$breakers, true);
}
/**
* Get a method name by its alias.
*
* @param string $method The method
*
* @return string The real method name
*/
public static function getAliasOf($method)
{
return Underscore::option('aliases.'.$method);
}
/**
* Get the native function corresponding to a method.
*
* @param string $method The method to look for
*
* @return string The native function
*/
public static function getNative($method)
{
// If a defered method exist
if (in_array($method, static::$defer, true)) {
$native = array_search($method, static::$defer, true);
return is_int($native) ? $method : $native;
}
return false;
}
/**
* Find a method in the type classes.
*
* @param string $originalClass The class calling the method
* @param string $method The method
*
* @return string The class name
*/
public static function findInClasses($originalClass, $method)
{
$classes = ['Arrays', 'Collection', 'Functions', 'Number', 'Object', 'Strings'];
foreach ($classes as $class) {
if (method_exists('\Underscore\Methods\\'.$class.'Methods', $method)) {
return '\Underscore\Types\\'.$class;
}
}
return $originalClass;
}
}