fix: Определения типов
This commit is contained in:
parent
9f6fd74b17
commit
dd74a97894
28 changed files with 334 additions and 249 deletions
|
|
@ -18,7 +18,7 @@
|
|||
* and is licensed under the LGPL. For more information please see
|
||||
* <http://creole.phpdb.org>.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Static class for extracting SQL statements from a string or file.
|
||||
*
|
||||
|
|
@ -30,12 +30,12 @@ namespace ctiso\Tools;
|
|||
use Exception;
|
||||
|
||||
class SQLStatementExtractor {
|
||||
|
||||
|
||||
protected static $delimiter = ';';
|
||||
|
||||
|
||||
/**
|
||||
* Get SQL statements from file.
|
||||
*
|
||||
*
|
||||
* @param string $filename Path to file to read.
|
||||
* @return array SQL statements
|
||||
*/
|
||||
|
|
@ -46,17 +46,17 @@ class SQLStatementExtractor {
|
|||
}
|
||||
throw new Exception("Unable to read file: " . $filename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract statements from string.
|
||||
*
|
||||
*
|
||||
* @param string $buffer
|
||||
* @return array
|
||||
*/
|
||||
public static function extract($buffer) {
|
||||
return self::extractStatements(self::getLines($buffer));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract SQL statements from array of lines.
|
||||
*
|
||||
|
|
@ -64,20 +64,20 @@ class SQLStatementExtractor {
|
|||
* @return array
|
||||
*/
|
||||
protected static function extractStatements($lines) {
|
||||
|
||||
|
||||
$statements = [];
|
||||
$sql = "";
|
||||
|
||||
|
||||
foreach($lines as $line) {
|
||||
|
||||
|
||||
$line = trim($line);
|
||||
|
||||
if (self::startsWith("//", $line) ||
|
||||
|
||||
if (self::startsWith("//", $line) ||
|
||||
self::startsWith("--", $line) ||
|
||||
self::startsWith("#", $line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (strlen($line) > 4 && strtoupper(substr($line,0, 4)) == "REM ") {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -91,19 +91,19 @@ class SQLStatementExtractor {
|
|||
if (strpos($line, "--") !== false) {
|
||||
$sql .= "\n";
|
||||
}
|
||||
|
||||
|
||||
if (self::endsWith(self::$delimiter, $sql)) {
|
||||
$statements[] = self::substring($sql, 0, strlen($sql)-1 - strlen(self::$delimiter));
|
||||
$sql = "";
|
||||
}
|
||||
}
|
||||
return $statements;
|
||||
return $statements;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Some string helper methods
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* Tests if a string starts with a given string.
|
||||
* @param string $check The substring to check.
|
||||
|
|
@ -117,24 +117,24 @@ class SQLStatementExtractor {
|
|||
return (strpos($string, $check) === 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if a string ends with a given string.
|
||||
* @param string $check The substring to check.
|
||||
* @param string $string The string to check in (haystack).
|
||||
* @return boolean True if $string ends with $check, or they are equal, or $check is empty.
|
||||
*/
|
||||
protected static function endsWith($check/*: string*/, $string) {
|
||||
protected static function endsWith(string $check, $string) {
|
||||
if ($check === "" || $check === $string) {
|
||||
return true;
|
||||
} else {
|
||||
return (strpos(strrev($string), strrev($check)) === 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* a natural way of getting a subtring, php's circular string buffer and strange
|
||||
* return values suck if you want to program strict as of C or friends
|
||||
* return values suck if you want to program strict as of C or friends
|
||||
*/
|
||||
protected static function substring($string, $startpos, $endpos = -1) {
|
||||
$len = strlen($string);
|
||||
|
|
@ -152,16 +152,16 @@ class SQLStatementExtractor {
|
|||
}
|
||||
return substr($string, $startpos, $len+1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert string buffer into array of lines.
|
||||
*
|
||||
*
|
||||
* @param string $buffer
|
||||
* @return array string[] lines of file.
|
||||
*/
|
||||
protected static function getLines($buffer) {
|
||||
protected static function getLines($buffer) {
|
||||
$lines = preg_split("/\r?\n|\r/", $buffer);
|
||||
return $lines;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -41,9 +41,8 @@ class TemplateImage
|
|||
public $resource;
|
||||
public $filename;
|
||||
|
||||
function __construct ($template = null)
|
||||
function __construct (?string $template = null)
|
||||
{
|
||||
// assert(is_string($src));
|
||||
if ($template) {
|
||||
$this->data = $template;
|
||||
}
|
||||
|
|
@ -52,27 +51,21 @@ class TemplateImage
|
|||
/**
|
||||
* Путь к изображению
|
||||
*/
|
||||
function resourcePath($path)
|
||||
function resourcePath(string $path)
|
||||
{
|
||||
assert(is_string($path));
|
||||
|
||||
$this->resource = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Путь у шрифтам
|
||||
*/
|
||||
function fontPath($path)
|
||||
function fontPath(string $path)
|
||||
{
|
||||
assert(is_string($path));
|
||||
|
||||
$this->base = $path;
|
||||
}
|
||||
|
||||
function set($name, $value)
|
||||
function set(string $name, $value)
|
||||
{
|
||||
assert(is_string($name));
|
||||
|
||||
$this->context['['.$name.']'] = $this->encode($value);
|
||||
}
|
||||
|
||||
|
|
@ -90,10 +83,8 @@ class TemplateImage
|
|||
/**
|
||||
* Создает изображение из файла
|
||||
*/
|
||||
function imagefromfile($file)
|
||||
function imagefromfile(string $file)
|
||||
{
|
||||
assert(is_string($file));
|
||||
|
||||
$suffix = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if (array_key_exists($suffix, self::$listfiles)) {
|
||||
return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file);
|
||||
|
|
@ -101,17 +92,15 @@ class TemplateImage
|
|||
return null;
|
||||
}
|
||||
|
||||
function getFontFile($name)
|
||||
function getFontFile(string $name)
|
||||
{
|
||||
assert(is_string($name));
|
||||
|
||||
if(array_key_exists(strtolower($name), self::$listfonts)) {
|
||||
return $this->base . self::$listfonts[$name];
|
||||
}
|
||||
return $this->base . 'arial.ttf';
|
||||
}
|
||||
|
||||
function fontSuffix($style)
|
||||
function fontSuffix(array $style)
|
||||
{
|
||||
if($style[0] && $style[1]) return "z";
|
||||
|
||||
|
|
@ -121,7 +110,11 @@ class TemplateImage
|
|||
return "";
|
||||
}
|
||||
|
||||
function imageText($text, $value/*: \stdClass*/)
|
||||
/**
|
||||
* @param string $text
|
||||
* @param object $value
|
||||
*/
|
||||
function imageText($text, $value)
|
||||
{
|
||||
assert(is_string($text));
|
||||
|
||||
|
|
@ -130,29 +123,30 @@ class TemplateImage
|
|||
$fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle));
|
||||
|
||||
$color = intval(substr($value->color, 1), 16);
|
||||
if ($value->align[0]) {
|
||||
if ($value->align[0]) {
|
||||
$align = Drawing::ALIGN_LEFT;
|
||||
} elseif ($value->align[2]) {
|
||||
} elseif ($value->align[2]) {
|
||||
$align = Drawing::ALIGN_RIGHT;
|
||||
} else {
|
||||
$align = Drawing::ALIGN_CENTER;
|
||||
}
|
||||
|
||||
if ($value->valign[0]) {
|
||||
if ($value->valign[0]) {
|
||||
$valign = Drawing::ALIGN_TOP;
|
||||
} elseif ($value->valign[1]) {
|
||||
} elseif ($value->valign[1]) {
|
||||
$valign = Drawing::ALIGN_CENTER;
|
||||
} else {
|
||||
$valign = Drawing::ALIGN_BOTTOM;
|
||||
}
|
||||
|
||||
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
||||
Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text,
|
||||
$value->width, $value->height,
|
||||
$align, $valign);
|
||||
}
|
||||
|
||||
/**
|
||||
* Перекодировка текста
|
||||
* @deprecated
|
||||
*/
|
||||
function encode($text)
|
||||
{
|
||||
|
|
@ -160,6 +154,10 @@ class TemplateImage
|
|||
return $text; //iconv("WINDOWS-1251", "UTF-8", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $new_width
|
||||
* @param int $new_height
|
||||
*/
|
||||
function setSize($new_width, $new_height)
|
||||
{
|
||||
$width = imagesx($this->image);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue