Skip to content

Latest commit

 

History

History
139 lines (91 loc) · 2.65 KB

Obj.md

File metadata and controls

139 lines (91 loc) · 2.65 KB

Object Documentation

\Greg\Support\Obj is working with objects.

Table of contents:

Methods:

  • call - Call a callable with arguments;
  • callRef - Call a callable with arguments reference;
  • callMixed - Call a callable with mixed arguments. You don't care anymore of arguments order;
  • callMixedRef - Call a callable with mixed arguments reference. You don't care anymore of arguments order;
  • baseName - Get basename of a class;
  • exists - Determine if a class exists;
  • uses - Get all uses of a class;
  • usesRecursive - Get all uses of a class and its parents.

call

Call a callable with arguments.

call(callable(...$args): mixed $callable, ...$args): mixed

$callable - Callable;
    ...$args - Arguments that was set in ...$args;
...$args - Callable arguments.

Example:

\Greg\Support\Obj::call(function($foo) { return $foo; }, 'foo'); // result: foo

callRef

Call a callable with arguments reference. See call method.

callMixed

Call a callable with mixed arguments. You don't care anymore of arguments order.

callMixed(callable(...$args): mixed $callable, ...$args): mixed

$callable - Callable;
    ...$args - Arguments that was set in ...$args;
...$args - Callable arguments.

Example:

class Foo
{
}

$foo = new Foo();

\Greg\Support\Obj::callMixed(function (Foo $foo, $one, $two, $three = 3) { return func_get_args(); }, 1, $foo, 2); // result: [Foo, 1, 2]

callMixedRef

Call a callable with mixed arguments reference. See callMixed method.

baseName

Get basename of a class.

baseName(string|object $class): string

$class - The class.

Example:

\Greg\Support\Obj::baseName(Foo\Bar::class); // result: Bar

exists

Determine if a class exists.

exists(string|array $name, string|array $prefix = null, string|array $suffix = null): boolean

$name - Name or name parts as array;
$prefix - Prefix;
$suffix - Suffix.

Example:

// Let say we have a class \Foo\BarStrategy
\Greg\Support\Obj::exists('Bar', 'Foo\\', 'Strategy'); // result: true

uses

Get all uses of a class.

uses(string|object $class): array

$class - The class.

Example:

trait FooTrait
{

}

trait BarTrait
{
    use FooTrait;
}

class Baz
{
    use BarTrait;
}

\Greg\Support\Obj::uses(Baz::class); // result: ['BarTrait' => 'BarTrait', 'FooTrait' => 'FooTrait']

usesRecursive

Get all uses of a class and its parents. See uses method.