"Fossies" - the Fresh Open Source Software Archive

Member "papayacms-core-6.9.4/src/system/Papaya/Database/Syntax/AbstractSyntax.php" (13 Dec 2019, 1746 Bytes) of package /linux/www/papayacms-core-6.9.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractSyntax.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 6.8.0_vs_6.9.0.

    1 <?php
    2 
    3 namespace Papaya\Database\Syntax {
    4 
    5   use Papaya\Database\Connection as DatabaseConnection;
    6   use Papaya\Database\Syntax as SQLSyntax;
    7 
    8   abstract class AbstractSyntax implements SQLSyntax {
    9 
   10     /**
   11      * @var DatabaseConnection
   12      */
   13     protected $_connection;
   14 
   15     /**
   16      * @param DatabaseConnection $connector
   17      */
   18     public function __construct(DatabaseConnection $connector) {
   19       $this->_connection = $connector;
   20     }
   21 
   22     /**
   23      * @param string $name
   24      * @return Identifier
   25      */
   26     public function identifier($name) {
   27       return new Identifier($name);
   28     }
   29 
   30     /**
   31      * @param string $name
   32      * @return Placeholder
   33      */
   34     public function placeholder($name = '') {
   35       return new Placeholder($name);
   36     }
   37 
   38     /**
   39      * Compile parameter into an SQL string.
   40      *
   41      * Quotes identifiers and string literals using the connection.
   42      *
   43      * @param SQLSource|string $parameter
   44      * @return string
   45      */
   46     protected function compileParameter($parameter) {
   47       if ($parameter instanceof Identifier) {
   48         return $this->_connection->quoteIdentifier($parameter);
   49       }
   50       if (
   51         $parameter instanceof SQLSource
   52       ) {
   53         return (string)$parameter;
   54       }
   55       if ($parameter === '?') {
   56         return '?';
   57       }
   58       return $this->_connection->quoteString($parameter);
   59     }
   60 
   61     /**
   62      * @param string|Parameter $haystack
   63      * @param string|Parameter $needle
   64      * @return string
   65      */
   66     public function substringCount($haystack, $needle) {
   67       $replace = $this->replace($haystack, $needle, $this->substring($needle, 2));
   68       return new SQLSource('('.$this->characterLength($haystack).' - '.$this->characterLength($replace).')');
   69     }
   70   }
   71 }