Exemple #1
0
 /**
  * Quote the value with single quotes
  *
  * @param  string $value
  * @return string
  */
 public function quote($value)
 {
     if ($value != '?' && substr($value, 0, 1) != ':' && preg_match('/^\\$\\d*\\d$/', $value) == 0 && !is_int($value) && !is_float($value)) {
         $value = "'" . $this->db->escape($value) . "'";
     }
     return $value;
 }
Exemple #2
0
 /**
  * Create and return Adapter\AdapterInterface instance.
  *
  * @param  null|string  $forceAdapter Optional adapter class name. Ccan be absolute namespace or class name
  *                                    relative to Zend\Console\Adapter\. If not provided, a best matching
  *                                    adapter will be automatically selected.
  * @param  null|string  $forceCharset optional charset name can be absolute namespace or class name relative to
  *                                    Zend\Console\Charset\. If not provided, charset will be detected
  *                                    automatically.
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  * @return Adapter\AdapterInterface
  */
 public static function getInstance($forceAdapter = null, $forceCharset = null)
 {
     if (static::$instance instanceof Adapter\AdapterInterface) {
         return static::$instance;
     }
     // Create instance
     if ($forceAdapter !== null) {
         // Use the supplied adapter class
         if (substr($forceAdapter, 0, 1) == '\\') {
             $className = $forceAdapter;
         } elseif (stristr($forceAdapter, '\\')) {
             $className = __NAMESPACE__ . '\\' . ltrim($forceAdapter, '\\');
         } else {
             $className = __NAMESPACE__ . '\\Adapter\\' . $forceAdapter;
         }
         if (!class_exists($className)) {
             throw new Exception\InvalidArgumentException(sprintf('Cannot find Console adapter class "%s"', $className));
         }
     } else {
         // Try to detect best instance for console
         $className = static::detectBestAdapter();
         // Check if we were able to detect console adapter
         if (!$className) {
             throw new Exception\RuntimeException('Cannot create Console adapter - am I running in a console?');
         }
     }
     // Create adapter instance
     static::$instance = new $className();
     // Try to use the supplied charset class
     if ($forceCharset !== null) {
         if (substr($forceCharset, 0, 1) == '\\') {
             $className = $forceCharset;
         } elseif (stristr($forceAdapter, '\\')) {
             $className = __NAMESPACE__ . '\\' . ltrim($forceCharset, '\\');
         } else {
             $className = __NAMESPACE__ . '\\Charset\\' . $forceCharset;
         }
         if (!class_exists($className)) {
             throw new Exception\InvalidArgumentException(sprintf('Cannot find Charset class "%s"', $className));
         }
         // Set adapter charset
         static::$instance->setCharset(new $className());
     }
     return static::$instance;
 }