function _getMethods() { $reflect = new ReflectionClass('Underscore\\Underscore'); $examples = _getExamples(); return _::chain($reflect->getMethods())->map(function ($method) { $parameters = _getParameters($method); $documentation = _getDocumentation($method, $parameters); return (object) ['name' => $method->name, 'isPublic' => $method->isPublic() && strpos($method->name, '__') === false, 'parameters' => $parameters, 'description' => $documentation->description, 'category' => $documentation->category, 'throws' => $documentation->throws, 'returns' => $documentation->returns, 'aliasOf' => $documentation->aliasOf, 'aliases' => [], 'reflect' => $method, 'prototype' => "_::{$method->name}(" . implode(',', _::keys($parameters)) . ")"]; })->indexBy('name')->filter(function ($method) { return $method->isPublic; })->invoke(function () use($examples) { $this->argumentsAsString = implode(', ', _::pluck($this->parameters, 'asString')); $this->argumentsAsStringNoRef = implode(', ', _::pluck($this->parameters, 'asStringNoRef')); $this->argumentsAsStringNoRefNoValue = implode(', ', _::pluck($this->parameters, 'asStringNoRefNoValue')); $this->examples = (array) _::get($examples, $this->name, []); })->tap(function (&$methods) { foreach ($methods as $method) { if ($method->aliasOf) { $methods[$method->aliasOf]->aliases[] = $method->name; } } })->reject(function ($method) { return $method->aliasOf; })->value(); }
function _keys($object) { return Underscore::keys($object); }
/** * @tags objects */ public function testKeys() { $array = ['a' => 1, 'b' => 2, 'c' => 3]; $this->array(_::keys($array))->isEqualTo(array_keys($array)); $object = new \stdClass(); $object->a = 1; $object->b = 2; $object->c = 3; $this->array(_::keys($object))->isEqualTo(['a', 'b', 'c']); $iterator = new \ArrayIterator([1, 2, 3]); $this->array(_::keys($iterator))->isEqualTo([0, 1, 2]); }