Created
November 19, 2014 22:33
-
-
Save thomasbellio/8bb4e5120d3857468db4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh namespace Repositories\Generics; | |
class BaseRepository<T> | |
{ | |
private $model; | |
public function __construct(T $model) | |
{ | |
$this->model = $model; | |
} | |
/** | |
* Saves the model | |
* @param T $model | |
* @return bool true if the model was saved | |
*/ | |
public function save(T $model) | |
{ | |
return $model->save(); | |
} | |
public function all() | |
{ | |
return $this->model->all(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Auth\UserTrait; | |
use Illuminate\Auth\UserInterface; | |
use Illuminate\Auth\Reminders\RemindableTrait; | |
use Illuminate\Auth\Reminders\RemindableInterface; | |
use Illuminate\Database\Eloquent\Model; | |
class User extends Model implements UserInterface, RemindableInterface { | |
use UserTrait, RemindableTrait; | |
/** | |
* The database table used by the model. | |
* | |
* @var string | |
*/ | |
protected $table = 'users'; | |
/** | |
* The attributes excluded from the model's JSON form. | |
* | |
* @var array | |
*/ | |
protected $hidden = array('password', 'remember_token'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?hh use Repositories\Generics\BaseRepository; | |
class UserControllerGeneric { | |
private BaseRepository<User> $baseRepository; | |
public function __construct(BaseRepository<User> $baseRepository) | |
{ | |
$this->baseRepository = $baseRepository; | |
} | |
public function save() | |
{ | |
$user = new User; | |
$user->email = uniqid().'@indatus.com'; | |
$user->password = 'password'; | |
$this->baseRepository->save($user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment