Skip to content

Commit d0f0c48

Browse files
committed
Namespacify
1 parent df647e6 commit d0f0c48

File tree

20 files changed

+119
-73
lines changed

20 files changed

+119
-73
lines changed

src/php/Chaplin/Auth.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
class Chaplin_Auth extends Zend_Auth
25+
namespace Chaplin;
26+
27+
use Zend_Auth as ZendAuth;
28+
29+
class Auth extends ZendAuth
2630
{
2731
public static function getInstance()
28-
{
32+
{
2933
if (null === self::$_instance) {
3034
self::$_instance = new self();
31-
}
35+
}
3236

3337
return self::$_instance;
3438
}
3539

36-
public static function inject(Zend_Auth $auth)
40+
public static function inject(ZendAuth $auth)
3741
{
3842
self::$_instance = $auth;
3943
}

src/php/Chaplin/Auth/Adapter/Database.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
class Chaplin_Auth_Adapter_Database implements Zend_Auth_Adapter_Interface
25+
namespace Chaplin\Auth\Adapter;
26+
27+
use Chaplin\Auth\Identity;
28+
use Chaplin_Dao_Exception_User_NotFound as ExceptionUserNotFound;
29+
use Chaplin_Gateway as Gateway;
30+
use Zend_Auth_Adapter_Interface as AdapterInterface;
31+
use Zend_Auth_Result as Result;
32+
33+
class Database implements AdapterInterface
2634
{
2735
private $_strUsername;
2836
private $_strPassword;
@@ -36,19 +44,19 @@ public function __construct($strUsername, $strPassword)
3644
public function authenticate()
3745
{
3846
try {
39-
$modelUser = Chaplin_Gateway::getInstance()
47+
$modelUser = Gateway::getInstance()
4048
->getUser()
4149
->getByUsernameAndPassword(
4250
$this->_strUsername,
4351
$this->_strPassword
4452
);
4553

46-
$identity = new Chaplin_Auth_Identity($modelUser);
54+
$identity = new Identity($modelUser);
4755

48-
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
49-
} catch(Chaplin_Dao_Exception_User_NotFound $e) {
50-
return new Zend_Auth_Result(
51-
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
56+
return new Result(Result::SUCCESS, $identity);
57+
} catch(ExceptionUserNotFound $e) {
58+
return new Result(
59+
Result::FAILURE_CREDENTIAL_INVALID,
5260
null,
5361
array($e->getMessage())
5462
);

src/php/Chaplin/Auth/Identity.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
class Chaplin_Auth_Identity
25+
namespace Chaplin\Auth;
26+
27+
use Chaplin_Model_User as ModelUser;
28+
29+
class Identity
2630
{
2731
private $_modelUser;
2832

29-
public function __construct(Chaplin_Model_User $modelUser)
33+
public function __construct(ModelUser $modelUser)
3034
{
3135
$this->_modelUser = $modelUser;
3236
}

src/php/Chaplin/Cache/Backend/Exception/PhpRedisMissing.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
class Chaplin_Cache_Backend_Exception_PhpRedisMissing extends Exception
25+
namespace Chaplin\Cache\Backend\Exception;
26+
27+
class PhpRedisMissing extends \Exception
2628
{
2729
const MESSAGE = 'PhpRedis was not included in the options array of the backend';
2830

src/php/Chaplin/Cache/Backend/PhpRedis.php

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111

1212
/**
1313
* Redis adapter for Zend_Cache
14-
*
14+
*
1515
* @author Soin Stoiana
1616
* @author Colin Mollenhour
1717
* @version 0.0.1
1818
**/
19-
class Chaplin_Cache_Backend_PhpRedis extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
19+
namespace Chaplin\Cache\Backend;
20+
21+
use Redis;
22+
use Zend_Cache as Cache;
23+
use Zend_Cache_Backend as Backend;
24+
use Zend_Cache_Backend_ExtendedInterface as BackendInterface;
25+
use Zend_Config as Config;
26+
27+
class PhpRedis extends Backend implements BackendInterface
2028
{
2129

2230
const SET_IDS = 'zc:ids';
@@ -46,34 +54,33 @@ class Chaplin_Cache_Backend_PhpRedis extends Zend_Cache_Backend implements Zend_
4654
* Contruct Zend_Cache Redis backend
4755
*
4856
* @param array $options
49-
* @return \Chaplin_Cache_Backend_PhpRedis
5057
**/
5158
public function __construct($options = array())
5259
{
53-
if ($options instanceof Zend_Config) {
60+
if ($options instanceof Config) {
5461
$options = $options->toArray();
5562
}
56-
63+
5764
if (isset($options['phpredis'])) {
5865
$this->_redis = $options['phpredis'];
5966
} else {
6067
if (empty($options['server']) ) {
61-
Zend_Cache::throwException('Redis \'server\' not specified.');
68+
Cache::throwException('Redis \'server\' not specified.');
6269
}
6370

6471
if (empty($options['port']) ) {
65-
Zend_Cache::throwException('Redis \'port\' not specified.');
72+
Cache::throwException('Redis \'port\' not specified.');
6673
}
6774

6875
$this->_redis = new Redis;
6976
if (! $this->_redis->connect($options['server'], $options['port']) ) {
70-
Zend_Cache::throwException("Could not connect to Redis server {$options['server']}:{$options['port']}");
77+
Cache::throwException("Could not connect to Redis server {$options['server']}:{$options['port']}");
7178
}
7279
}
7380

7481
if (! empty($options['database'])) {
75-
$this->_redis->select((int) $options['database']) or
76-
Zend_Cache::throwException('The redis database could not be selected.');
82+
$this->_redis->select((int) $options['database']) or
83+
Cache::throwException('The redis database could not be selected.');
7784
}
7885

7986
if (isset($options['notMatchingTags']) ) {
@@ -373,17 +380,17 @@ protected function _collectGarbage()
373380
* @throws Zend_Cache_Exception
374381
* @return boolean True if no problem
375382
**/
376-
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
383+
public function clean($mode = Cache::CLEANING_MODE_ALL, $tags = array())
377384
{
378385
if ($tags && ! is_array($tags)) {
379386
$tags = array($tags);
380387
}
381388

382-
if ($mode == Zend_Cache::CLEANING_MODE_ALL) {
389+
if ($mode == Cache::CLEANING_MODE_ALL) {
383390
return ($this->_redis->flushDb() == 'OK');
384391
}
385392

386-
if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
393+
if ($mode == Cache::CLEANING_MODE_OLD) {
387394
$this->_collectGarbage();
388395
return true;
389396
}
@@ -396,23 +403,23 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
396403

397404
switch ($mode)
398405
{
399-
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
406+
case Cache::CLEANING_MODE_MATCHING_TAG:
400407

401408
$this->_removeByMatchingTags($tags);
402409
break;
403410

404-
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
411+
case Cache::CLEANING_MODE_NOT_MATCHING_TAG:
405412

406413
$this->_removeByNotMatchingTags($tags);
407414
break;
408415

409-
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
416+
case Cache::CLEANING_MODE_MATCHING_ANY_TAG:
410417

411418
$this->_removeByMatchingAnyTags($tags);
412419
break;
413420

414421
default:
415-
Zend_Cache::throwException('Invalid mode for clean() method: '.$mode);
422+
Cache::throwException('Invalid mode for clean() method: '.$mode);
416423
}
417424
return (bool) $result;
418425
}
@@ -439,7 +446,7 @@ public function setDirectives($directives)
439446
parent::setDirectives($directives);
440447
$lifetime = $this->getLifetime(false);
441448
if ($lifetime > 2592000) {
442-
Zend_Cache::throwException('Redis backend has a limit of 30 days (2592000 seconds) for the lifetime');
449+
Cache::throwException('Redis backend has a limit of 30 days (2592000 seconds) for the lifetime');
443450
}
444451
}
445452

@@ -496,7 +503,7 @@ public function getIdsMatchingTags($tags = array())
496503
public function getIdsNotMatchingTags($tags = array())
497504
{
498505
if (! $this->_notMatchingTags) {
499-
Zend_Cache::throwException("notMatchingTags is currently disabled.");
506+
Cache::throwException("notMatchingTags is currently disabled.");
500507
}
501508
return (array) $this->_redisVariadic('sDiff', self::SET_IDS, $this->_preprocessTagIds($tags));
502509
}
@@ -547,7 +554,7 @@ public function getMetadatas($id)
547554

548555
return array(
549556
'expire' => time() + $ttl,
550-
'tags' => $tags,
557+
'tags' => $tags,
551558
'mtime' => $mtime,
552559
);
553560
}

src/php/Chaplin/Cache/Abstract.php renamed to src/php/Chaplin/Cache/CacheAbstract.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
abstract class Chaplin_Cache_Abstract
25+
namespace Chaplin\Cache;
26+
27+
use Zend_Cache_Core as ZendCache;
28+
29+
abstract class CacheAbstract
2630
{
2731
private $_zendCache;
28-
29-
public function setCache(Zend_Cache_Core $zendCache = null)
32+
33+
public function setCache(ZendCache $zendCache = null)
3034
{
3135
$this->_zendCache = $zendCache;
3236
}

src/php/Chaplin/Cache/Http/Client.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25-
class Chaplin_Cache_Http_Client
26-
extends Chaplin_Cache_Abstract
27-
implements Chaplin_Http_Interface
25+
26+
namespace Chaplin\Cache\Http;
27+
28+
use Chaplin\Cache\CacheAbstract;
29+
use Chaplin_Http_Interface as HttpInterface;
30+
use Chaplin_Log as Log;
31+
use Zend_Cache_Core as Cache;
32+
use Zend_Log as ZendLog;
33+
34+
class Client extends CacheAbstract implements HttpInterface
2835
{
2936
private $_objHttpClient;
3037

31-
public function __construct(Chaplin_Http_Interface $objHttpClient, Zend_Cache_Core $cacheHttpClient = null)
38+
public function __construct(HttpInterface $objHttpClient, Cache $cacheHttpClient = null)
3239
{
3340
$this->_objHttpClient = $objHttpClient;
3441
$this->setCache($cacheHttpClient);
3542
}
36-
37-
public function getPageBody($strURL, $intLogPriority = Zend_Log::ERR)
43+
44+
public function getPageBody($strURL, $intLogPriority = ZendLog::ERR)
3845
{
3946
$cacheKey = $this->_getCacheKey(__METHOD__, $strURL);
4047
if (false === ($response = $this->_cacheLoadKey($cacheKey))) {
@@ -44,7 +51,7 @@ public function getPageBody($strURL, $intLogPriority = Zend_Log::ERR)
4451
return $response;
4552
}
4653

47-
public function getObject($strURL, $intLogPriority = Zend_Log::ERR)
54+
public function getObject($strURL, $intLogPriority = ZendLog::ERR)
4855
{
4956
$cacheKey = $this->_getCacheKey(__METHOD__, $strURL);
5057
if (false === ($response = $this->_cacheLoadKey($cacheKey))) {
@@ -53,7 +60,7 @@ public function getObject($strURL, $intLogPriority = Zend_Log::ERR)
5360
}
5461
return $response;
5562
}
56-
63+
5764
public function scrapeXPath($strURL, $strXPath)
5865
{
5966
$cacheKey = $this->_getCacheKey(__METHOD__, $strURL . 'X' . $strXPath);
@@ -64,24 +71,24 @@ public function scrapeXPath($strURL, $strXPath)
6471
return $response;
6572
}
6673

67-
public function getHttpResponse($strURL, $intLogPriority = Zend_Log::ERR, $bCache = true)
74+
public function getHttpResponse($strURL, $intLogPriority = ZendLog::ERR, $bCache = true)
6875
{
6976
if(!$bCache) {
7077
return $this->_objHttpClient->getHttpResponse($strURL, $intLogPriority);
7178
}
72-
73-
Chaplin_Log::getInstance()->log('Cache: trying to load ('.$strURL.')', $intLogPriority);
79+
80+
Log::getInstance()->log('Cache: trying to load ('.$strURL.')', $intLogPriority);
7481
$cacheKey = $this->_getCacheKey(__METHOD__, $strURL);
7582
if (false === ($response = $this->_cacheLoadKey($cacheKey))) {
7683
$response = $this->_objHttpClient->getHttpResponse($strURL, $intLogPriority);
7784
if(200 == $response->getStatus()) {
7885
$this->_cacheSaveKey($cacheKey, $response);
7986
}
8087
}
81-
Chaplin_Log::getInstance()->log('Cache: retrieved ('.$response->getBody().')', $intLogPriority);
88+
Log::getInstance()->log('Cache: retrieved ('.$response->getBody().')', $intLogPriority);
8289
return $response;
8390
}
84-
91+
8592
public function parseRawXPath($strData, $strXPath)
8693
{
8794
return $this->_objHttpClient->parseRawXPath($strData, $strXPath);

src/php/Chaplin/Controller/Plugin/Acl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25+
use Chaplin\Auth;
26+
2527
class Chaplin_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
2628
{
2729
private $_acl;
@@ -57,7 +59,7 @@ public function preDispatch(Zend_Controller_Request_Abstract $request)
5759
$strController = $request->getControllerName();
5860
$strAction = $request->getActionName();
5961

60-
$auth = Chaplin_Auth::getInstance();
62+
$auth = Auth::getInstance();
6163
$resource = $strModule.'/'.$strController;
6264
$role = $auth->hasIdentity() ?
6365
$auth->getIdentity()->getUser()->getUserType()->getUserType():

src/php/Chaplin/Model/Video.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @version GIT: $Id$
2323
* @link https://github.com/danwdart/projectchaplin
2424
**/
25+
use Chaplin\Auth;
2526
use Misd\Linkify\Linkify;
2627

2728
class Chaplin_Model_Video extends Chaplin_Model_Field_Hash
@@ -277,14 +278,14 @@ public function getYourVote()
277278

278279
public function isMine()
279280
{
280-
if (!Chaplin_Auth::getInstance()->hasIdentity()) {
281+
if (!Auth::getInstance()->hasIdentity()) {
281282
return false;
282283
}
283-
if (Chaplin_Auth::getInstance()->getIdentity()->getUser()->isGod()) {
284+
if (Auth::getInstance()->getIdentity()->getUser()->isGod()) {
284285
// God users own everything, mwuhahaha
285286
return true;
286287
}
287-
return Chaplin_Auth::getInstance()
288+
return Auth::getInstance()
288289
->getIdentity()
289290
->getUser()
290291
->getUsername() ==

0 commit comments

Comments
 (0)