Example #1
0
 /**
  * Constructor
  * 
  * @param float $value Value in dollars (0.1, 0.2 ... 1, 2, 5)
  */
 public function __construct($value)
 {
     if ($value < 0.1) {
         throw \UnexpectedValueException('Minimal value is one cent');
     }
     $this->value = $value;
 }
Example #2
0
 /** {@inheritdoc} */
 protected function _parseDatatype($data)
 {
     // SQLite's dynamic typing works different than the static typing of
     // other DBMS. The best we can do here is determining the column's type
     // affinity according to the rules documented at
     // http://www.sqlite.org/datatype3.html#affname
     $type = strtoupper($data['type']);
     if (strpos($type, 'INT') !== false) {
         $this->_datatype = self::TYPE_INTEGER;
     } elseif (preg_match('/(CHAR|CLOB|TEXT).*?(\\((\\d+)\\))?$/', $type, $matches)) {
         // Although SQLite ignores a length specification, it is preserved
         // in the column definition. If a length is given, the type is
         // interpreted as VARCHAR(length), otherwise as CLOB.
         if (isset($matches[3])) {
             $this->_datatype = self::TYPE_VARCHAR;
             $this->_length = (int) $matches[3];
         } else {
             $this->_datatype = self::TYPE_CLOB;
         }
     } elseif (strpos($type, 'BLOB') !== false) {
         $this->_datatype = self::TYPE_BLOB;
     } elseif (preg_match('/(REAL|FLOA|DOUB)/', $type)) {
         $this->_datatype = self::TYPE_FLOAT;
     } else {
         UnexpectedValueException('Unrecognized SQLite Datatype: ' . $data['type']);
     }
 }
Example #3
0
 public static function __callStatic($priority = 'debug', $params = array())
 {
     $trace = Debugger::trace(array('format' => 'array', 'depth' => 3, 'includeScope' => false));
     $trace = $trace[2];
     if (empty($trace)) {
         throw UnexpectedValueException('Could not trace method');
     }
     $trace = array('method' => $trace['functionRef'], 'line' => $trace['line'], 'file' => $trace['file']);
     $message = "//////////// {$trace['file']}:{$trace['line']} -> {$trace['method']} ////////////\n";
     foreach ($params as $param) {
         $dump = Debugger::export($param);
         $message = "{$message}{$dump}\n";
     }
     return parent::write($priority, $message);
 }
Example #4
0
 /**
  * Convert a Hexadecimal color to its RGB equivalent
  *
  * @param String $hex
  * @return array
  */
 public static function hex_to_rgb($hex)
 {
     if (!Color::is_valid_hex($hex)) {
         throw UnexpectedValueException($hex . ' is not a valid hexadecimal color. It must be a 3 or 6 character hexadecimal number');
     }
     $hex = str_replace('#', '', $hex);
     $color = array();
     if (strlen($hex) === 3) {
         $color['r'] = (int) hexdec(substr($hex, 0, 1));
         $color['g'] = (int) hexdec(substr($hex, 1, 1));
         $color['b'] = (int) hexdec(substr($hex, 2, 1));
     } elseif (strlen($hex) === 6) {
         $color['r'] = (int) hexdec(substr($hex, 0, 2));
         $color['g'] = (int) hexdec(substr($hex, 2, 2));
         $color['b'] = (int) hexdec(substr($hex, 4, 2));
     } else {
         $color = self::hex_to_rgb('000');
     }
     return $color;
 }
Example #5
0
 /**
  * Returns the child node to be annotated.
  * 
  * @param DOMNode $node
  * @param DOMXPath $xpath
  * @return DOMNode
  * @throws UnexpectedValueException
  */
 protected function get_child_node($node, $xpath = null)
 {
     if (null !== $xpath) {
         // TODO(cs) Future...
         throw UnexpectedValueException($xpath);
     } else {
         $child = $node->firstChild;
         if (null === $child) {
             $node->appendChild(new DOMText());
             $child = $node->firstChild;
         } else {
             if (1 === $child->nodeType) {
                 if ($this->ignore_node($child->tagName)) {
                     $node->insertBefore(new DOMText(), $child);
                     $child = $node->firstChild;
                 }
             }
         }
     }
     return $child;
 }
 /**
  * build
  *
  * Builds a template and saves it to the filesystem
  * in the self::$templateDir path
  *
  *
  * @param TemplateInterface $template
  * @param SiteInterface $site
  * @param TemplateInterface $extendedTemplate
  *
  * @throws UnexpectedValueException
  * @return int
  */
 public function build(TemplateInterface $template, SiteInterface $site, TemplateInterface $extendedTemplate = null)
 {
     if (!$template->getFilename()) {
         throw new \InvalidArgumentException('Cannot build a template without a unique filename');
     }
     $templateDir = $site->getTemplateDir();
     if ($extendedTemplate) {
         $content = sprintf('{# %s %s %s #}%s', $template->getId(), $template->getFilename(), date('c'), PHP_EOL);
         $content .= sprintf("{%% extends '%s' %%}", $this->buildTemplatePath($extendedTemplate, $site));
         $content .= PHP_EOL . PHP_EOL;
         $content .= $template->getActiveVersion()->getContent();
         $baseDir = dirname($templateDir . '/' . $extendedTemplate->getFilename());
         if (!file_exists($baseDir)) {
             mkdir($baseDir, 0755, true);
         }
         if (!file_exists($templateDir . '/' . $extendedTemplate->getFilename())) {
             $this->build($extendedTemplate, $site, null);
         }
     } else {
         $content = $template->getActiveVersion()->getContent();
     }
     $baseDir = dirname($templateDir . '/' . $template->getFilename());
     if (!file_exists($baseDir)) {
         mkdir($baseDir, 0755, true);
     }
     $status = file_put_contents($templateDir . '/' . $template->getFilename(), $content);
     if (false == $status) {
         throw \UnexpectedValueException(sprintf('Could Not Save File %s In %s', $template->getFilename(), $templateDir));
     }
 }
function MOOperation($phase, &$output)
{
    $method = strtolower($phase["method"]);
    switch ($method) {
        case "post":
            return 'mo_post("' . $phase["uri"] . '", ' . var_export($phase["payload"], true) . ');';
        default:
            throw UnexpectedValueException("Don't know the method {$method}");
    }
}
 /**
  * Merge another colleciton into this collection assuming they are of the same type
  *
  * @param \Common\Collection\BaseCollection $Collection
  * @throws
  */
 public function merge(BaseCollection $Collection)
 {
     $class = get_class($this);
     $newClass = get_class($Collection);
     if ($class !== $newClass) {
         throw \UnexpectedValueException('You can only merge classes of the same type. Expected collection of type ' . $class . ' and received ' . $newClass);
     }
     foreach ($Collection as $Item) {
         $this->append($Item);
     }
 }