コード例 #1
0
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();
}
コード例 #2
0
function _pluck($list, $propertyName)
{
    return Underscore::pluck($list, $propertyName);
}
コード例 #3
0
ファイル: Underscore.php プロジェクト: brombal/underscore.php
 /**
  * @dataProvider peopleDataProvider
  * @tags collections
  */
 public function testPluck($people, $type, $meta)
 {
     // it should extract a single column from a 2 dimentionnal array
     $this->array(_::pluck($people, 'name'))->containsValues($meta['names'])->hasSize($meta['count'])->hasKeys($meta['keys']);
     // it should set values to null when given property is not found
     $this->array(_::pluck($people, 'inexistent'))->isEqualTo(array_combine($meta['keys'], array_fill(0, $meta['count'], null)));
 }