本文整理汇总了PHP中Ouzo\Utilities\Arrays::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Arrays::first方法的具体用法?PHP Arrays::first怎么用?PHP Arrays::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ouzo\Utilities\Arrays
的用法示例。
在下文中一共展示了Arrays::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callFunction
public static function callFunction($functionName, $parameters)
{
$db = self::getInstance();
$bindParams = Arrays::toArray($parameters);
$paramsQueryString = implode(',', array_pad(array(), sizeof($bindParams), '?'));
return Arrays::first($db->query("SELECT {$functionName}({$paramsQueryString})", $parameters)->fetch());
}
示例2: removeTablePrefix
private function removeTablePrefix($tableNameParts)
{
if (Arrays::first($tableNameParts) == $this->tablePrefix) {
array_shift($tableNameParts);
}
return $tableNameParts;
}
示例3: __construct
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());
}
示例4: shouldTraceInfoAboutHttpRequest
/**
* @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));
}
示例5: resolve
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');
}
示例6: isScored
/**
* @inheritdoc
*/
public function isScored($field, $multiplier)
{
$isScoredField = in_array($field, self::$SCORED_FIELDS);
if ($isScoredField) {
$sum = Hit::select('sum(multiplier)')->where(['game_user_id' => $this->game->current_game_user_id, 'field' => $field])->fetch();
$hitCountBeforeCurrentHit = Arrays::first($sum) - $multiplier;
return $hitCountBeforeCurrentHit < 3;
}
return false;
}
示例7: shouldCreateSelectQueryWithJoin
/**
* @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);
}
示例8: shouldReturnCorrectRouteRule
/**
* @test
*/
public function shouldReturnCorrectRouteRule()
{
//given
Route::get('/user/index', 'User#index');
//when
$route = Arrays::first(Route::getRoutes());
//then
$this->assertEquals('/user/index', $route->getUri());
$this->assertEquals('User', $route->getController());
$this->assertEquals('index', $route->getAction());
}
示例9: shouldEmitEventAfterHit
/**
* @test
*/
public function shouldEmitEventAfterHit()
{
//given
$field = '20t';
//when
$this->post('/hit', ['field' => $field]);
//then
/** @var Event $event */
$event = Arrays::first(Event::all());
$this->assertEquals('hit', $event->name);
$this->assertEquals('{"field":20,"multiplier":3,"scored":true,"winner":false,"shots_left":2}', $event->params);
}
示例10: execute
public function execute()
{
if (empty($this->_models)) {
return;
}
$this->_callBeforeSaveCallbacks();
$metaInstance = Arrays::first($this->_models);
$columns = $metaInstance->getFieldsWithoutPrimaryKey();
$primaryKey = $metaInstance->getIdName();
$table = $metaInstance->getTableName();
$sql = DialectFactory::create()->batchInsert($table, $primaryKey, $columns, count($this->_models));
$params = $this->_prepareParams($primaryKey);
$ids = Arrays::flatten(Db::getInstance()->query($sql, $params)->fetchAll(PDO::FETCH_NUM));
$this->_assignPrimaryKeys($primaryKey, $ids);
$this->_callAfterSaveCallbacks();
}
示例11: extracting
public function extracting()
{
$selectors = func_get_args();
$actual = array();
if (count($selectors) == 1) {
$selector = Arrays::first($selectors);
$actual = Arrays::map($this->actual, Functions::extractExpression($selector, true));
} else {
foreach ($this->actual as $item) {
$extracted = array();
foreach ($selectors as $selector) {
$extracted[] = Functions::call(Functions::extractExpression($selector, true), $item);
}
$actual[] = $extracted;
}
}
return self::that($actual);
}
示例12: addRoute
private static function addRoute($method, $uri, $action, $requireAction = true, $options = array(), $isResource = false)
{
$methods = Arrays::toArray($method);
if (self::$isDebug && $requireAction && self::$validate && self::existRouteRule($methods, $uri)) {
$methods = implode(', ', $methods);
throw new InvalidArgumentException('Route rule for method ' . $methods . ' and URI "' . $uri . '" already exists');
}
$elements = explode('#', $action);
$controller = Arrays::first($elements);
$actionToRule = Arrays::getValue($elements, 1);
$routeRule = new RouteRule($method, $uri, $controller, $actionToRule, $requireAction, $options, $isResource);
if ($routeRule->hasRequiredAction()) {
throw new InvalidArgumentException('Route rule ' . $uri . ' required action');
}
self::$routes[] = $routeRule;
foreach ($methods as $method) {
self::$routeKeys[$method . $uri] = true;
}
}
示例13: shouldGetHitsOnlyForPlayersInCurrentGame
/**
* @test
*/
public function shouldGetHitsOnlyForPlayersInCurrentGame()
{
//given
$user = User::create(['login' => 'test', 'password' => 'a']);
$game1 = Game::create();
$game1->addPlayer($user->getId());
/** @var GameUser $gameUser1 */
$gameUser1 = Arrays::first($game1->game_users);
$game2 = Game::create();
$game2->addPlayer($user->getId());
/** @var GameUser $gameUser2 */
$gameUser2 = Arrays::first($game2->game_users);
Hit::createFor('4d', $gameUser1);
Hit::createFor('15t', $gameUser2);
//when
$hits = Hit::findForGame($game1);
//then
Assert::thatArray($hits)->onProperty('field')->containsExactly('4');
}
示例14: parse
public static function parse($data)
{
$array = array();
$items = Arrays::filterNotBlank(explode(',', $data));
foreach ($items as $item) {
$elements = explode(';', $item);
$media = Arrays::first($elements);
$params = array_slice($elements, 1);
list($type, $subtype) = Arrays::map(explode('/', $media), Functions::trim());
$q = Arrays::getValue(self::extractParams($params), 'q');
$array[] = array('type' => $type, 'subtype' => $subtype, 'q' => $q);
}
usort($array, '\\Ouzo\\Http\\AcceptHeaderParser::_compare');
return Arrays::toMap($array, function ($input) {
return $input['type'] . '/' . $input['subtype'];
}, function ($input) {
return $input['q'];
});
}
示例15: process
public function process()
{
$post = $this->post;
$filterLogin = Arrays::filter($this->getElements(), function ($element) use($post) {
if ($element->user_name == $post->user_auth->user_name && $element->password == $post->user_auth->password) {
return $element;
}
return null;
});
if (!$filterLogin) {
$response = new stdClass();
$response->name = 'Invalid Login';
$response->number = '10';
$response->description = 'Login attempt failed please check the username and password';
$this->response = $response;
} else {
$user = Arrays::first($filterLogin);
$response = new stdClass();
$response->id = $user->id;
$this->response = $response;
}
return $this;
}