Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Delegate quoteIdentifier operation to quoteIdentifierChain #233

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions src/Adapter/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert. The topic of this PR is "Delegate quoteIdentifier operation to quoteIdentifierChain" and not fixing the CS!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you reviewing old commits by accident? I think this is before you told me not to run outdated CS fixer in another PR. I redid all my other PRs same evening, including this one.

/**
* Zend Framework (http://framework.zend.com/)
* Zend Framework (http://framework.zend.com/).
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
*
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down Expand Up @@ -31,7 +33,7 @@ abstract class AbstractPlatform implements PlatformInterface
*/
public function quoteIdentifierInFragment($identifier, array $safeWords = [])
{
if (! $this->quoteIdentifiers) {
if (!$this->quoteIdentifiers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert, the white space was correct.

return $identifier;
}

Expand All @@ -54,8 +56,8 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = [])
$identifier .= isset($safeWordsInt[strtolower($part)])
? $part
: $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part)
. $this->quoteIdentifier[1];
.str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert, the white space was correct.

.$this->quoteIdentifier[1];
}

return $identifier;
Expand All @@ -66,21 +68,29 @@ public function quoteIdentifierInFragment($identifier, array $safeWords = [])
*/
public function quoteIdentifier($identifier)
{
if (! $this->quoteIdentifiers) {
return $identifier;
}

return $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier)
. $this->quoteIdentifier[1];
return $this->quoteIdentifierChain([$identifier]);
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
if (is_string($identifierChain)) {
$identifierChain = [$identifierChain];
}

if (!$this->quoteIdentifiers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White space after exclamation mark is missing.

return implode($this->getIdentifierSeparator(), $identifierChain);
}

/** @var array $identifierChain */
foreach ($identifierChain as $key => $identifier) {
$identifierChain[$key] = str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier);
}
$chainGlue = $this->quoteIdentifier[1].$this->getIdentifierSeparator().$this->quoteIdentifier[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White space before and after the dots is missing.


return $this->quoteIdentifier[0].implode($chainGlue, $identifierChain).$this->quoteIdentifier[1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

White space before and after the dots is missing.

}

/**
Expand All @@ -105,18 +115,19 @@ public function getQuoteValueSymbol()
public function quoteValue($value)
{
trigger_error(
'Attempting to quote a value in ' . get_class($this) .
'Attempting to quote a value in '.get_class($this).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert, the white space was correct.

' without extension/driver support can introduce security vulnerabilities in a production environment'
);
return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\'';

return '\''.addcslashes((string) $value, "\x00\n\r\\'\"\x1a").'\'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert, the white space was correct.

}

/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\'';
return '\''.addcslashes((string) $value, "\x00\n\r\\'\"\x1a").'\'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert, the white space was correct.

}

/**
Expand Down
8 changes: 0 additions & 8 deletions src/Adapter/Platform/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ public function getName()
return 'MySQL';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '`' . implode('`.`', (array) str_replace('`', '``', $identifierChain)) . '`';
}

/**
* {@inheritDoc}
*/
Expand Down
14 changes: 1 addition & 13 deletions src/Adapter/Platform/Oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Oci8\Oci8;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use \Zend\Db\Adapter\Exception\InvalidArgumentException;
use Zend\Db\Adapter\Exception\InvalidArgumentException;

class Oracle extends AbstractPlatform
{
Expand Down Expand Up @@ -78,18 +78,6 @@ public function getName()
return 'Oracle';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
if ($this->quoteIdentifiers === false) {
return implode('.', (array) $identifierChain);
}

return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Adapter/Platform/Postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ public function getName()
return 'PostgreSQL';
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '""', $identifierChain)) . '"';
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Adapter/Platform/SqlServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ public function getQuoteIdentifierSymbol()
return $this->quoteIdentifier;
}

/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '[' . implode('].[', (array) $identifierChain) . ']';
}

/**
* {@inheritDoc}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Sql/AbstractSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Platform\PlatformInterface;
use Zend\Db\Sql\Platform\PlatformDecoratorInterface;
use Zend\Db\Adapter\Platform\Sql92 as DefaultAdapterPlatform;
use Zend\Db\Sql\Platform\PlatformDecoratorInterface;

abstract class AbstractSql implements SqlInterface
{
Expand Down Expand Up @@ -435,7 +435,7 @@ protected function resolveTable(
}

if ($schema && $table) {
$table = $platform->quoteIdentifier($schema) . $platform->getIdentifierSeparator() . $table;
$table = $platform->quoteIdentifierChain($schema) . $platform->getIdentifierSeparator() . $table;
}
return $table;
}
Expand Down