多くのLaravel 4は私にとって初めてなので、これがばかげた質問である場合はお詫びします。独自のパスワード検証ルール (投稿時にコアにハードコードされている) を定義し、エラー報告の方法を変更したいので、コア パスワード機能のいくつかのメソッドをオーバーライドしようとしています (で使用される $errors 配列セッションベースではなく、他の形式)。
したがって、私のアプローチは、 /app/lib/MyProject/User に Password.php という新しいクラスを作成することでした。これは次のようになります。
<?php namespace MyProject\User;
use Closure;
use Illuminate\Mail\Mailer;
use Illuminate\Routing\Redirector;
use Illuminate\Auth\UserProviderInterface;
class Password extends \Illuminate\Support\Facades\Password
{
/**
* Reset the password for the given token.
*
* @param array $credentials
* @param Closure $callback
* @return mixed
*/
public function reset(array $credentials, Closure $callback)
{
// If the responses from the validate method is not a user instance, we will
// assume that it is a redirect and simply return it from this method and
// the user is properly redirected having an error message on the post.
$user = $this->validateReset($credentials);
if ( ! $user instanceof RemindableInterface)
{
return $user;
}
$pass = $this->getPassword();
// Once we have called this callback, we will remove this token row from the
// table and return the response from this callback so the user gets sent
// to the destination given by the developers from the callback return.
$response = call_user_func($callback, $user, $pass);
$this->reminders->delete($this->getToken());
return $response;
}
}
/vendor/laravel/framework/src/Illuminate/Auth/Reminders/PasswordBroker.php からリセット メソッドをコピーしました。これは、コアの Password ファサードが解決される場所のようです。
次に、composer.json ファイルで、autoload:classmap 配列に以下を追加しました。
"app/lib/MyProject/User"
最後に、/app/config/app.php ファイルで、パスワード エイリアスを修正しました。
'Password' => 'MyProject\User\Password',
わかった。私のroutes.phpファイルには、ドキュメントからほとんど直接取られた次のものがあります。
Route::post('password/reset/{token}', function()
{
$credentials = array('email' => Input::get('email'));
return Password::reset($credentials, function($user, $password)
{
$user->password = Hash::make($password);
$user->save();
return 'saved - login';
});
});
この reset() メソッドを実行すると、次のエラーが発生します。
非静的メソッド MyProject\User\Password::reset() を静的に呼び出すべきではありません
私が拡張しているクラスの reset() メソッドは static ではないので驚きましたが、reset メソッドを static に設定すると、そのエラーがクリアされます。次に、次のエラーが表示されます。
オブジェクト コンテキスト以外で $this を使用する
$this->validateReset($credentials) を実行しようとすると発生します。
私は今、完全に私の深さから外れています。私はこれを正しい方法で行っていますか、それとも完全に正しい道から外れていますか?
アドバイスをありがとう