Skip to content

Commit

Permalink
Refs #3741 Resuming PHP Namespaces conversion of Piwik core, mostly f…
Browse files Browse the repository at this point in the history
…inished core/ conversion
  • Loading branch information
mattab committed Jul 30, 2013
1 parent 5104d94 commit 765be0d
Show file tree
Hide file tree
Showing 150 changed files with 382 additions and 559 deletions.
9 changes: 4 additions & 5 deletions core/API/DocumentationGenerator.php
Expand Up @@ -14,8 +14,7 @@
use Piwik\Piwik;
use Piwik\Common;
use Piwik\API\Proxy;
use Piwik_API_Proxy_NoDefaultValue;
use Piwik_Url;
use Piwik\Url;

/**
* @package Piwik
Expand Down Expand Up @@ -203,11 +202,11 @@ public function getExampleUrl($class, $methodName, $parametersToSet = array())
$defaultValue = $knowExampleDefaultParametersValues[$nameVariable];
} // if there isn't a default value for a given parameter,
// we need a 'know default value' or we can't generate the link
elseif ($defaultValue instanceof Piwik_API_Proxy_NoDefaultValue) {
elseif ($defaultValue instanceof NoDefaultValue) {
return false;
}
}
return '?' . Piwik_Url::getQueryStringFromParameters($aParameters);
return '?' . Url::getQueryStringFromParameters($aParameters);
}

/**
Expand All @@ -228,7 +227,7 @@ public function getParametersString($class, $name)
continue;
}
$str = $nameVariable;
if (!($defaultValue instanceof Piwik_API_Proxy_NoDefaultValue)) {
if (!($defaultValue instanceof NoDefaultValue)) {
if (is_array($defaultValue)) {
$str .= " = 'Array'";
} else {
Expand Down
16 changes: 8 additions & 8 deletions core/API/Proxy.php
Expand Up @@ -50,7 +50,7 @@ class Proxy
*/
protected function __construct()
{
$this->noDefaultValue = new Piwik_API_Proxy_NoDefaultValue();
$this->noDefaultValue = new NoDefaultValue();
}

