Skip to content

Commit b8dfbe4

Browse files
committed
Creating Tag v6.0.0-RC1 at 2020-01-07 - ignoring test folder for packagist distro
1 parent bf0e617 commit b8dfbe4

8 files changed

+196
-154
lines changed

.php_cs.cache

+1-1
Large diffs are not rendered by default.

README.md

+21-18
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ PHP Based administration tool for PostgreSQL. Blazing fast routing with [Slim Fr
1111

1212
This is a hard fork of [phppgadmin](https://github.com/phppgadmin/phppgadmin) which adds the following enhancements:
1313

14-
- Composer Installation and dependency management
15-
- Autoloading (thanks to the above)
16-
- Namespaced classes
17-
- Removal of global variables
18-
- Full PHP 7+ support
19-
- Support for PG 9.3+ features (Materialized Views, BRIN Indexes, etc)
20-
- Nice urls
14+
- Composer Installation and dependency management
15+
- [PSR-2 Coding Standard](https://www.php-fig.org/psr/psr-2) (Will evolve to PSR-12 soon)
16+
- [PSR-4 Autoloading](https://www.php-fig.org/psr/psr-4)
17+
- Removal of global variables (WIP)
18+
- Removal of superglobals in favour of [PSR-7 Message interfaces](http://www.php-fig.org/psr/psr-7/) (WIP)
19+
- Full PHP 7+ support
20+
- Usage of Dependency Injection compliant with [PSR-11 Container interface](http://www.php-fig.org/psr/psr-11/)
21+
- Support for PG 9.3+ features (Materialized Views, BRIN Indexes, etc)
22+
- Nice urls
2123

2224
### WIP
2325

2426
Other enhancements are in progress and would be a nice to have:
2527

26-
- Replace usage of superglobals with [PSR-7 Message interfaces](http://www.php-fig.org/psr/psr-7/) to carry information around.
27-
- Usage of Dependency Injection compliant with [PSR-11 Container interface](http://www.php-fig.org/psr/psr-11/)
28+
## Requirements
2829

29-
This project is made on top of [Slim Framework 3](https://www.slimframework.com/) and communicates with the Database using [AdoDB](https://adodb.org/)
30+
- PHP 5.6+ (but you should really, really consider switching to at least v7.1)
31+
- ext-psql
32+
- [Composer](https://getcomposer.org/download/)
3033

3134
## Installation
3235

@@ -51,7 +54,7 @@ composer install --no-dev
5154
If there's something broken and I cannot risk breaking the rest to fix your issue, I might push a fix or feature to [develop branch](https://github.com/HuasoFoundries/phpPgAdmin6/tree/develop). Said branch can be installed as
5255

5356
```sh
54-
composer create-project huasofoundries/phppgadmin6 <FOLDER> *@beta --no-dev --prefer-dist
57+
composer create-project huasofoundries/phppgadmin6 <FOLDER> v6.*.*@beta --no-dev --prefer-dist
5558
```
5659

5760
(or, you know, clone the repo and make sure you're in develop branch)
@@ -134,12 +137,12 @@ You can choose between one of them if you use this work.
134137
We're preserving due credits to all people that contributed in the past, as well as other release notes
135138
contained in the old version of [phppgadmin](https://github.com/phppgadmin/phppgadmin)
136139

137-
- [Bugs](docs/BUGS.md)
138-
- [Changelog](docs/CHANGELOG.md) (_outdated_)
139-
- [Credits](docs/CREDITS.md)
140-
- [Developers](docs/DEVELOPERS.md)
141-
- [FAQ](docs/FAQ.md) (_outdated_)
142-
- [History](docs/HISTORY.md) (_outdated_)
143-
- [Translators](docs/TRANSLATORS.md)
140+
- [Bugs](docs/BUGS.md)
141+
- [Changelog](docs/CHANGELOG.md) (_outdated_)
142+
- [Credits](docs/CREDITS.md)
143+
- [Developers](docs/DEVELOPERS.md)
144+
- [FAQ](docs/FAQ.md) (_outdated_)
145+
- [History](docs/HISTORY.md) (_outdated_)
146+
- [Translators](docs/TRANSLATORS.md)
144147

145148
Kudos to all people that helped build the original project, upon which this one was built.

config.inc.php-dist

+10-11
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,39 @@
99

1010

1111

12-
// Set this to true to enable debug features
13-
$conf['debugmode'] = false;
14-
1512
// Enable this to debug on console using
1613
// https://github.com/barbushin/php-console
1714
// (Only in Chrome)
1815
$conf['php_console'] = true;
1916

2017
$conf['debugmode'] = true;
21-
2218
if ($conf['php_console'] === true &&
2319
// PHP_CONSOLE doesn't work on PHP 7.4 yet
2420
version_compare(PHP_VERSION, 7.4, '<') &&
25-
isset($_SERVER['HTTP_USER_AGENT']) &&
26-
stripos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false) {
21+
class_exists('PhpConsole\Handler')) {
2722

28-
$handler = PhpConsole\Handler::getInstance();
23+
$phpConsoleHandler = PhpConsole\Handler::getInstance();
2924

25+
/* Get the reference to the connector instance
26+
$connector=$phpConsoleHandler->getConnector();
27+
*/
3028
/* Set a password for PHPConsole Connector
31-
$connector=$handler->getConnector();
29+
$connector->setPassword('yohoho123', true);
3230
*/
3331

3432
/* enable in SSL mode only
3533
$connector->enableSslOnlyMode();
3634
*/
3735

3836
/* Override default Handler behavior:
39-
$handler->setHandleErrors(false); // disable errors handling
40-
$handler->setHandleExceptions(false); // disable exceptions handling
41-
$handler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers
37+
$phpConsoleHandler->setHandleErrors(false); // disable errors handling
38+
$phpConsoleHandler->setHandleExceptions(false); // disable exceptions handling
39+
$phpConsoleHandler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers
4240
*/
4341

4442
}
4543

44+
4645
// optionally, set a path for your error log, relative to this project root
4746
// $conf['error_log']='temp/phppga.php_error.log';
4847

index.php

+31-37
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,39 @@
44
* PHPPgAdmin v6.0.0-RC1
55
*/
66

7-
require_once __DIR__ . '/src/lib.inc.php';
7+
require_once __DIR__.'/src/lib.inc.php';
88

99
// This section is made to be able to parse requests coming from PHP Builtin webserver
1010
if (PHP_SAPI === 'cli-server') {
11-
//include_once __DIR__ . '/src/cli.router.php';
1211
$will_redirect = false;
13-
$req_uri = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
14-
$first10chars = substr($req_uri, 0, 10);
15-
if ($first10chars === '/index.php') {
12+
// @todo is PHP_SELF is not set, chances are REQUEST_URI won't either
13+
$req_uri = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
14+
if (substr($req_uri, 0, 10) === '/index.php') {
1615
$will_redirect = true;
1716
$req_uri = substr($req_uri, 10);
1817
}
1918
$filePath = realpath(ltrim($req_uri, '/'));
20-
$new_location = 'Location: http://' . $_SERVER['HTTP_HOST'] . $req_uri;
21-
22-
if ($filePath && is_readable($filePath)) {
23-
// 1. check that file is not outside of this directory for security
24-
// 2. check for circular reference to router.php
25-
// 3. don't serve dotfiles
26-
27-
if (strpos($filePath, BASE_PATH . DIRECTORY_SEPARATOR) === 0 &&
28-
$filePath != BASE_PATH . DIRECTORY_SEPARATOR . 'index.php' &&
29-
substr(basename($filePath), 0, 1) != '.'
30-
) {
31-
if (strtolower(substr($filePath, -4)) == '.php') {
32-
// php file; serve through interpreter
33-
include $filePath;
34-
35-
return;
36-
}
37-
if ($will_redirect) {
38-
header($new_location, true, 301);
39-
40-
return;
41-
}
42-
// asset file; serve from filesystem
43-
return false;
19+
$new_location = 'Location: http://'.$_SERVER['HTTP_HOST'].$req_uri;
20+
21+
if ($filePath && // 1. check that filepath is set
22+
is_readable($filePath) && // 2. and references a readable file/folder
23+
strpos($filePath, BASE_PATH.DIRECTORY_SEPARATOR) === 0 && // 3. And is inside this folder
24+
$filePath != BASE_PATH.DIRECTORY_SEPARATOR.'index.php' && // 4. discard circular references to index.php
25+
substr(basename($filePath), 0, 1) != '.' // 5. don't serve dotfiles
26+
) {
27+
if (strtolower(substr($filePath, -4)) == '.php') {
28+
// php file; serve through interpreter
29+
include $filePath;
30+
31+
return;
4432
}
33+
if ($will_redirect) {
34+
header($new_location, true, 301);
35+
36+
return;
37+
}
38+
// asset file; serve from filesystem
39+
return false;
4540
}
4641
}
4742

@@ -53,7 +48,6 @@
5348
/* @scrutinizer ignore-unused */
5449
$args
5550
) {
56-
5751
return $response
5852
->withHeader('Content-type', 'application/json')
5953
->withJson(['version' => $this->version]);
@@ -73,7 +67,7 @@
7367
$loginShared = $request->getParsedBodyParam('loginShared');
7468
$loginServer = $request->getParsedBodyParam('loginServer');
7569
$loginUsername = $request->getParsedBodyParam('loginUsername');
76-
$loginPassword = $request->getParsedBodyParam('loginPassword_' . md5($loginServer));
70+
$loginPassword = $request->getParsedBodyParam('loginPassword_'.md5($loginServer));
7771

7872
// If login action is set, then set session variables
7973
if ((bool) $loginServer && (bool) $loginUsername && $loginPassword !== null) {
@@ -146,16 +140,16 @@
146140
$safe_subjects = ($subject === 'servers' || $subject === 'intro' || $subject === 'browser');
147141

148142
if ($this->misc->getServerId() === null && !$safe_subjects) {
149-
return $response->withStatus(302)->withHeader('Location', SUBFOLDER . '/src/views/servers');
143+
return $response->withStatus(302)->withHeader('Location', SUBFOLDER.'/src/views/servers');
150144
}
151145

152146
if (!isset($_server_info['username']) && $subject !== 'login' && !$safe_subjects) {
153-
$destinationurl = SUBFOLDER . '/src/views/login?server=' . $this->misc->getServerId();
147+
$destinationurl = SUBFOLDER.'/src/views/login?server='.$this->misc->getServerId();
154148

155149
return $response->withStatus(302)->withHeader('Location', $destinationurl);
156150
}
157151

158-
$className = '\PHPPgAdmin\Controller\\' . ucfirst($subject) . 'Controller';
152+
$className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller';
159153
$controller = new $className($this);
160154

161155
return $controller->render();
@@ -184,7 +178,7 @@
184178
$subject = 'servers';
185179
}
186180

187-
return maybeRenderIframes($this, $response, $subject, $query_string);
181+
return $this->utils->maybeRenderIframes($response, $subject, $query_string);
188182
});
189183

190184
$app->get('/', function (
@@ -199,11 +193,11 @@
199193

200194
$query_string = $request->getUri()->getQuery();
201195

202-
return maybeRenderIframes($this, $response, $subject, $query_string);
196+
return $this->utils->maybeRenderIframes($response, $subject, $query_string);
203197
});
204198

205199
$app->get('[/{path:.*}]', function ($request, $response, $args) {
206-
$filepath = \BASE_PATH . '/' . $args['path'];
200+
$filepath = \BASE_PATH.'/'.$args['path'];
207201
$query_string = $request->getUri()->getQuery();
208202

209203
$this->utils->dump($query_string, $filepath);

src/classes/ContainerUtils.php

+27-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ContainerUtils
3131
*/
3232
public function __construct()
3333
{
34-
$composerinfo = json_decode(file_get_contents(BASE_PATH . '/composer.json'));
34+
$composerinfo = json_decode(file_get_contents(BASE_PATH.'/composer.json'));
3535
$appVersion = $composerinfo->version;
3636

3737
$phpMinVer = (str_replace(['<', '>', '='], '', $composerinfo->require->php));
@@ -49,14 +49,14 @@ public function __construct()
4949
'base_path' => BASE_PATH,
5050
'debug' => DEBUGMODE,
5151

52-
'routerCacheFile' => BASE_PATH . '/temp/route.cache.php',
52+
'routerCacheFile' => BASE_PATH.'/temp/route.cache.php',
5353

5454
// Configuration file version. If this is greater than that in config.inc.php, then
5555
// the app will refuse to run. This and $conf['version'] should be incremented whenever
5656
// backwards incompatible changes are made to config.inc.php-dist.
5757
'base_version' => 60,
5858
// Application version
59-
'appVersion' => 'v' . $appVersion,
59+
'appVersion' => 'v'.$appVersion,
6060
// Application name
6161
'appName' => 'phpPgAdmin6',
6262

@@ -73,7 +73,7 @@ public function __construct()
7373
// Fetch DI Container
7474
$container = $this->app->getContainer();
7575
$container['utils'] = $this;
76-
$container['version'] = 'v' . $appVersion;
76+
$container['version'] = 'v'.$appVersion;
7777
$container['errors'] = [];
7878

7979
$this->container = $container;
@@ -88,6 +88,26 @@ public static function createContainer()
8888
return [self::$instance->container, self::$instance->app];
8989
}
9090

91+
public function maybeRenderIframes($response, $subject, $query_string)
92+
{
93+
$c = $this->container;
94+
$in_test = $c->view->offsetGet('in_test');
95+
96+
if ($in_test === '1') {
97+
$className = '\PHPPgAdmin\Controller\\'.ucfirst($subject).'Controller';
98+
$controller = new $className($c);
99+
100+
return $controller->render();
101+
}
102+
103+
$viewVars = [
104+
'url' => '/src/views/'.$subject.($query_string ? '?'.$query_string : ''),
105+
'headertemplate' => 'header.twig',
106+
];
107+
108+
return $c->view->render($response, 'iframe_view.twig', $viewVars);
109+
}
110+
91111
/**
92112
* Gets the theme from
93113
* 1. The $_REQUEST global (when it's chosen from start screen)
@@ -186,10 +206,10 @@ public function getRedirectUrl()
186206

187207
// if server_id isn't set, then you will be redirected to intro
188208
if ($this->container->requestobj->getQueryParam('server') === null) {
189-
$destinationurl = \SUBFOLDER . '/src/views/intro';
209+
$destinationurl = \SUBFOLDER.'/src/views/intro';
190210
} else {
191211
// otherwise, you'll be redirected to the login page for that server;
192-
$destinationurl = \SUBFOLDER . '/src/views/login' . ($query_string ? '?' . $query_string : '');
212+
$destinationurl = \SUBFOLDER.'/src/views/login'.($query_string ? '?'.$query_string : '');
193213
}
194214

195215
return $destinationurl;
@@ -213,7 +233,7 @@ public function getDestinationWithLastTab($subject)
213233
$destinationurl = $this->getRedirectUrl();
214234
} else {
215235
$url = $this->container->misc->getLastTabURL($subject);
216-
$this->addFlash($url, 'getLastTabURL for ' . $subject);
236+
$this->addFlash($url, 'getLastTabURL for '.$subject);
217237
// Load query vars into superglobal arrays
218238
if (isset($url['urlvars'])) {
219239
$urlvars = [];

0 commit comments

Comments
 (0)