Skip to content

Commit

Permalink
Merge pull request #2 from laravel/5.2
Browse files Browse the repository at this point in the history
Don't use `{!! !!}` (laravel#13398)
  • Loading branch information
zither committed May 3, 2016
2 parents 8984ac1 + 61f1afb commit 52fc0b7
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="panel-heading">Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
{!! csrf_field() !!}
{{ csrf_field() }}

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@endif

<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}">
{!! csrf_field() !!}
{{ csrf_field() }}

<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/password/reset') }}">
{!! csrf_field() !!}
{{ csrf_field() }}

<input type="hidden" name="token" value="{{ $token }}">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{!! csrf_field() !!}
{{ csrf_field() }}

<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Name</label>
Expand Down
14 changes: 10 additions & 4 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,15 @@ protected function updateSession($id)
*/
public function loginUsingId($id, $remember = false)
{
$this->session->set($this->getName(), $id);
$user = $this->provider->retrieveById($id);

if (! is_null($user)) {
$this->login($user, $remember);

$this->login($user = $this->provider->retrieveById($id), $remember);
return $user;
}

return $user;
return false;
}

/**
Expand All @@ -487,7 +491,9 @@ public function loginUsingId($id, $remember = false)
*/
public function onceUsingId($id)
{
if (! is_null($user = $this->provider->retrieveById($id))) {
$user = $this->provider->retrieveById($id);

if (! is_null($user)) {
$this->setUser($user);

return true;
Expand Down
37 changes: 26 additions & 11 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ class Builder
*/
protected $scopes = [];

/**
* Removed global scopes.
*
* @var array
*/
protected $removedScopes = [];

/**
* Create a new Eloquent query builder instance.
*
Expand Down Expand Up @@ -102,17 +109,13 @@ public function withGlobalScope($identifier, $scope)
*/
public function withoutGlobalScope($scope)
{
if (is_string($scope)) {
unset($this->scopes[$scope]);

return $this;
if (! is_string($scope)) {
$scope = get_class($scope);
}

foreach ($this->scopes as $key => $value) {
if ($scope instanceof $value) {
unset($this->scopes[$key]);
}
}
unset($this->scopes[$scope]);

$this->removedScopes[] = $scope;

return $this;
}
Expand All @@ -136,6 +139,16 @@ public function withoutGlobalScopes(array $scopes = null)
return $this;
}

/**
* Get an array of global scopes that were removed from the query.
*
* @return array
*/
public function removedScopes()
{
return $this->removedScopes;
}

/**
* Find a model by its primary key.
*
Expand Down Expand Up @@ -942,11 +955,13 @@ protected function whereCountQuery(QueryBuilder $query, $operator = '>=', $count
*/
protected function mergeModelDefinedRelationWheresToHasQuery(Builder $hasQuery, Relation $relation)
{
$removedScopes = $hasQuery->removedScopes();

$relationQuery = $relation->withoutGlobalScopes($removedScopes)->toBase();

// Here we have the "has" query and the original relation. We need to copy over any
// where clauses the developer may have put in the relationship function over to
// the has query, and then copy the bindings from the "has" query to the main.
$relationQuery = $relation->toBase();

$hasQuery->withoutGlobalScopes()->mergeWheres(
$relationQuery->wheres, $relationQuery->getBindings()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public function morphTo($name = null, $type = null, $id = null)
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
if (is_null($class = $this->$type)) {
if (empty($class = $this->$type)) {
return new MorphTo(
$this->newQuery(), $this, $id, null, $type, $name
);
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Eloquent/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ protected function getEagerModelKeys(array $models)
}
}

// If there are no keys that were not null we will just return an array with 0 in
// it so the query doesn't fail, but will not return any results, which should
// be what this developer is expecting in a case where this happens to them.
if (count($keys) == 0) {
return [0];
// If there are no keys that were not null we will just return an array with either
// null or 0 in (depending on if incrementing keys are in use) so the query wont
// fail plus returns zero results, which should be what the developer expects.
if (count($keys) === 0) {
return [$this->related->incrementing ? 0 : null];
}

return array_values(array_unique($keys));
Expand Down
18 changes: 18 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/Pivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ public function __construct(Model $parent, $attributes, $table, $exists = false)
$this->timestamps = $this->hasTimestampAttributes();
}

/**
* Create a new pivot model from raw values returned from a query.
*
* @param \Illuminate\Database\Eloquent\Model $parent
* @param array $attributes
* @param string $table
* @param bool $exists
* @return static
*/
public static function fromRawAttributes(Model $parent, $attributes, $table, $exists = false)
{
$instance = new static($parent, $attributes, $table, $exists);

$instance->setRawAttributes($attributes, true);

return $instance;
}

/**
* Set the keys for a save update query.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected function invalidOperatorAndValue($operator, $value)
{
$isOperator = in_array($operator, $this->operators);

return $isOperator && $operator != '=' && is_null($value);
return is_null($value) && $isOperator && ! in_array($operator, ['=', '<>', '!=']);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,30 @@ public function rename($from, $to)
$this->build($blueprint);
}

/**
* Enable foreign key constraints.
*
* @return bool
*/
public function enableForeignKeyConstraints()
{
return $this->connection->statement(
$this->grammar->compileEnableForeignKeyConstraints()
);
}

/**
* Disable foreign key constraints.
*
* @return bool
*/
public function disableForeignKeyConstraints()
{
return $this->connection->statement(
$this->grammar->compileDisableForeignKeyConstraints()
);
}

/**
* Execute the blueprint to build / modify the table.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
return "rename table {$from} to ".$this->wrapTable($command->to);
}

/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'SET FOREIGN_KEY_CHECKS=1;';
}

/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'SET FOREIGN_KEY_CHECKS=0;';
}

/**
* Create the column definition for a char type.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ public function compileDropForeign(Blueprint $blueprint, Fluent $command)
return "alter table {$table} drop constraint {$index}";
}

/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'SET CONSTRAINTS ALL IMMEDIATE;';
}

/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'SET CONSTRAINTS ALL DEFERRED;';
}

/**
* Compile a rename table command.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
return "alter table {$from} rename to ".$this->wrapTable($command->to);
}

/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'PRAGMA foreign_keys = ON;';
}

/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'PRAGMA foreign_keys = OFF;';
}

/**
* Create the column definition for a char type.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
return "sp_rename {$from}, ".$this->wrapTable($command->to);
}

/**
* Compile the command to enable foreign key constraints.
*
* @return string
*/
public function compileEnableForeignKeyConstraints()
{
return 'EXEC sp_msforeachtable @command1="print \'?\'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all";';
}

/**
* Compile the command to disable foreign key constraints.
*
* @return string
*/
public function compileDisableForeignKeyConstraints()
{
return 'EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all";';
}

/**
* Create the column definition for a char type.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Foundation/Auth/ResetsPasswords.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ trait ResetsPasswords
{
use RedirectsUsers;

/**
* Get the name of the guest middleware.
*
* @return string
*/
protected function guestMiddleware()
{
$guard = $this->getGuard();

return $guard ? 'guest:'.$guard : 'guest';
}

/**
* Display the form to request a password reset link.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
*/
protected function getRecipients(Swift_Mime_Message $message)
{
$to = $bcc = [];
$to = [];

if ($message->getTo()) {
$to = array_merge($to, array_keys($message->getTo()));
Expand All @@ -83,7 +83,7 @@ protected function getRecipients(Swift_Mime_Message $message)
}

if ($message->getBcc()) {
$to = array_merge($bcc, array_keys($message->getBcc()));
$to = array_merge($to, array_keys($message->getBcc()));
}

$recipients = array_map(function ($address) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ protected function actionReferencesController($action)
return false;
}

return is_string($action) || is_string(isset($action['uses']) ? $action['uses'] : null);
return is_string($action) || (isset($action['uses']) && is_string($action['uses']));
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,18 @@ protected function validateActiveUrl($attribute, $value)
return false;
}

/**
* Validate the given value is a valid file.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function validateFile($attribute, $value)
{
return $this->isAValidFileInstance($value);
}

/**
* Validate the MIME type of a file is an image MIME type.
*
Expand Down
Loading

0 comments on commit 52fc0b7

Please sign in to comment.