Skip to content

Commit

Permalink
Fixed exceptions + small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bacinsky committed Jan 9, 2017
1 parent 52cba24 commit c437f74
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 25 deletions.
15 changes: 11 additions & 4 deletions src/WebinoDbDump/Db/Dump/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk)
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

namespace WebinoDbDump\Db\Dump;

use WebinoDbDump\Exception;
use Zend\Db\Adapter\Adapter as DbAdapter;
use Zend\Db\Adapter\AdapterInterface as DbAdapterInterface;

/**
* Database dump utility adapter
*
* @author Peter Bačinský <peter@bacinsky.sk>
*/
class Adapter
{
Expand Down Expand Up @@ -53,9 +53,16 @@ public function getSchema()
/**
* @param string $sql
* @return \Zend\Db\ResultSet\ResultSet
* @throws Exception\SqlQueryException
*/
public function executeQuery($sql)
{
return $this->adapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
try {
return $this->adapter->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
} catch (\Exception $exc) {
throw new Exception\SqlQueryException(
PHP_EOL . $exc->getMessage() . PHP_EOL . $sql . PHP_EOL
);
}
}
}
20 changes: 9 additions & 11 deletions src/WebinoDbDump/Db/Dump/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk)
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

Expand All @@ -13,13 +14,12 @@
use WebinoDbDump\Db\Dump\Platform\PlatformInterface;
use WebinoDbDump\Db\Sql\SqlFile;
use WebinoDbDump\Db\Sql\SqlInterface;
use WebinoDbDump\Exception;
use WebinoDbDump\Module;
use Zend\Db\Adapter\AdapterInterface;

/**
* Database dump utility
*
* @author Peter Bačinský <peter@bacinsky.sk>
*/
class Dump implements DumpInterface
{
Expand Down Expand Up @@ -49,15 +49,15 @@ public function __construct($adapter)
/**
* @param AdapterInterface|Adapter $adapter
* @return $this
* @throws Exception\InvalidArgumentException
*/
protected function setAdapter($adapter)
{
if ($adapter instanceof AdapterInterface) {
$adapter = new Adapter($adapter);

} elseif (!($adapter instanceof Adapter)) {
// TODO exception
throw new \InvalidArgumentException('Expected Db\Adapter or Dump\Adapter');
throw new Exception\InvalidArgumentException('Expected Db\Adapter or Dump\Adapter');
}

$this->adapter = $adapter;
Expand Down Expand Up @@ -99,15 +99,14 @@ public function setDumpPlatform(PlatformInterface $dumpPlatform = null)
*
* @param string $filePath
* @return File
* @throws \RuntimeException
* @throws Exception\RuntimeException
*/
public function createOutputFile($filePath)
{
try {
return new File($filePath, 'wb');
} catch (\Exception $exc) {
// TODO exception
throw new \RuntimeException(
throw new Exception\RuntimeException(
sprintf('Can\'t open file for writing `%s`', $filePath),
$exc->getCode(),
$exc
Expand All @@ -122,15 +121,14 @@ public function createOutputFile($filePath)
*
* @param string $filePath
* @return SqlFile
* @throws \RuntimeException
* @throws Exception\RuntimeException
*/
public function createInputFile($filePath)
{
try {
return new SqlFile($filePath, 'rb');
} catch (\Exception $exc) {
// TODO exception
throw new \RuntimeException(
throw new Exception\RuntimeException(
sprintf('Can\'t open file for reading `%s`', $filePath),
$exc->getCode(),
$exc
Expand Down
5 changes: 2 additions & 3 deletions src/WebinoDbDump/Db/Dump/Platform/Mysql/Table/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk)
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

Expand All @@ -15,8 +16,6 @@

/**
* Mysql database dump utility platform columns
*
* @author Peter Bačinský <peter@bacinsky.sk>
*/
class Columns extends AbstractColumns implements ColumnsInterface
{
Expand Down
14 changes: 7 additions & 7 deletions src/WebinoDbDump/Db/Dump/Table/AbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2014-2016 Webino, s. r. o. (http://webino.sk)
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

Expand All @@ -12,11 +13,10 @@
use SplFileObject as File;
use WebinoDbDump\Db\Dump\Dump;
use WebinoDbDump\Db\Dump\Adapter;
use WebinoDbDump\Exception;

/**
* Base class for a dump utility platform table
*
* @author Peter Bačinský <peter@bacinsky.sk>
*/
abstract class AbstractTable
{
Expand Down Expand Up @@ -60,7 +60,7 @@ abstract protected function showColumns();
abstract protected function select();

/**
* @return TableColumnsInterface
* @return ColumnsInterface
*/
abstract protected function createColumns();

Expand Down Expand Up @@ -101,12 +101,12 @@ protected function setName($name)

/**
* @return bool
* @throws Exception\RuntimeException
*/
protected function isView()
{
if (null === $this->view) {
// TODO exception
throw new \RuntimeException('Don\'t know if is view');
throw new Exception\RuntimeException('Don\'t know if is view');
}

return $this->view;
Expand Down Expand Up @@ -188,7 +188,7 @@ private function writeData(File $file)
}

/**
* @return TableColumnsInterface
* @return ColumnsInterface
*/
private function createColumnsInternal()
{
Expand Down
18 changes: 18 additions & 0 deletions src/WebinoDbDump/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

namespace WebinoDbDump\Exception;

/**
* Interface ExceptionInterface
*/
interface ExceptionInterface
{
}
18 changes: 18 additions & 0 deletions src/WebinoDbDump/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

namespace WebinoDbDump\Exception;

/**
* Class InvalidArgumentException
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
18 changes: 18 additions & 0 deletions src/WebinoDbDump/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

namespace WebinoDbDump\Exception;

/**
* Class RuntimeException
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
18 changes: 18 additions & 0 deletions src/WebinoDbDump/Exception/SqlQueryException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Webino (http://webino.sk)
*
* @link https://github.com/webino/WebinoDbDump/ for the canonical source repository
* @copyright Copyright (c) 2017 Webino, s. r. o. (http://webino.sk)
* @author Peter Bačinský <peter@bacinsky.sk>
* @license The BSD 3-Clause License
*/

namespace WebinoDbDump\Exception;

/**
* Class SqlQueryException
*/
class SqlQueryException extends \RuntimeException implements ExceptionInterface
{
}

0 comments on commit c437f74

Please sign in to comment.