1818use Cake \Datasource \ConnectionInterface ;
1919use Cake \Datasource \ConnectionManager ;
2020use InvalidArgumentException ;
21- use RuntimeException ;
2221use Symfony \Component \Filesystem \Filesystem ;
2322
2423/**
@@ -31,32 +30,20 @@ trait BackupTrait
3130 * @since 2.4.0
3231 * @var array
3332 */
34- private static $ validExtensions = ['sql.bz2 ' => 'bzip2 ' , 'sql.gz ' => 'gzip ' , 'sql ' => false ];
33+ protected static $ validExtensions = ['sql.bz2 ' => 'bzip2 ' , 'sql.gz ' => 'gzip ' , 'sql ' => false ];
3534
3635 /**
3736 * Returns an absolute path
3837 * @param string $path Relative or absolute path
3938 * @return string
40- * @uses getTarget()
4139 */
4240 public function getAbsolutePath (string $ path ): string
4341 {
44- return (new Filesystem ())->isAbsolutePath ($ path ) ? $ path : add_slash_term ($ this ->getTarget ()) . $ path ;
45- }
46-
47- /**
48- * Gets a binary path
49- * @param string $name Binary name
50- * @return string
51- * @since 2.0.0
52- * @throws \RuntimeException
53- */
54- public function getBinary (string $ name ): string
55- {
56- $ binary = Configure::read ('DatabaseBackup.binaries. ' . $ name );
57- is_true_or_fail ($ binary , __d ('database_backup ' , 'Binary for `{0}` could not be found. You have to set its path manually ' , $ name ), RuntimeException::class);
42+ if (!(new Filesystem ())->isAbsolutePath ($ path )) {
43+ return add_slash_term (Configure::read ('DatabaseBackup.target ' )) . $ path ;
44+ }
5845
59- return $ binary ;
46+ return $ path ;
6047 }
6148
6249 /**
@@ -93,12 +80,11 @@ public function getConnection(?string $name = null): ConnectionInterface
9380 * @since 2.0.0
9481 * @throws \InvalidArgumentException
9582 * @uses getConnection()
96- * @uses getDriverName()
9783 */
9884 public function getDriver (?ConnectionInterface $ connection = null ): object
9985 {
10086 $ connection = $ connection ?: $ this ->getConnection ();
101- $ className = $ this -> getDriverName ( $ connection );
87+ $ className = get_class_short_name ( $ connection -> getDriver () );
10288 $ driver = App::classname (sprintf ('%s.%s ' , 'DatabaseBackup ' , $ className ), 'Driver ' );
10389 is_true_or_fail (
10490 $ driver ,
@@ -109,41 +95,18 @@ public function getDriver(?ConnectionInterface $connection = null): object
10995 return new $ driver ($ connection );
11096 }
11197
112- /**
113- * Gets the driver name, according to the database engine
114- * @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
115- * @return string The driver name
116- * @since 2.6.2
117- * @uses getConnection()
118- */
119- public function getDriverName (?ConnectionInterface $ connection = null ): string
120- {
121- $ connection = $ connection ?: $ this ->getConnection ();
122-
123- return get_class_short_name ($ connection ->getDriver ());
124- }
125-
12698 /**
12799 * Returns the extension from a filename
128100 * @param string $filename Filename
129101 * @return string|null Extension or `null` if the extension is not found or
130102 * if is an invalid extension
131- * @uses getValidExtensions()
103+ * @uses $validExtensions
132104 */
133105 public function getExtension (string $ filename ): ?string
134106 {
135107 $ extension = get_extension ($ filename );
136108
137- return in_array ($ extension , $ this ->getValidExtensions ()) ? $ extension : null ;
138- }
139-
140- /**
141- * Returns the target path
142- * @return string
143- */
144- public function getTarget (): string
145- {
146- return Configure::read ('DatabaseBackup.target ' );
109+ return in_array ($ extension , array_keys (self ::$ validExtensions )) ? $ extension : null ;
147110 }
148111
149112 /**
@@ -156,15 +119,4 @@ public function getValidCompressions(): array
156119 {
157120 return array_filter (self ::$ validExtensions );
158121 }
159-
160- /**
161- * Returns all valid extensions
162- * @return array
163- * @since 2.4.0
164- * @uses $validExtensions
165- */
166- public function getValidExtensions (): array
167- {
168- return array_keys (self ::$ validExtensions );
169- }
170122}
0 commit comments