Skip to content

Commit 81b2714

Browse files
committed
added BackupTrait::getDriverName() method
1 parent 0ec6e04 commit 81b2714

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2.x branch
22
## 2.6 branch
33
### 2.6.2
4+
* added `BackupTrait::getDriverName()` method;
45
* `BackupExport::compression()` takes a compression type name as string or
56
`null` to disable compression;
67
* `BackupExport::send()` takes a recipient's email address as string or `null`

src/BackupTrait.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,19 @@ public function getConnection($name = null)
8080
}
8181

8282
/**
83-
* Gets the driver containing all methods to export/import database backups
84-
* according to the database engine
83+
* Gets the driver instance containing all methods to export/import database
84+
* backups, according to the database engine
8585
* @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
86-
* @return object A driver instance
86+
* @return object The driver instance
8787
* @since 2.0.0
8888
* @throws \InvalidArgumentException
8989
* @uses getConnection()
90+
* @uses getDriverName()
9091
*/
9192
public function getDriver(ConnectionInterface $connection = null)
9293
{
9394
$connection = $connection ?: $this->getConnection();
94-
$className = get_class_short_name($connection->getDriver());
95+
$className = $this->getDriverName($connection);
9596
$driver = App::classname(sprintf('%s.%s', 'DatabaseBackup', $className), 'Driver');
9697
is_true_or_fail(
9798
$driver,
@@ -102,6 +103,20 @@ public function getDriver(ConnectionInterface $connection = null)
102103
return new $driver($connection);
103104
}
104105

106+
/**
107+
* Gets the driver name, according to the database engine
108+
* @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
109+
* @return string The driver name
110+
* @since 2.6.2
111+
* @uses getConnection()
112+
*/
113+
public function getDriverName(ConnectionInterface $connection = null)
114+
{
115+
$connection = $connection ?: $this->getConnection();
116+
117+
return get_class_short_name(get_class($connection->getDriver()));
118+
}
119+
105120
/**
106121
* Returns the extension from a filename
107122
* @param string $filename Filename

src/Console/Command.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@ class Command extends BaseCommand
2929
* Implement this method with your command's logic
3030
* @param \Cake\Console\Arguments $args The command arguments
3131
* @param \Cake\Console\ConsoleIo $io The console io
32-
* @return null|int The exit code or null for success
32+
* @return int|null The exit code or null for success
3333
*/
3434
public function execute(Arguments $args, ConsoleIo $io)
3535
{
3636
$config = $this->getConnection()->config();
37-
$driver = $this->getDriver($this->getConnection());
3837

3938
$io->out(__d('database_backup', 'Connection: {0}', $config['name']));
40-
$io->out(__d('database_backup', 'Driver: {0}', get_class_short_name($driver)));
39+
$io->out(__d('database_backup', 'Driver: {0}', $this->getDriverName($this->getConnection())));
4140
$io->hr();
4241

4342
return null;

tests/TestCase/BackupTraitTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ public function testGetDriver()
131131
$this->getDriver($connection);
132132
}
133133

134+
/**
135+
* Test for `getDriverName()` method
136+
* @test
137+
*/
138+
public function testGetDriverName()
139+
{
140+
foreach ([ConnectionManager::get('test'), null] as $driver) {
141+
$this->assertEquals('Mysql', $this->getDriverName($driver));
142+
}
143+
}
144+
134145
/**
135146
* Test for `getExtension()` method
136147
* @test

0 commit comments

Comments
 (0)