/**
Expand All @@ -60,10 +60,10 @@ protected function __construct()
*/
static public function getInstance()
{
if (\Piwik\API\self::$instance == null) {
\Piwik\API\self::$instance = new \Piwik\API\self;
if (self::$instance == null) {
self::$instance = new self;
}
return \Piwik\API\self::$instance;
return self::$instance;
}

/**
Expand Down Expand Up @@ -203,7 +203,7 @@ public function call($className, $methodName, $parametersRequest)

// log the API Call
try {
Zend_Registry::get('logger_api_call')->logEvent(
\Zend_Registry::get('logger_api_call')->logEvent(
$className,
$methodName,
$parameterNamesDefaultValues,
Expand Down Expand Up @@ -277,7 +277,7 @@ private function getRequestParametersArray($requiredParameters, $parametersReque
$finalParameters = array();
foreach ($requiredParameters as $name => $defaultValue) {
try {
if ($defaultValue instanceof Piwik_API_Proxy_NoDefaultValue) {
if ($defaultValue instanceof NoDefaultValue) {
$requestValue = Common::getRequestVar($name, null, null, $parametersRequest);
} else {
try {
Expand Down Expand Up @@ -315,7 +315,7 @@ private function getRequestParametersArray($requiredParameters, $parametersReque
*/
private function includeApiFile($fileName)
{
$module = \Piwik\API\self::getModuleNameFromClassName($fileName);
$module = self::getModuleNameFromClassName($fileName);
$path = PIWIK_INCLUDE_PATH . '/plugins/' . $module . '/API.php';

if (is_readable($path)) {
Expand Down Expand Up @@ -414,6 +414,6 @@ private function checkClassIsSingleton($className)
* @package Piwik
* @subpackage Piwik_API
*/
class Piwik_API_Proxy_NoDefaultValue
class NoDefaultValue
{
}
1 change: 1 addition & 0 deletions core/Access.php
Expand Up @@ -13,6 +13,7 @@
use Piwik\Config;
use Piwik\Common;
use Piwik\Auth;
use Piwik\Db;

/**
* Class to handle User Access:
Expand Down
2 changes: 1 addition & 1 deletion core/Archive.php
Expand Up @@ -456,7 +456,7 @@ private function cacheArchiveIdsAfterLaunching($archiveGroups, $plugins)
continue;
}

// if the starting date is in the future we know there is no visit
// if the starting date is in the future we know there is no visiidsite = ?t
if ($twoDaysBeforePeriod->isLater($today)) {
$archiveDesc = $this->getArchiveDescriptor($idSite, $period);
Piwik::log("Archive $archiveDesc skipped, archive is after today.");
Expand Down
2 changes: 1 addition & 1 deletion core/Controller.php
Expand Up @@ -680,7 +680,7 @@ public function redirectToIndex($moduleToRedirect, $actionToRedirect, $websiteId
&& $currentLogin != 'anonymous'
) {
$errorMessage = sprintf(Piwik_Translate('CoreHome_NoPrivilegesAskPiwikAdmin'), $currentLogin, "<br/><a href='mailto:" . Piwik::getSuperUserEmail() . "?subject=Access to Piwik for user $currentLogin'>", "</a>");
$errorMessage .= "<br /><br />&nbsp;&nbsp;&nbsp;<b><a href='index.php?module=" . Zend_Registry::get('auth')->getName() . "&amp;action=logout'>&rsaquo; " . Piwik_Translate('General_Logout') . "</a></b><br />";
$errorMessage .= "<br /><br />&nbsp;&nbsp;&nbsp;<b><a href='index.php?module=" . \Zend_Registry::get('auth')->getName() . "&amp;action=logout'>&rsaquo; " . Piwik_Translate('General_Logout') . "</a></b><br />";
Piwik_ExitWithMessage($errorMessage, false, true);
}

Expand Down
1 change: 1 addition & 0 deletions core/DataAccess/ArchiveSelector.php
Expand Up @@ -21,6 +21,7 @@
use Piwik\Segment;
use Piwik\Site;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Db;

/**
* Data Access object used to query archives
Expand Down
2 changes: 1 addition & 1 deletion core/DataAccess/ArchiveTableCreator.php
Expand Up @@ -51,7 +51,7 @@ static protected function createArchiveTablesIfAbsent($tableName, $tableNamePref
}

if (!in_array($tableName, self::$tablesAlreadyInstalled)) {
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$sql = Piwik::getTableCreateSql($tableNamePrefix);

// replace table name template by real name
Expand Down
2 changes: 1 addition & 1 deletion core/DataAccess/LogAggregator.php
Expand Up @@ -511,6 +511,6 @@ static public function makeArrayOneColumn($row, $columnName, $lookForThisPrefix

public function getDb()
{
return Zend_Registry::get('db');
return \Zend_Registry::get('db');
}
}
14 changes: 7 additions & 7 deletions core/Db.php
Expand Up @@ -31,7 +31,7 @@ static private function getDb()
$db = Tracker::getDatabase();
}
if ($db === null) {
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
}
return $db;
}
Expand All @@ -42,13 +42,13 @@ static private function getDb()
* If you want to fetch data from the DB you should use the function Db::fetchAll()
*
* @param string $sql SQL Query
* @return integer|Zend_Db_Statement
* @return integer|\Zend_Db_Statement
*/
static public function exec($sql)
{
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$profiler = $db->getProfiler();
$q = $profiler->queryStart($sql, Zend_Db_Profiler::INSERT);
$q = $profiler->queryStart($sql, \Zend_Db_Profiler::INSERT);
$return = self::getDb()->exec($sql);
$profiler->queryEnd($q);
return $return;
Expand Down Expand Up @@ -315,7 +315,7 @@ static public function segmentedFetchOne($sql, $first, $last, $step, $params = a
*
* @return array
*/
static public function segmentedFetchAll($sql, $first, $last, $step, $params)
static public function segmentedFetchAll($sql, $first, $last, $step, $params = array())
{
$result = array();
if ($step > 0) {
Expand Down Expand Up @@ -378,7 +378,7 @@ static public function getDbLock($lockName, $maxRetries = 30)
*/
$sql = 'SELECT GET_LOCK(?, 1)';

$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');

while ($maxRetries > 0) {
if ($db->fetchOne($sql, array($lockName)) == '1') {
Expand All @@ -399,7 +399,7 @@ static public function releaseDbLock($lockName)
{
$sql = 'SELECT RELEASE_LOCK(?)';

$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
return $db->fetchOne($sql, array($lockName)) == '1';
}
}
2 changes: 1 addition & 1 deletion core/Db/Adapter.php
Expand Up @@ -75,7 +75,7 @@ public static function factory($adapterName, & $dbInfos, $connect = true)
*/
private static function getAdapterClassName($adapterName)
{
return 'Piwik_Db_Adapter_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($adapterName))));
return 'Piwik\Db\Adapter\\' . str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($adapterName))));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/Db/Adapter/Pdo/Mssql.php
Expand Up @@ -14,7 +14,7 @@
use PDO;
use PDOException;
use Piwik\Config;
use Piwik\Db\Adapter\AdapterInterface;
use Piwik\Db\AdapterInterface;
use Zend_Db;
use Zend_Db_Adapter_Exception;
use Zend_Db_Adapter_Pdo_Mssql;
Expand Down
2 changes: 1 addition & 1 deletion core/Db/Adapter/Pdo/Mysql.php
Expand Up @@ -14,7 +14,7 @@
use PDO;
use PDOException;
use Piwik\Config;
use Piwik\Db\Adapter\AdapterInterface;
use Piwik\Db\AdapterInterface;
use Zend_Config;
use Zend_Db_Adapter_Pdo_Mysql;
use Zend_Db_Select;
Expand Down
2 changes: 1 addition & 1 deletion core/Db/Adapter/Pdo/Pgsql.php
Expand Up @@ -14,7 +14,7 @@
use PDO;
use PDOException;
use Piwik\Config;
use Piwik\Db\Adapter\AdapterInterface;
use Piwik\Db\AdapterInterface;
use Zend_Db_Adapter_Pdo_Pgsql;

/**
Expand Down
5 changes: 2 additions & 3 deletions core/Db/Schema.php
Expand Up @@ -11,7 +11,6 @@
namespace Piwik\Db;

use Piwik\Config;
use Piwik\Db\Schema\SchemaInterface;

/**
* Schema abstraction
Expand Down Expand Up @@ -58,7 +57,7 @@ static public function getInstance()
*/
private static function getSchemaClassName($schemaName)
{
return 'Piwik_Db_Schema_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', strtolower($schemaName))));
return '\Piwik\Db\Schema\\' . str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($schemaName))));
}

