Skip to content

Commit 4dca630

Browse files
committed
Compatibility with "aura/sql" 4.x+ package
1 parent b317d86 commit 4dca630

File tree

5 files changed

+249
-78
lines changed

5 files changed

+249
-78
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"console-helpers/prophecy-phpunit": "^3.0"
3232
},
3333
"autoload": {
34+
"files": [
35+
"svn-buddy_autoloader.php"
36+
],
3437
"psr-4": {
3538
"ConsoleHelpers\\SVNBuddy\\": "src/SVNBuddy/"
3639
}

src/SVNBuddy/Database/StatementProfiler.php

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
class StatementProfiler implements ProfilerInterface
2121
{
2222

23+
use TStatementProfiler;
24+
2325
/**
2426
* Is the profiler active?
2527
*
@@ -126,28 +128,6 @@ public function ignoreDuplicateStatement($statement)
126128
$this->ignoredDuplicateStatements[] = $this->normalizeStatement($statement);
127129
}
128130

129-
/**
130-
* Turns the profiler on and off.
131-
*
132-
* @param boolean $active True to turn on, false to turn off.
133-
*
134-
* @return void
135-
*/
136-
public function setActive($active)
137-
{
138-
$this->active = (bool)$active;
139-
}
140-
141-
/**
142-
* Is the profiler active?
143-
*
144-
* @return boolean
145-
*/
146-
public function isActive()
147-
{
148-
return (bool)$this->active;
149-
}
150-
151131
/**
152132
* Toggle duplicate statement tracker.
153133
*
@@ -308,60 +288,4 @@ public function resetProfiles()
308288
$this->profiles = array();
309289
}
310290

311-
/**
312-
* @inheritDoc
313-
*/
314-
public function getLogger()
315-
{
316-
return $this->logger;
317-
}
318-
319-
/**
320-
* @inheritDoc
321-
*/
322-
public function getLogLevel()
323-
{
324-
return $this->logLevel;
325-
}
326-
327-
/**
328-
* @inheritDoc
329-
*/
330-
public function setLogLevel($logLevel)
331-
{
332-
$this->logLevel = $logLevel;
333-
}
334-
335-
/**
336-
* @inheritDoc
337-
*/
338-
public function getLogFormat()
339-
{
340-
return $this->logFormat;
341-
}
342-
343-
/**
344-
* @inheritDoc
345-
*/
346-
public function setLogFormat($logFormat)
347-
{
348-
$this->logFormat = $logFormat;
349-
}
350-
351-
/**
352-
* @inheritDoc
353-
*/
354-
public function start($function)
355-
{
356-
357-
}
358-
359-
/**
360-
* @inheritDoc
361-
*/
362-
public function finish($statement = null, array $values = [])
363-
{
364-
365-
}
366-
367291
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* This file is part of the SVN-Buddy library.
4+
* For the full copyright and license information, please view
5+
* the LICENSE file that was distributed with this source code.
6+
*
7+
* @copyright Alexander Obuhovich <[email protected]>
8+
* @link https://github.com/console-helpers/svn-buddy
9+
*/
10+
11+
namespace ConsoleHelpers\SVNBuddy\Database;
12+
13+
14+
trait TStatementProfiler
15+
{
16+
17+
/**
18+
* Turns the profiler on and off.
19+
*
20+
* @param boolean $active True to turn on, false to turn off.
21+
*
22+
* @return void
23+
*/
24+
public function setActive($active)
25+
{
26+
$this->active = (bool)$active;
27+
}
28+
29+
/**
30+
* Is the profiler active?
31+
*
32+
* @return boolean
33+
*/
34+
public function isActive()
35+
{
36+
return (bool)$this->active;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function getLogger()
43+
{
44+
return $this->logger;
45+
}
46+
47+
/**
48+
* @inheritDoc
49+
*/
50+
public function getLogLevel()
51+
{
52+
return $this->logLevel;
53+
}
54+
55+
/**
56+
* @inheritDoc
57+
*/
58+
public function setLogLevel($logLevel)
59+
{
60+
$this->logLevel = $logLevel;
61+
}
62+
63+
/**
64+
* @inheritDoc
65+
*/
66+
public function getLogFormat()
67+
{
68+
return $this->logFormat;
69+
}
70+
71+
/**
72+
* @inheritDoc
73+
*/
74+
public function setLogFormat($logFormat)
75+
{
76+
$this->logFormat = $logFormat;
77+
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
public function start($function)
83+
{
84+
85+
}
86+
87+
/**
88+
* @inheritDoc
89+
*/
90+
public function finish($statement = null, array $values = [])
91+
{
92+
93+
}
94+
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* This file is part of the SVN-Buddy library.
4+
* For the full copyright and license information, please view
5+
* the LICENSE file that was distributed with this source code.
6+
*
7+
* @copyright Alexander Obuhovich <[email protected]>
8+
* @link https://github.com/console-helpers/svn-buddy
9+
*/
10+
11+
namespace ConsoleHelpers\SVNBuddy\Database;
12+
13+
14+
trait TStatementProfiler
15+
{
16+
17+
/**
18+
* Turns the profiler on and off.
19+
*
20+
* @param boolean $active True to turn on, false to turn off.
21+
*
22+
* @return void
23+
*/
24+
public function setActive(bool $active)
25+
{
26+
$this->active = (bool)$active;
27+
}
28+
29+
/**
30+
* Is the profiler active?
31+
*
32+
* @return boolean
33+
*/
34+
public function isActive(): bool
35+
{
36+
return (bool)$this->active;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function getLogger(): \Psr\Log\LoggerInterface
43+
{
44+
return $this->logger;
45+
}
46+
47+
/**
48+
* @inheritDoc
49+
*/
50+
public function getLogLevel(): string
51+
{
52+
return $this->logLevel;
53+
}
54+
55+
/**
56+
* @inheritDoc
57+
*/
58+
public function setLogLevel(string $logLevel): void
59+
{
60+
$this->logLevel = $logLevel;
61+
}
62+
63+
/**
64+
* @inheritDoc
65+
*/
66+
public function getLogFormat(): string
67+
{
68+
return $this->logFormat;
69+
}
70+
71+
/**
72+
* @inheritDoc
73+
*/
74+
public function setLogFormat(string $logFormat): void
75+
{
76+
$this->logFormat = $logFormat;
77+
}
78+
79+
/**
80+
* @inheritDoc
81+
*/
82+
public function start(string $function): void
83+
{
84+
85+
}
86+
87+
/**
88+
* @inheritDoc
89+
*/
90+
public function finish(?string $statement = null, array $values = []): void
91+
{
92+
93+
}
94+
95+
}

svn-buddy_autoloader.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* This file is part of the SVN-Buddy library.
4+
* For the full copyright and license information, please view
5+
* the LICENSE file that was distributed with this source code.
6+
*
7+
* @copyright Alexander Obuhovich <[email protected]>
8+
* @link https://github.com/console-helpers/svn-buddy
9+
*/
10+
11+
namespace ConsoleHelpers\SVNBuddy;
12+
13+
14+
use Aura\Sql\Profiler\ProfilerInterface;
15+
16+
if ( \class_exists('ConsoleHelpers\SVNBuddy\Autoload', false) === false ) {
17+
18+
/**
19+
* Custom autoloader.
20+
*/
21+
final class Autoload
22+
{
23+
24+
/**
25+
* Loads a class.
26+
*
27+
* @param string $class_name The name of the class to load.
28+
*
29+
* @return boolean
30+
*/
31+
public static function load($class_name)
32+
{
33+
// Only load classes belonging to this library.
34+
if ( \stripos($class_name, 'ConsoleHelpers\SVNBuddy\Database\TStatementProfiler') !== 0 ) {
35+
return false;
36+
}
37+
38+
$method = new \ReflectionMethod(ProfilerInterface::class, 'setActive');
39+
$method_parameters = $method->getParameters();
40+
41+
if ( PHP_VERSION_ID >= 70000 && $method_parameters[0]->hasType() ) {
42+
require_once __DIR__ . '/src/SVNBuddy/Database/TStatementProfiler7.php';
43+
}
44+
else {
45+
require_once __DIR__ . '/src/SVNBuddy/Database/TStatementProfiler5.php';
46+
}
47+
48+
return true;
49+
}
50+
51+
}
52+
53+
\spl_autoload_register(__NAMESPACE__ . '\Autoload::load');
54+
}

0 commit comments

Comments
 (0)