Exemplo n.º 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();
}
function _get($object, $key, $default = NULL)
{
    return Underscore::get($object, $key, $default);
}
 private function filterModels($filter)
 {
     if (is_array($filter)) {
         foreach ($filter as $key => $keyValue) {
             if (is_array($keyValue)) {
                 if ($keyValue[0] == 'strict') {
                     $this->allModels = Arrays::filter($this->allModels, function ($value) use($key, $keyValue) {
                         return $value[$key] == $keyValue[1];
                     });
                 }
             } elseif (is_bool($keyValue)) {
                 $this->allModels = Arrays::filterBy($this->allModels, $key, $keyValue);
             } else {
                 // todo: Optimize filter with param for "like" and "equal" filtering
                 if ($key === 'slug') {
                     $this->allModels = Arrays::filterBy($this->allModels, $key, $keyValue);
                 } else {
                     $this->allModels = Arrays::filter($this->allModels, function ($value) use($key, $keyValue) {
                         if (!empty($value[$key]) && is_array($value[$key])) {
                             $value[$key] = Arrays::implode($value[$key], "||");
                         } elseif (strpos($key, "|") !== false) {
                             $key = str_replace("|", ".", $key);
                         }
                         $array = new Underscore($value);
                         return stripos($array->get($key), html_entity_decode($keyValue)) !== false;
                     });
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @tags objects
  */
 public function testGet()
 {
     $this->variable(_::get([], 'any'))->isNull();
     $this->variable(_::get(new \stdClass(), 'any'))->isNull();
     $this->variable(_::get([null => null], null))->isNull();
     $this->variable(_::get([0 => 0], false))->isEqualTo(0);
     $this->variable(_::get(['foo' => 1], 'bar'))->isNull();
     $this->variable(_::get((object) ['a' => 1], 'a'))->isEqualTo(1);
     $this->variable(_::get([1, 2, 3], 2))->isEqualTo(3);
     $this->variable(_::get(false, false))->isNull();
 }