private function _parseUrlParams($url) { $urlComponents = parse_url($url); $query = Arrays::getValue($urlComponents, 'query', ''); parse_str($query, $array); return $array; }
/** * @return bool */ public function isShittyRound() { $hitsInRound = Hit::where(['game_user_id' => $this->game->current_game_user_id, 'round' => $this->game->round])->fetchAll(); return Arrays::all($hitsInRound, function ($hit) { return !$this->isScored($hit->field, $hit->multiplier); }); }
public static function newInstance($options) { if (Arrays::getValue($options, Options::EMULATE_PREPARES)) { return new EmulatedPDOPreparedStatementExecutor(); } return new PDOPreparedStatementExecutor(); }
/** * Returns object from cache. * If there's no object for the given key and $functions is passed, $function result will be stored in cache under the given key. * * Example: * <code> * $countries = Cache::get("countries", function() {{ * //expensive computation that returns a list of countries * return Country:all(); * }) * </code> * * @param $key * @param null $function * @return mixed|null */ public static function get($key, $function = null) { if (!self::contains($key) && $function) { self::put($key, call_user_func($function)); } return Arrays::getValue(self::$_cache, $key); }
private static function newRelation($name, $localKey, $foreignKey, $collection, $params) { $class = $params['class']; $condition = Arrays::getValue($params, 'conditions', ''); $order = Arrays::getValue($params, 'order', ''); return new Relation($name, $class, $localKey, $foreignKey, $collection, $condition, $order); }
public static function of(array $conditions) { if (Arrays::isAssociative($conditions)) { return new ArrayWhereClause($conditions, 'OR'); } return new OrClause($conditions); }
public function matches($argument) { if (get_class($this->expected) !== get_class($argument)) { return false; } $actualAttributes = Arrays::filterByAllowedKeys($argument->attributes(), $this->expected->getFields()); return $this->expectedAttributes == $actualAttributes; }
public function getRelation($name) { $value = Arrays::getValue($this->relations, $name); if (is_null($value)) { throw new Exception("Relation not found"); } return $value; }
private function _prepareParameters($uri) { preg_match_all('#:(\\w+)#', $uri, $matches); $parameters = Arrays::getValue($matches, 1, array()); return Arrays::map($parameters, function ($parameter) { return '$' . $parameter; }); }
private function whereWithUsing() { $usingClauses = $this->_query->usingClauses; $whereClauses = Arrays::map($usingClauses, function (JoinClause $usingClause) { return WhereClause::create($usingClause->getJoinColumnWithTable() . ' = ' . $usingClause->getJoinedColumnWithTable()); }); return $this->_where(array_merge($whereClauses, $this->_query->whereClauses)); }
/** * Returns comparator which compares objects by using values computed using given expressions. * Expressions should comply with format accepted by <code>Functions::extractExpression</code>. * Comparator returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. * * @param mixed ... * @return callable */ public static function compareBy() { $expressions = func_get_args(); $comparators = Arrays::map($expressions, function ($expression) { return new EvaluatingComparator(Functions::extractExpression($expression)); }); return sizeof($comparators) == 1 ? $comparators[0] : new CompoundComparator($comparators); }
public function contents() { $this->_setupTablePlaceholderReplacements(); $this->classStub->addPlaceholderReplacement('class', $this->className); $this->classStub->addPlaceholderReplacement('namespace', $this->classNamespace); Arrays::map($this->tableInfo->tableColumns, array($this->classStub, 'addColumn')); return $this->classStub->contents(); }
public function __construct($httpCode, $errors, $headers = array()) { $this->_httpCode = $httpCode; $this->_errors = Arrays::toArray($errors); $this->_headers = $headers; $firstError = Arrays::first($this->_errors); parent::__construct($firstError->getMessage(), $firstError->getCode()); }
private static function getViewPostfix($responseType) { $availableViewsMap = array('text/xml' => '.xml.phtml', 'application/json' => '.json.phtml', 'text/json' => '.json.phtml'); $viewForType = Arrays::getValue($availableViewsMap, $responseType, false); if ($viewForType) { return $viewForType; } return Uri::isAjax() ? '.ajax.phtml' : '.phtml'; }
private static function extractParams($elements) { $params = array(); foreach ($elements as $element) { list($name, $value) = Arrays::map(explode('=', $element), Functions::trim()); $params[$name] = $value; } return $params; }
private function _getPrimaryKey($tableName) { $primaryKey = Db::getInstance()->query("SHOW KEYS FROM {$tableName} WHERE Key_name = 'PRIMARY'")->fetch(); if ($primaryKey) { return Arrays::getValue($primaryKey, 'Column_name'); } else { return ''; } }
public function parse() { if (preg_match('/^findBy([a-zA-Z]\\w*)$/', $this->method, $names)) { $names = explode('And', $names[1]); $this->names = Arrays::map($names, function ($name) { return Strings::camelCaseToUnderscore($name); }); } }
/** * @test */ public function shouldTraceInfoAboutHttpRequest() { //given $this->_createHttpTraceRequest('/request1', array('param1' => 1, 'param2' => 2)); //when $queries = Arrays::first(Stats::queries()); //then ArrayAssert::that($queries['request_params'][0])->hasSize(2)->containsKeyAndValue(array('param1' => 1, 'param2' => 2)); }
public function getPath() { $uri = Arrays::getValue($_SERVER, 'REDIRECT_URL'); if (!$uri) { return Arrays::getValue($_SERVER, 'REQUEST_URI', '/'); } $queryString = Arrays::getValue($_SERVER, 'REDIRECT_QUERY_STRING'); return $queryString ? $uri . '?' . $queryString : $uri; }
public function getFieldsAsString() { $fields = array_keys($this->_attributes); $escapedFields = Arrays::map($fields, Functions::compose(Functions::append("'"), Functions::prepend("'"))); for ($index = self::FIELDS_COUNT_IN_LINE; $index < sizeof($escapedFields); $index += self::FIELDS_COUNT_IN_LINE) { $escapedFields[$index] = "\n\t\t\t" . $escapedFields[$index]; } return implode(', ', $escapedFields); }
private function _getPrimaryKey($tableName) { $primaryKey = Db::getInstance()->query("SELECT pg_attribute.attname\n FROM pg_index, pg_class, pg_attribute\n WHERE\n pg_class.oid = '{$tableName}'::REGCLASS AND\n indrelid = pg_class.oid AND\n pg_attribute.attrelid = pg_class.oid AND\n pg_attribute.attnum = ANY(pg_index.indkey)\n AND indisprimary;\n ")->fetch(); if ($primaryKey) { return Arrays::getValue($primaryKey, 'attname'); } else { return ''; } }
public function join() { $any = Arrays::any($this->_query->joinClauses, function (JoinClause $joinClause) { return Strings::equalsIgnoreCase($joinClause->type, 'RIGHT'); }); if ($any) { throw new BadMethodCallException('RIGHT JOIN is not supported in sqlite3'); } return parent::join(); }
public static function resolve() { $accept = array_keys(RequestHeaders::accept()) ?: array('*/*'); $supported = array('application/json' => 'application/json', 'application/xml' => 'application/xml', 'application/*' => 'application/json', 'text/html' => 'text/html', 'text/*' => 'text/html'); $intersection = array_intersect($accept, array_keys($supported)); if ($intersection) { return $supported[Arrays::first($intersection)]; } return Arrays::getValue($supported, ContentType::value(), 'text/html'); }
public static function __callStatic($name, $arguments) { Session::checkSession(); $dynamicFinder = DynamicFinder::match($name); if ($dynamicFinder) { $where = Arrays::combine($dynamicFinder->getNames(), $arguments); return static::where($where); } throw new BadMethodCallException('Method [' . $name . '] not exists'); }
function postButton($label, $url, $options = []) { $class = Arrays::getValue($options, 'class', ''); $id = Arrays::getValue($options, 'id', ''); $idHtml = $id ? " id=\"{$id}\" " : ""; return <<<TAG <form action="{$url}" {$idHtml} method="post" class="post-button {$class}"> <button type="submit" class="btn btn-primary">{$label}</button> </form> TAG; }
function showSuccess(array $notices = array()) { if (Session::has('messages') || $notices) { $sessionMessages = Arrays::filterNotBlank(Arrays::toArray(Session::get('messages'))); $notices = array_merge($sessionMessages, $notices); $noticeView = new View('success_alert'); $noticeView->notices = $notices; return $noticeView->render(); } return null; }
private function _getColumnsWithoutPrimary(Dialect $dialect) { $primaryKeyName = $this->primaryKeyName; $columns = $dialect->columns(); if ($primaryKeyName != 'id') { return Arrays::filter($columns, function (DatabaseColumn $column) use($primaryKeyName) { return $column->name != $primaryKeyName; }); } return $columns; }
/** * @test */ public function shouldCreateSelectQueryWithJoin() { // when $query = Query::select()->join('table', 'id', 'other_id', 'tab'); // then $this->assertCount(1, $query->joinClauses); $join = Arrays::first($query->joinClauses); $this->assertEquals('id', $join->joinColumn); $this->assertEquals('table', $join->joinTable); $this->assertEquals('other_id', $join->joinedColumn); }
private function createCheckParameters($parameters) { if ($parameters) { $indent = self::INDENT; $checkFunctionParameters = Arrays::map($parameters, function ($element) use($indent) { return $indent . "checkParameter({$element});"; }); return implode("\n", $checkFunctionParameters) . "\n" . $indent; } return self::INDENT; }
public static function _checkCredentials($authUser, $authPassword, $realm) { $login = Arrays::getValue($_SERVER, 'PHP_AUTH_USER'); $pass = Arrays::getValue($_SERVER, 'PHP_AUTH_PW'); if ($authUser != $login || $authPassword != $pass) { $code = defined('UNAUTHORIZED') ? UNAUTHORIZED : 0; $error = new Error($code, I18n::t('exception.unauthorized')); throw new UnauthorizedException($error, array('WWW-Authenticate: Basic realm="' . $realm . '"')); } return true; }