Skip to content

Commit

Permalink
[#14213] - Adjusted tests; Added Enum classes; Refactored Db/Acl abst…
Browse files Browse the repository at this point in the history
…ract classes
  • Loading branch information
niden committed Jul 4, 2019
1 parent 8a0fc4e commit 648331f
Show file tree
Hide file tree
Showing 134 changed files with 294 additions and 325 deletions.
62 changes: 0 additions & 62 deletions phalcon/Acl.zep

This file was deleted.

2 changes: 1 addition & 1 deletion phalcon/Acl/Adapter/Memory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use ReflectionFunction;
* }
*```
*/
class Memory extends Adapter
class Memory extends AbstractAdapter
{
/**
* Access
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Crypt/Crypt.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use Phalcon\Crypt\Mismatch;
* Provides encryption capabilities to Phalcon applications.
*
* ```php
* use Phalcon\Crypt;
* use Phalcon\Crypt\Crypt;
*
* $crypt = new Crypt();
*
Expand Down Expand Up @@ -95,7 +95,7 @@ class Crypt implements CryptInterface
protected useSigning = true;

/**
* Phalcon\Crypt constructor.
* Phalcon\Crypt\Crypt constructor.
*/
public function __construct(string! cipher = "aes-256-cfb", bool useSigning = false) -> void
{
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Crypt/CryptInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phalcon\Crypt;

/**
* Interface for Phalcon\Crypt
* Interface for Phalcon\Crypt\Crypt
*/
interface CryptInterface
{
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Crypt/Exception.zep
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phalcon\Crypt;

/**
* Exceptions thrown in Phalcon\Crypt use this class
* Exceptions thrown in Phalcon\Crypt\Crypt use this class
*/
class Exception extends \Phalcon\Exception
{
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Crypt/Mismatch.zep
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Phalcon\Crypt;

/**
* Exceptions thrown in Phalcon\Crypt will use this class.
* Exceptions thrown in Phalcon\Crypt\Crypt will use this class.
*/
class Mismatch extends Exception
{
Expand Down
24 changes: 3 additions & 21 deletions phalcon/Db.zep → phalcon/Db/AbstractDb.zep
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace Phalcon;
namespace Phalcon\Db;

use \PDO as Pdo;

Expand Down Expand Up @@ -45,7 +45,7 @@ use \PDO as Pdo;
* "SELECT * FROM robots LIMIT 5"
* );
*
* $result->setFetchMode(Db::FETCH_NUM);
* $result->setFetchMode(Enum::FETCH_NUM);
*
* while ($robot = $result->fetch()) {
* print_r($robot);
Expand All @@ -55,26 +55,8 @@ use \PDO as Pdo;
* }
* ```
*/
abstract class Db
abstract class AbstractDb
{
const FETCH_ASSOC = \Pdo::FETCH_ASSOC;
const FETCH_BOTH = \Pdo::FETCH_BOTH;
const FETCH_BOUND = \Pdo::FETCH_BOUND;
const FETCH_CLASS = \Pdo::FETCH_CLASS;
const FETCH_CLASSTYPE = \Pdo::FETCH_CLASSTYPE;
const FETCH_COLUMN = \Pdo::FETCH_COLUMN;
const FETCH_FUNC = \Pdo::FETCH_FUNC;
const FETCH_GROUP = \Pdo::FETCH_GROUP;
const FETCH_INTO = \Pdo::FETCH_INTO;
const FETCH_KEY_PAIR = \Pdo::FETCH_KEY_PAIR;
const FETCH_LAZY = \Pdo::FETCH_LAZY;
const FETCH_NAMED = \Pdo::FETCH_NAMED;
const FETCH_NUM = \Pdo::FETCH_NUM;
const FETCH_OBJ = \Pdo::FETCH_OBJ;
const FETCH_PROPS_LATE = \Pdo::FETCH_PROPS_LATE;
const FETCH_SERIALIZE = \Pdo::FETCH_SERIALIZE;
const FETCH_UNIQUE = \Pdo::FETCH_UNIQUE;

/**
* Enables/disables options in the Database component
*/
Expand Down
39 changes: 23 additions & 16 deletions phalcon/Db/Adapter.zep → phalcon/Db/Adapter/AbstractAdapter.zep
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
* file that was distributed with this source code.
*/

namespace Phalcon\Db;
namespace Phalcon\Db\Adapter;

use Phalcon\Db;
use Phalcon\Db\Adapter\AdapterInterface;
use Phalcon\Db\ColumnInterface;
use Phalcon\Db\Enum;
use Phalcon\Db\Exception;
use Phalcon\Db\Index;
use Phalcon\Db\IndexInterface;
use Phalcon\Db\Reference;
use Phalcon\Db\ReferenceInterface;
use Phalcon\Db\RawValue;
use Phalcon\Events\EventsAwareInterface;
use Phalcon\Events\ManagerInterface;

/**
* Base class for Phalcon\Db adapters
*/
abstract class Adapter implements AdapterInterface, EventsAwareInterface
abstract class AbstractAdapter implements AdapterInterface, EventsAwareInterface
{
/**
* Connection ID
Expand Down Expand Up @@ -289,7 +296,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface

let indexes = [];

for index in this->fetchAll(this->dialect->describeIndexes(table, schema), Db::FETCH_NUM) {
for index in this->fetchAll(this->dialect->describeIndexes(table, schema), Enum::FETCH_NUM) {
let keyName = index[2];

if !isset indexes[keyName] {
Expand Down Expand Up @@ -331,7 +338,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface

let references = [];

for reference in this->fetchAll(this->dialect->describeReferences(table, schema), Db::FETCH_NUM) {
for reference in this->fetchAll(this->dialect->describeReferences(table, schema), Enum::FETCH_NUM) {
let constraintName = reference[2];

if !isset references[constraintName] {
Expand Down Expand Up @@ -489,7 +496,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* // Getting all robots with associative indexes only
* $robots = $connection->fetchAll(
* "SELECT * FROM robots",
* \Phalcon\Db::FETCH_ASSOC
* \Phalcon\Db\Enum::FETCH_ASSOC
* );
*
* foreach ($robots as $robot) {
Expand All @@ -499,7 +506,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* // Getting all robots that contains word "robot" withing the name
* $robots = $connection->fetchAll(
* "SELECT * FROM robots WHERE name LIKE :name",
* \Phalcon\Db::FETCH_ASSOC,
* \Phalcon\Db\Enum::FETCH_ASSOC,
* [
* "name" => "%robot%",
* ]
Expand All @@ -509,7 +516,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* }
*```
*/
public function fetchAll(string sqlQuery, int fetchMode = Db::FETCH_ASSOC, var bindParams = null, var bindTypes = null) -> array
public function fetchAll(string sqlQuery, int fetchMode = Enum::FETCH_ASSOC, var bindParams = null, var bindTypes = null) -> array
{
var result;

Expand Down Expand Up @@ -544,7 +551,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
{
var row, columnValue;

let row = this->fetchOne(sqlQuery, Db::FETCH_BOTH, placeholders);
let row = this->fetchOne(sqlQuery, Enum::FETCH_BOTH, placeholders);

if !fetch columnValue, row[column] {
return false;
Expand All @@ -564,12 +571,12 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* // Getting first robot with associative indexes only
* $robot = $connection->fetchOne(
* "SELECT * FROM robots",
* \Phalcon\Db::FETCH_ASSOC
* \Phalcon\Db\Enum::FETCH_ASSOC
* );
* print_r($robot);
*```
*/
public function fetchOne(string! sqlQuery, var fetchMode = Db::FETCH_ASSOC, var bindParams = null, var bindTypes = null) -> array
public function fetchOne(string! sqlQuery, var fetchMode = Enum::FETCH_ASSOC, var bindParams = null, var bindTypes = null) -> array
{
var result;

Expand Down Expand Up @@ -888,7 +895,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface

let tables = this->fetchAll(
this->dialect->listTables(schemaName),
Db::FETCH_NUM
Enum::FETCH_NUM
);

for table in tables {
Expand All @@ -915,7 +922,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface

let tables = this->fetchAll(
this->dialect->listViews(schemaName),
Db::FETCH_NUM
Enum::FETCH_NUM
);

for table in tables {
Expand Down Expand Up @@ -1050,7 +1057,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
*/
public function tableExists(string! tableName, string! schemaName = null) -> bool
{
return this->fetchOne(this->dialect->tableExists(tableName, schemaName), Db::FETCH_NUM)[0] > 0;
return this->fetchOne(this->dialect->tableExists(tableName, schemaName), Enum::FETCH_NUM)[0] > 0;
}

/**
Expand All @@ -1072,7 +1079,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
return [];
}

return this->fetchAll(sql, Db::FETCH_ASSOC)[0];
return this->fetchAll(sql, Enum::FETCH_ASSOC)[0];
}

/**
Expand Down Expand Up @@ -1274,6 +1281,6 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
*/
public function viewExists(string! viewName, string! schemaName = null) -> bool
{
return this->fetchOne(this->dialect->viewExists(viewName, schemaName), Db::FETCH_NUM)[0] > 0;
return this->fetchOne(this->dialect->viewExists(viewName, schemaName), Enum::FETCH_NUM)[0] > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
* file that was distributed with this source code.
*/

namespace Phalcon\Db;
namespace Phalcon\Db\Adapter;

use Phalcon\Db\ColumnInterface;
use Phalcon\Db\IndexInterface;
use Phalcon\Db\RawValue;
use Phalcon\Db\ReferenceInterface;

/**
* Interface for Phalcon\Db adapters
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Db/Adapter/Pdo.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Phalcon\Db\Adapter;

use Phalcon\Db\Adapter;
use Phalcon\Db\Adapter\AbstractAdapter;
use Phalcon\Db\Column;
use Phalcon\Db\Exception;
use Phalcon\Db\Result\Pdo as ResultPdo;
Expand All @@ -35,7 +35,7 @@ use Phalcon\Events\ManagerInterface;
* $connection = new Mysql($config);
*```
*/
abstract class Pdo extends Adapter
abstract class Pdo extends AbstractAdapter
{
/**
* Last affected rows
Expand Down
8 changes: 4 additions & 4 deletions phalcon/Db/Adapter/Pdo/Mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace Phalcon\Db\Adapter\Pdo;

use Phalcon\Db;
use Phalcon\Db\Adapter\Pdo as PdoAdapter;
use Phalcon\Db\Column;
use Phalcon\Db\ColumnInterface;
use Phalcon\Db\Enum;
use Phalcon\Db\Exception;
use Phalcon\Db\Index;
use Phalcon\Db\IndexInterface;
Expand Down Expand Up @@ -97,7 +97,7 @@ class Mysql extends PdoAdapter

let fields = this->fetchAll(
this->dialect->describeColumns(table, schema),
Db::FETCH_NUM
Enum::FETCH_NUM
);

/**
Expand Down Expand Up @@ -465,7 +465,7 @@ class Mysql extends PdoAdapter

let indexes = [];

for index in this->fetchAll(this->dialect->describeIndexes(table, schema), Db::FETCH_ASSOC) {
for index in this->fetchAll(this->dialect->describeIndexes(table, schema), Enum::FETCH_ASSOC) {
let keyName = index["Key_name"];
let indexType = index["Index_type"];

Expand Down Expand Up @@ -523,7 +523,7 @@ class Mysql extends PdoAdapter

let references = [];

for reference in this->fetchAll(this->dialect->describeReferences(table, schema), Db::FETCH_NUM) {
for reference in this->fetchAll(this->dialect->describeReferences(table, schema), Enum::FETCH_NUM) {

let constraintName = reference[2];

Expand Down
Loading

0 comments on commit 648331f

Please sign in to comment.