Skip to content

Commit

Permalink
Merge pull request #331 from perftools/psr-4
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Sep 22, 2020
2 parents 2402fb8 + 6a604f5 commit 6f9376f
Show file tree
Hide file tree
Showing 35 changed files with 265 additions and 147 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "A web based interface for viewing profile data collected by XHProf",
"license": "MIT",
"autoload": {
"psr-0": {
"Xhgui_": "src/"
"psr-4": {
"XHGui\\": "src/Xhgui/"
}
},
"autoload-dev": {
Expand Down
8 changes: 6 additions & 2 deletions external/import.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

use XHGui\Saver\SaverInterface;
use XHGui\ServiceContainer;

if (!defined('XHGUI_ROOT_DIR')) {
require dirname(__DIR__) . '/src/bootstrap.php';
}
Expand All @@ -20,8 +24,8 @@
throw new RuntimeException('Can\'t open '.$file);
}

$container = Xhgui_ServiceContainer::instance();
/** @var Xhgui_Saver_Interface $saver */
$container = ServiceContainer::instance();
/** @var SaverInterface $saver */
$saver = $container['saver'];

while (!feof($fp)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace XHGui;

use Slim\Slim;

abstract class Xhgui_Controller
abstract class AbstractController
{
/**
* @var array
Expand Down
5 changes: 4 additions & 1 deletion src/Xhgui/Config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace XHGui;

/**
* Loads and reads config file.
*/
class Xhgui_Config
class Config
{
private static $config = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

namespace XHGui\Controller;

use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;

class Xhgui_Controller_Custom extends Xhgui_Controller
class CustomController extends AbstractController
{
/**
* @var Xhgui_Searcher_Interface
* @var SearcherInterface
*/
protected $searcher;

public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
public function __construct(Slim $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<?php

namespace XHGui\Controller;

use Exception;
use InvalidArgumentException;
use Slim\Http\Request;
use Slim\Slim;
use XHGui\Saver\SaverInterface;
use XHGui\AbstractController;

class Xhgui_Controller_Import extends Xhgui_Controller
class ImportController extends AbstractController
{
/**
* @var Xhgui_Saver_Interface
* @var SaverInterface
*/
private $saver;

/** @var string */
private $token;

public function __construct(Slim $app, Xhgui_Saver_Interface $saver, $token)
public function __construct(Slim $app, SaverInterface $saver, $token)
{
parent::__construct($app);
$this->saver = $saver;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

namespace XHGui\Controller;

use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;

class Xhgui_Controller_Metrics extends Xhgui_Controller
class MetricsController extends AbstractController
{
/**
* @var Xhgui_Searcher_Interface
* @var SearcherInterface
*/
protected $searcher;

public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
public function __construct(Slim $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?php

namespace XHGui\Controller;

use Exception;
use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;

class Xhgui_Controller_Run extends Xhgui_Controller
class RunController extends AbstractController
{
/**
* HTTP GET attribute name for comma separated filters
*/
const FILTER_ARGUMENT_NAME = 'filter';

/**
* @var Xhgui_Searcher_Interface
* @var SearcherInterface
*/
private $searcher;

public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
public function __construct(Slim $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

namespace XHGui\Controller;

use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;

class Xhgui_Controller_Watch extends Xhgui_Controller
class WatchController extends AbstractController
{
/**
* @var Xhgui_Searcher_Interface
* @var SearcherInterface
*/
protected $searcher;

public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
public function __construct(Slim $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php

namespace XHGui\Controller;

use Slim\Slim;
use XHGui\Searcher\SearcherInterface;
use XHGui\AbstractController;
use XHGui\Profile;

class Xhgui_Controller_Waterfall extends Xhgui_Controller
class WaterfallController extends AbstractController
{
/**
* @var Xhgui_Searcher_Interface
* @var SearcherInterface
*/
protected $searcher;

public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
public function __construct(Slim $app, SearcherInterface $searcher)
{
parent::__construct($app);
$this->searcher = $searcher;
Expand Down Expand Up @@ -64,7 +69,7 @@ public function query()
'projection' => true,
]);
$datas = [];
/** @var Xhgui_Profile $r */
/** @var Profile $r */
foreach ($result['results'] as $r) {
$duration = $r->get('main()', 'wt');
$start = $r->getMeta('SERVER.REQUEST_TIME_FLOAT');
Expand Down
9 changes: 8 additions & 1 deletion src/Xhgui/Db/Mapper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

class Xhgui_Db_Mapper
namespace XHGui\Db;

use DateInterval;
use DateTime;
use MongoDate;

class Mapper
{
/**
* Convert request data keys into mongo values.
Expand Down Expand Up @@ -117,6 +123,7 @@ protected function _direction($options)

return 'desc';
}

/**
* Get sort options for a paginated set.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

namespace XHGui\Middleware;

use Slim\Middleware;

class Xhgui_Middleware_Render extends Middleware
class RenderMiddleware extends Middleware
{
public function call()
{
Expand Down
16 changes: 11 additions & 5 deletions src/Xhgui/Profile.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

namespace XHGui;

use DateTime;
use Exception;

/**
* Domain object for handling profile runs.
*
* Provides method to manipulate the data from a single profile run.
*/
class Xhgui_Profile
class Profile
{
/**
* @const Key used for methods with no parent
Expand Down Expand Up @@ -369,7 +375,7 @@ public function extractDimension($dimension, $limit)
* Notes:
* Function names are not unique, but we're merging them
*
* @return Xhgui_Profile A new instance with exclusive data set.
* @return Profile A new instance with exclusive data set.
*/
public function calculateSelf()
{
Expand Down Expand Up @@ -431,7 +437,7 @@ public function filter($profileData, $filters = [])
foreach ($filters as $key => $item) {
foreach ($profileData as $keyItem => $method) {
if (fnmatch($item, $keyItem)) {
unset($profileData[ $keyItem ]);
unset($profileData[$keyItem]);
}
}
}
Expand Down Expand Up @@ -478,10 +484,10 @@ public function getFunctionCount()
/**
* Compare this run to another run.
*
* @param Xhgui_Profile $head The other run to compare with
* @param Profile $head The other run to compare with
* @return array An array of comparison data.
*/
public function compare(Xhgui_Profile $head)
public function compare(Profile $head)
{
$this->calculateSelf();
$head->calculateSelf();
Expand Down
8 changes: 7 additions & 1 deletion src/Xhgui/Saver/Mongo.php → src/Xhgui/Saver/MongoSaver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

class Xhgui_Saver_Mongo implements Xhgui_Saver_Interface
namespace XHGui\Saver;

use MongoCollection;
use MongoDate;
use MongoId;

class MongoSaver implements SaverInterface
{
/**
* @var MongoCollection
Expand Down
12 changes: 9 additions & 3 deletions src/Xhgui/Saver/Pdo.php → src/Xhgui/Saver/PdoSaver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

class Xhgui_Saver_Pdo implements Xhgui_Saver_Interface
namespace XHGui\Saver;

use PDO;
use PDOStatement;
use XHGui\Util;

class PdoSaver implements SaverInterface
{
const TABLE_DDL = <<<SQL
Expand Down Expand Up @@ -68,7 +74,7 @@ class Xhgui_Saver_Pdo implements Xhgui_Saver_Interface
private $stmt;

/**
* @param PDO $pdo
* @param PDO $pdo
* @param string $table
*/
public function __construct(PDO $pdo, $table)
Expand All @@ -88,7 +94,7 @@ public function save(array $data)
$usec = $ts['usec'];

$this->stmt->execute([
'id' => Xhgui_Util::generateId(),
'id' => Util::generateId(),
'profile' => json_encode($data['profile']),
'url' => $data['meta']['url'],
'SERVER' => json_encode($data['meta']['SERVER']),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

interface Xhgui_Saver_Interface
namespace XHGui\Saver;

interface SaverInterface
{
public function save(array $data);
}
Loading

0 comments on commit 6f9376f

Please sign in to comment.