PHPLinq_Adapter
[ class tree: PHPLinq_Adapter ] [ index: PHPLinq_Adapter ] [ all elements ]

Source for file Abstract.php

Documentation is available at Abstract.php

  1. <?php
  2. /**
  3.  * PHPLinq
  4.  *
  5.  * Copyright (c) 2008 - 2009 PHPLinq
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPLinq
  22.  * @package    PHPLinq_Adapter
  23.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  24.  * @license    http://www.gnu.org/licenses/lgpl.txt    LGPL
  25.  * @version    0.4.0, 2009-01-27
  26.  */
  27.  
  28.  
  29. /** PHPLinq_Adapter_Exception */
  30. require_once 'PHPLinq/Adapter/Exception.php';
  31.  
  32. /** Zend_Db_Adapter_Abstract */
  33. require_once 'Zend/Db/Adapter/Abstract.php';
  34.  
  35.  
  36. /**
  37.  * PHPLinq_Adapter_Abstract
  38.  *
  39.  * @category   PHPLinq
  40.  * @package    PHPLinq_Adapter
  41.  * @copyright  Copyright (c) 2008 - 2009 PHPLinq (http://www.codeplex.com/PHPLinq)
  42.  */
  43. abstract class PHPLinq_Adapter_Abstract {
  44.     
  45.     // CHECK http://en.wikibooks.org/wiki/SQL_dialects_reference/Functions_and_expressions/String_functions
  46.     
  47.     /**
  48.      * Zend_Db_Adapter_Abstract
  49.      *
  50.      * @var Zend_Db_Adapter_Abstract 
  51.      */
  52.     protected $_adapter = null;
  53.     
  54.     /**
  55.      * Constructor
  56.      *
  57.      * @param Zend_Db_Adapter_Abstract $adapter 
  58.      */
  59.     public function __construct(Zend_Db_Adapter_Abstract $adapter null{
  60.         $this->_adapter = $adapter;
  61.     }
  62.     
  63.     /**
  64.      * Safely quotes a value for an SQL statement.
  65.      *
  66.      * If an array is passed as the value, the array values are quoted
  67.      * and then returned as a comma-separated string.
  68.      *
  69.      * @param mixed $value The value to quote.
  70.      * @param mixed $type  OPTIONAL the SQL datatype name, or constant, or null.
  71.      * @return mixed An SQL-safe quoted value (or string of separated values).
  72.      */
  73.     public function quote($value$type null)
  74.     {
  75.         return $this->_adapter->quote($value$type);
  76.     }
  77.     
  78.     /**
  79.      * Quotes an identifier.
  80.      *
  81.      * Accepts a string representing a qualified indentifier. For Example:
  82.      * <code>
  83.      * $adapter->quoteIdentifier('myschema.mytable')
  84.      * </code>
  85.      * Returns: "myschema"."mytable"
  86.      *
  87.      * Or, an array of one or more identifiers that may form a qualified identifier:
  88.      * <code>
  89.      * $adapter->quoteIdentifier(array('myschema','my.table'))
  90.      * </code>
  91.      * Returns: "myschema"."my.table"
  92.      *
  93.      * The actual quote character surrounding the identifiers may vary depending on
  94.      * the adapter.
  95.      *
  96.      * @param string|array|Zend_Db_Expr$ident The identifier.
  97.      * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  98.      * @return string The quoted identifier.
  99.      */
  100.     public function quoteIdentifier($ident$auto=false)
  101.     {
  102.         return $this->_adapter->quoteIdentifier($ident$auto);
  103.     }
  104.     
  105.     /**
  106.      * List of functions
  107.      *
  108.      * @var array 
  109.      */
  110.     protected static $_functions array(
  111.         'custom',
  112.         'ord',
  113.         'chr',
  114.         'substr',
  115.         'strlen',
  116.         'count',
  117.         'max',
  118.         'min',
  119.         'abs',
  120.         'strtolower',
  121.         'strtoupper',
  122.         'ltrim',
  123.         'rand',
  124.         'str_replace',
  125.         'round',
  126.         'rtrim',
  127.         'trim',
  128.         'strpos',
  129.         'stripos',
  130.         'lcfirst',
  131.         'ucfirst',
  132.         'md5',
  133.         'sha1',
  134.         'soundex',
  135.         'addslashes',
  136.         'str_repeat'
  137.     );
  138.     
  139.     /**
  140.      * Get list of functions
  141.      * 
  142.      * @return array; 
  143.      */
  144.     public static function getFunctions({
  145.         return self::$_functions;
  146.     }
  147.     
  148.     /**
  149.      * Convert operator
  150.      *
  151.      * @param string $operator 
  152.      * @return string 
  153.      */
  154.     public function operator($operator{
  155.         switch ($operator{
  156.             case '=':
  157.             case '!=':
  158.             case '>=':
  159.             case '<=':
  160.             case '>':
  161.             case '<':
  162.             case '+':
  163.             case '-':
  164.             case '*':
  165.             case '/':
  166.             case '%':
  167.             case '.':
  168.                 return $operator;
  169.         }
  170.     }
  171.     
  172.     /**
  173.      * Convert operand
  174.      *
  175.      * @param string $operand 
  176.      * @return string 
  177.      */
  178.     public function operand($operand{
  179.         switch ($operand{
  180.             case 'AND':
  181.             case 'OR':
  182.                 return $operand;
  183.         }
  184.     }
  185.     
  186.     /**
  187.      * Execute a custom function (outside of PHPLinq_Adapter package).
  188.      *
  189.      * @param array $function Function to call
  190.      */
  191.     public function custom({
  192.         $arguments func_get_args();
  193.         $functionName array_shift($arguments);
  194.         $functionName trim($functionName'"\'');
  195.         
  196.         return call_user_func_array$functionName$arguments );
  197.     }
  198.     
  199.     /**
  200.      * Return ASCII value of character
  201.      *
  202.      * @param string $string A character
  203.      * @return string 
  204.      */
  205.     abstract public function ord($string);
  206.     
  207.     /**
  208.      * Return a specific character
  209.      *
  210.      * @param string $string The ascii code
  211.      * @return string 
  212.      */
  213.     abstract public function chr($string);
  214.     
  215.     /**
  216.      * Return part of a string
  217.      *
  218.      * @param string $string 
  219.      * @param int $start 
  220.      * @param int $length 
  221.      * @return string 
  222.      */
  223.     abstract public function substr($string$start$length '');
  224.     
  225.     /**
  226.      * Get string length
  227.      *
  228.      * @param string $string 
  229.      * @return string 
  230.      */
  231.     abstract public function strlen($string);
  232.     
  233.     /**
  234.      * Count elements in an array, or properties in an object
  235.      *
  236.      * @param mixed $var 
  237.      * @return string 
  238.      */
  239.     abstract public function count($var);
  240.     
  241.     /**
  242.      * Find highest value
  243.      *
  244.      * @param mixed $values 
  245.      * @return string 
  246.      */
  247.     abstract public function max($values);
  248.     
  249.     /**
  250.      * Find lowest value
  251.      *
  252.      * @param mixed $values 
  253.      * @return string 
  254.      */
  255.     abstract public function min($values);
  256.     
  257.     /**
  258.      * Absolute value
  259.      *
  260.      * @param mixed $number 
  261.      * @return string 
  262.      */
  263.     abstract public function abs($number);
  264.     
  265.     /**
  266.      * Make a string lowercase
  267.      *
  268.      * @param string $str 
  269.      * @return string 
  270.      */
  271.     abstract public function strtolower($str);
  272.     
  273.     /**
  274.      * Make a string uppercase
  275.      *
  276.      * @param string $str 
  277.      * @return string 
  278.      */
  279.     abstract public function strtoupper($str);
  280.     
  281.     /**
  282.      * Strip whitespace (or other characters) from the beginning of a string
  283.      *
  284.      * @param string $str 
  285.      * @return string 
  286.      */
  287.     abstract public function ltrim($str);
  288.     
  289.     /**
  290.      * Generate a random integer
  291.      * 
  292.      * @return string 
  293.      */
  294.     abstract public function rand();
  295.     
  296.     /**
  297.      * Replace all occurrences of the search string with the replacement string
  298.      *
  299.      * @param mixed $search 
  300.      * @param mixed $replace 
  301.      * @param mixed $subject 
  302.      * @return string 
  303.      */
  304.     abstract public function str_replace($search$replace$subject);
  305.     
  306.     /**
  307.      * Rounds a float
  308.      *
  309.      * @param float $val 
  310.      * @param int $precision 
  311.      * @return string 
  312.      */
  313.     abstract public function round($val$precision 0);
  314.     
  315.     /**
  316.      * Strip whitespace (or other characters) from the end of a string
  317.      *
  318.      * @param string $str 
  319.      * @return string 
  320.      */
  321.     abstract public function rtrim($str);
  322.     
  323.     /**
  324.      * Strip whitespace (or other characters) from the beginning and end of a string
  325.      *
  326.      * @param string $str 
  327.      * @return string 
  328.      */
  329.     abstract public function trim($str);
  330.     
  331.     /**
  332.      * Find position of first occurrence of a string
  333.      *
  334.      * @param string $haystack 
  335.      * @param mixed $needle 
  336.      * @param int $offset 
  337.      * @return string 
  338.      */
  339.     abstract public function strpos($haystack$needle$offset 0);
  340.     
  341.     /**
  342.      * Find position of first occurrence of a case-insensitive string
  343.      *
  344.      * @param string $haystack 
  345.      * @param mixed $needle 
  346.      * @param int $offset 
  347.      * @return string 
  348.      */
  349.     abstract public function stripos($haystack$needle$offset 0);
  350.     
  351.     /**
  352.      * Make a string's first character lowercase
  353.      *
  354.      * @param string $str 
  355.      * @return string 
  356.      */
  357.     abstract public function lcfirst($str);
  358.     
  359.     /**
  360.      * Make a string's first character uppercase
  361.      *
  362.      * @param string $str 
  363.      * @return string 
  364.      */
  365.     abstract public function ucfirst($str);
  366.     
  367.     /**
  368.      * Calculate the md5 hash of a string
  369.      *
  370.      * @param string $str 
  371.      * @param boolean $raw_output 
  372.      * @return string 
  373.      */
  374.     abstract public function md5($str$raw_output false);
  375.     
  376.     /**
  377.      * Calculate the sha1 hash of a string
  378.      *
  379.      * @param string $str 
  380.      * @param boolean $raw_output 
  381.      * @return string 
  382.      */
  383.     abstract public function sha1($str$raw_output false);
  384.     
  385.     /**
  386.      * Calculate the soundex key of a string
  387.      *
  388.      * @param string $str 
  389.      * @return string 
  390.      */
  391.     abstract public function soundex($str);
  392.     
  393.     /**
  394.      * Quote string with slashes
  395.      *
  396.      * @param string $str 
  397.      * @return string 
  398.      */
  399.     abstract public function addslashes($str);
  400.     
  401.     /**
  402.      * Repeat a string
  403.      *
  404.      * @param string $input 
  405.      * @param int $multiplier 
  406.      * @return string 
  407.      */
  408.     abstract public function str_repeat($input$multiplier);
  409. }

Documentation generated on Tue, 27 Jan 2009 08:29:15 +0100 by phpDocumentor 1.4.1