/**
Expand Down Expand Up @@ -150,7 +149,7 @@ private function loadSchema()
/**
* Returns an instance that subclasses Schema
*
* @return \Piwik\Db\Schema\SchemaInterface
* @return \Piwik\Db\SchemaInterface
*/
private function getSchema()
{
Expand Down
14 changes: 8 additions & 6 deletions core/Db/Schema/Myisam.php
Expand Up @@ -12,12 +12,14 @@

use Exception;
use Piwik\Config;
use Piwik\Db\Schema\SchemaInterface;
use Piwik\Db\SchemaInterface;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Date;
use Piwik\Db;
use Zend_Registry;


/**
* MySQL schema
*
Expand All @@ -34,7 +36,7 @@ class Myisam implements SchemaInterface
*/
static private function hasStorageEngine($engineName)
{
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$allEngines = $db->fetchAssoc('SHOW ENGINES');
if (array_key_exists($engineName, $allEngines)) {
$support = $allEngines[$engineName]['Support'];
Expand Down Expand Up @@ -452,7 +454,7 @@ public function getTablesInstalled($forceReload = true)
if (is_null($this->tablesInstalled)
|| $forceReload === true
) {
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$config = Config::getInstance();
$prefixTables = $config->database['tables_prefix'];

Expand Down Expand Up @@ -515,7 +517,7 @@ public function dropDatabase()
*/
public function createTables()
{
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$config = Config::getInstance();
$prefixTables = $config->database['tables_prefix'];

Expand All @@ -539,7 +541,7 @@ public function createAnonymousUser()
{
// The anonymous user is the user that is assigned by default
// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');
$db->query("INSERT INTO " . Common::prefixTable("user") . "
VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', 'anonymous', '" . Date::factory('now')->getDatetime() . "' );");
}
Expand All @@ -563,7 +565,7 @@ public function truncateAllTables()
public function dropTables($doNotDelete = array())
{
$tablesAlreadyInstalled = $this->getTablesInstalled();
$db = Zend_Registry::get('db');
$db = \Zend_Registry::get('db');

$doNotDeletePattern = '/(' . implode('|', $doNotDelete) . ')/';

Expand Down
2 changes: 1 addition & 1 deletion core/ErrorHandler.php
Expand Up @@ -47,7 +47,7 @@ function Piwik_ErrorHandler($errno, $errstr, $errfile, $errline)
}

try {
Zend_Registry::get('logger_error')->logEvent($errno, $errstr, $errfile, $errline, $backtrace);
\Zend_Registry::get('logger_error')->logEvent($errno, $errstr, $errfile, $errline, $backtrace);
} catch (Exception $e) {
// in case the error occurs before the logger creation, we simply display it
print("<pre>$errstr \nin '$errfile' at the line $errline\n\n$backtrace\n</pre>");
Expand Down
5 changes: 3 additions & 2 deletions core/ExceptionHandler.php
Expand Up @@ -9,6 +9,7 @@
* @package Piwik
*/
use Piwik\Piwik;
use Piwik\Log;
use Piwik\FrontController;

/**
Expand All @@ -20,7 +21,7 @@
function Piwik_ExceptionHandler(Exception $exception)
{
try {
Zend_Registry::get('logger_exception')->logEvent($exception);
\Zend_Registry::get('logger_exception')->logEvent($exception);
} catch (Exception $e) {

if (FrontController::shouldRethrowException()) {
Expand All @@ -36,7 +37,7 @@ function Piwik_ExceptionHandler(Exception $exception)
$event['errline'] = $exception->getLine();
$event['backtrace'] = $exception->getTraceAsString();

$formatter = new Piwik_Log_Exception_Formatter_ScreenFormatter();
$formatter = new ExceptionScreenFormatter();

$message = $formatter->format($event);
$message .= "<br /><br />And this exception raised another exception \"" . $e->getMessage() . "\"";
Expand Down
4 changes: 2 additions & 2 deletions core/FrontController.php
Expand Up @@ -218,7 +218,7 @@ public function init()
$initialized = true;

try {
Zend_Registry::set('timer', new Timer);
\Zend_Registry::set('timer', new Timer);

$directoriesToCheck = array(
'/tmp/',
Expand Down Expand Up @@ -277,7 +277,7 @@ public function init()

Piwik_PostEvent('FrontController.initAuthenticationObject');
try {
$authAdapter = Zend_Registry::get('auth');
$authAdapter = \Zend_Registry::get('auth');
} catch (Exception $e) {
throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?
<br />You can activate the plugin by adding:<br />
Expand Down

0 comments on commit 765be0d

Please sign in to comment.