Skip to content

Commit b03a14b

Browse files
committed
change Orm to ActiveRecord
1 parent dd7df0e commit b03a14b

40 files changed

Lines changed: 9617 additions & 32 deletions

composer.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@
2828
"predis/predis": "0.8.*",
2929
"stack/builder": "1.0.*",
3030
"swiftmailer/swiftmailer": "5.0.*",
31-
"symfony/browser-kit": "2.4.1",
32-
"symfony/console": "2.4.1",
33-
"symfony/css-selector": "2.4.1",
34-
"symfony/debug": "2.4.1",
35-
"symfony/dom-crawler": "2.4.1",
36-
"symfony/finder": "2.4.1",
37-
"symfony/http-foundation": "2.4.1",
38-
"symfony/http-kernel": "2.4.1",
39-
"symfony/process": "2.4.1",
40-
"symfony/routing": "2.4.1",
41-
"symfony/translation": "2.4.1"
31+
"symfony/browser-kit": "2.4.*",
32+
"symfony/console": "2.4.*",
33+
"symfony/css-selector": "2.4.*",
34+
"symfony/debug": "2.4.*",
35+
"symfony/dom-crawler": "2.4.*",
36+
"symfony/finder": "2.4.*",
37+
"symfony/http-foundation": "2.4.*",
38+
"symfony/http-kernel": "2.4.*",
39+
"symfony/process": "2.4.*",
40+
"symfony/routing": "2.4.*",
41+
"symfony/translation": "2.4.*"
4242
},
4343
"require-dev": {
4444
"aws/aws-sdk-php": "2.5.*",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php namespace Fly\Auth;
2+
3+
use Fly\Hashing\HasherInterface;
4+
5+
class ActiveRecordUserProvider implements UserProviderInterface {
6+
7+
/**
8+
* The hasher implementation.
9+
*
10+
* @var \Fly\Hashing\HasherInterface
11+
*/
12+
protected $hasher;
13+
14+
/**
15+
* The ActiveRecord user model.
16+
*
17+
* @var string
18+
*/
19+
protected $model;
20+
21+
/**
22+
* Create a new database user provider.
23+
*
24+
* @param \Fly\Hashing\HasherInterface $hasher
25+
* @param string $model
26+
* @return void
27+
*/
28+
public function __construct(HasherInterface $hasher, $model)
29+
{
30+
$this->model = $model;
31+
$this->hasher = $hasher;
32+
}
33+
34+
/**
35+
* Retrieve a user by their unique identifier.
36+
*
37+
* @param mixed $identifier
38+
* @return \Fly\Auth\UserInterface|null
39+
*/
40+
public function retrieveById($identifier)
41+
{
42+
return $this->createModel()->newQuery()->find($identifier);
43+
}
44+
45+
/**
46+
* Retrieve a user by the given credentials.
47+
*
48+
* @param array $credentials
49+
* @return \Fly\Auth\UserInterface|null
50+
*/
51+
public function retrieveByCredentials(array $credentials)
52+
{
53+
// First we will add each credential element to the query as a where clause.
54+
// Then we can execute the query and, if we found a user, return it in a
55+
// ActiveRecord User "model" that will be utilized by the Guard instances.
56+
$query = $this->createModel()->newQuery();
57+
58+
foreach ($credentials as $key => $value)
59+
{
60+
if ( ! str_contains($key, 'password')) $query->where($key, $value);
61+
}
62+
63+
return $query->first();
64+
}
65+
66+
/**
67+
* Validate a user against the given credentials.
68+
*
69+
* @param \Fly\Auth\UserInterface $user
70+
* @param array $credentials
71+
* @return bool
72+
*/
73+
public function validateCredentials(UserInterface $user, array $credentials)
74+
{
75+
$plain = $credentials['password'];
76+
77+
return $this->hasher->check($plain, $user->getAuthPassword());
78+
}
79+
80+
/**
81+
* Create a new instance of the model.
82+
*
83+
* @return \Fly\Database\ActiveRecord\Model
84+
*/
85+
public function createModel()
86+
{
87+
$class = '\\'.ltrim($this->model, '\\');
88+
89+
return new $class;
90+
}
91+
92+
}

src/Fly/Auth/AuthManager.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,35 @@ protected function createDatabaseProvider()
6161
$connection = $this->app['db']->connection();
6262

6363
// When using the basic database user provider, we need to inject the table we
64-
// want to use, since this is not an Eloquent model we will have no way to
64+
// want to use, since this is not an ActiveRecord model we will have no way to
6565
// know without telling the provider, so we'll inject the config value.
6666
$table = $this->app['config']['auth.table'];
6767

6868
return new DatabaseUserProvider($connection, $this->app['hash'], $table);
6969
}
7070

7171
/**
72-
* Create an instance of the Eloquent driver.
72+
* Create an instance of the ActiveRecord driver.
7373
*
7474
* @return \Fly\Auth\Guard
7575
*/
76-
public function createEloquentDriver()
76+
public function createActiveRecordDriver()
7777
{
78-
$provider = $this->createEloquentProvider();
78+
$provider = $this->createActiveRecordProvider();
7979

8080
return new Guard($provider, $this->app['session.store']);
8181
}
8282

8383
/**
84-
* Create an instance of the Eloquent user provider.
84+
* Create an instance of the ActiveRecord user provider.
8585
*
86-
* @return \Fly\Auth\EloquentUserProvider
86+
* @return \Fly\Auth\ActiveRecordUserProvider
8787
*/
88-
protected function createEloquentProvider()
88+
protected function createActiveRecordProvider()
8989
{
9090
$model = $this->app['config']['auth.model'];
9191

92-
return new OrmUserProvider($this->app['hash'], $model);
92+
return new ActiveRecordUserProvider($this->app['hash'], $model);
9393
}
9494

9595
/**

0 commit comments

Comments
 (0)