/** * This method renders the data for the writer. * * @access public * @return string the data as string * @throws \Exception indicates a problem occurred * when generating the template */ public function render() { $delimiter = $this->metadata['delimiter']; $enclosure = $this->metadata['enclosure']; $escape = $this->metadata['escape']; $eol = $this->metadata['eol']; $encoding = $this->metadata['encoding']; ob_start(); try { if (!empty($this->metadata['template'])) { $file = new IO\File($this->metadata['template']); $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($field) use($delimiter, $enclosure, $escape, $encoding) { $value = Core\Data\Charset::encode($field, $encoding[0], $encoding[1]); if ($enclosure != '' && (strpos($value, $delimiter) !== false || strpos($value, $enclosure) !== false || strpos($value, "\n") !== false || strpos($value, "\r") !== false || strpos($value, "\t") !== false || strpos($value, ' ') !== false)) { $literal = $enclosure; $escaped = 0; $length = strlen($value); for ($i = 0; $i < $length; $i++) { if ($value[$i] == $escape) { $escaped = 1; } else { if (!$escaped && $value[$i] == $enclosure) { $literal .= $enclosure; } else { $escaped = 0; } } $literal .= $value[$i]; } $literal .= $enclosure; return $literal; } else { return Core\Convert::toString($value); } })); echo $mustache->render($file->getFileName(), $this->data); } else { if ($this->metadata['header']) { if (!empty($this->metadata['headings'])) { echo static::format($this->metadata['headings'], $delimiter, $enclosure, $escape, $eol, $encoding); } else { if (!empty($this->data)) { echo static::format(array_keys($this->data[0]), $delimiter, $enclosure, $escape, $eol, $encoding); } } } foreach ($this->data as $values) { echo static::format($values, $delimiter, $enclosure, $escape, $eol, $encoding); } } } catch (\Exception $ex) { ob_end_clean(); throw $ex; } $template = ob_get_clean(); return $template; }
/** * This destructor ensures that any resources are properly disposed. * * @access public */ public function __destruct() { unset($this->reader); unset($this->writer); unset($this->pointer); unset($this->length); if ($this->file->exists()) { unlink($this->file); unset($this->file); } }
/** * This method sends the message. * * @access public */ public function send() { header(implode(' ', array($this->protocol, $this->status, static::$statuses[$this->status]))); foreach ($this->headers as $name => $value) { header($name . ': ' . trim($value)); } header('content-length: ' . $this->getLength()); if ($this->body !== null) { echo $this->body->getBytes(); } exit; }
/** * This method renders the data for the writer. * * @access public * @return string the data as string * @throws \Exception indicates a problem occurred * when generating the template */ public function render() { $metadata = $this->metadata; $declaration = $metadata['declaration'] ? Core\Data\XML::declaration($metadata['encoding'][1], $metadata['standalone']) . $metadata['eol'] : ''; if (!empty($metadata['template'])) { $file = new IO\File($metadata['template']); $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($string) use($metadata) { $string = Core\Data\Charset::encode($string, $metadata['encoding'][0], $metadata['encoding'][1]); $string = Core\Data\XML::entities($string); return $string; })); ob_start(); try { echo $declaration; echo $mustache->render($file->getFileName(), $this->data); } catch (\Exception $ex) { ob_end_clean(); throw $ex; } $template = ob_get_clean(); if (!empty($metadata['minify'])) { $template = Minify\XML::minify($template, $metadata['minify']); } return $template; } else { ob_start(); try { $document = new \DOMDocument(); $document->formatOutput = true; $this->toXML($document, $document, $this->data); echo $declaration; echo $document->saveXML(); } catch (\Exception $ex) { ob_end_clean(); throw $ex; } $template = ob_get_clean(); return $template; } }
/** * This method renders the data for the writer. * * @access public * @return string the data as string * @throws \Exception indicates a problem occurred * when generating the template */ public function render() { $declaration = $this->metadata['declaration'] ? '<!DOCTYPE html>' . "\n" : ''; if (!empty($this->metadata['template'])) { $file = new IO\File($this->metadata['template']); $mustache = new \Mustache_Engine(array('loader' => new \Mustache_Loader_FilesystemLoader($file->getFilePath()), 'escape' => function ($string) { return htmlentities($string); })); ob_start(); try { echo $declaration; echo $mustache->render($file->getFileName(), $this->data); } catch (\Exception $ex) { ob_end_clean(); throw $ex; } $template = ob_get_clean(); //if (!empty($this->metadata['minify'])) { // $template = Minify\HTML::minify($template, $this->metadata['minify']); //} return $template; } return $declaration; }
/** * This destructor ensures that any resources are properly disposed. * * @access public */ public function __destruct() { parent::__destruct(); unset($this->error); unset($this->index); unset($this->key); unset($this->post); }
/** * This method returns an instance of the class with the contents of the specified * XML file. * * @access public * @static * @param IO\File $file the input file stream to be used * @return Core\Data\XML an instance of this class * @throws Throwable\InvalidArgument\Exception indicates a data type mismatch * @throws Throwable\FileNotFound\Exception indicates that the file does not exist */ public static function load(IO\File $file) { if (!$file->exists()) { throw new Throwable\FileNotFound\Exception('Unable to locate file. File ":file" does not exist.', array(':file' => $file)); } $buffer = file_get_contents($file); $buffer = preg_replace('/^' . pack('H*', 'EFBBBF') . '/', '', $buffer); if (!preg_match('/^<\\?xml\\s+.+\\?>/', $buffer)) { $buffer = static::declaration(Core\Data\Charset::UTF_8_ENCODING) . "\n" . $buffer; } $xml = new static($buffer); return $xml; }
/** * This destructor ensures that any resources are properly disposed. * * @access public */ public function __destruct() { parent::__destruct(); unset($this->mime); }
/** * This method returns the length of the resource. * * @access public * @return integer the length of the resource */ public function length() { return $this->file->getFileSize(); }
/** * This function will read an image with a Code 39 Barcode and will decode it. * * @access public * @static * @param IO\File $file the image's URI * @return string the decode value */ public static function decode(IO\File $file) { $image = NULL; $ext = $file->getFileExtension(); switch ($ext) { case 'png': $image = imagecreatefrompng($file); break; case 'jpg': $image = imagecreatefromjpeg($file); break; default: throw new Throwable\InvalidArgument\Exception('Unrecognized file format. File name must have either a png or jpg extension.', array('file' => $file)); } $width = imagesx($image); $height = imagesy($image); $y = floor($height / 2); // finds middle $pixels = array(); for ($x = 0; $x < $width; $x++) { $rgb = imagecolorat($image, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $pixels[$x] = ($r + $g + $b) / 3 < 128.0 ? 1 : 0; } $code = array(); $bw = array(); $i = 0; $code[0] = 1; $bw[0] = 'b'; for ($x = 1; $x < $width; $x++) { if ($pixels[$x] == $pixels[$x - 1]) { $code[$i]++; } else { $code[++$i] = 1; $bw[$i] = $pixels[$x] == 1 ? 'b' : 'w'; } } $max = 0; for ($x = 1; $x < count($code) - 1; $x++) { if ($code[$x] > $max) { $max = $code[$x]; } } $code_string = ''; for ($x = 1; $x < count($code) - 1; $x++) { $code_string .= $code[$x] > $max / 2 * 1.5 ? strtoupper($bw[$x]) : $bw[$x]; } // parse code string $msg = ''; for ($x = 0; $x < strlen($code_string); $x += 10) { $msg .= self::$patterns[substr($code_string, $x, 9)]; } return $msg; }
/** * This constructor initializes the class with the specified URI. * * @access public * @param string $prefix the prefix of the generated temporary file * @throws Throwable\InvalidArgument\Exception indicates a data type mismatch */ public function __construct($prefix = '') { parent::__construct(tempnam(static::directory(), $prefix)); $this->temporary = true; }