public static function resize($image, $destination, $width, $height, $filter = NULL) { ImageValidate::mustBeImage($image); StringValidate::mustBeNotEmpty($destination, "Destination must not be empty"); $width = (int) $width; $height = (int) $height; IntValidate::mustBePositive($width, "Image width must be a positive number"); IntValidate::mustBePositive($height, "Image height must be a positive number"); $filter = empty($filter) ? \Imagick::FILTER_LANCZOS : $filter; $destDir = dirname($destination); if (!is_dir($destDir)) { if (!@mkdir($destDir, $mode = 0777, $recursive = TRUE)) { throw new \Exception("Could not create directory {$destDir} to save resized image"); } } $resize = new \Imagick(); $resize->readImage($image); $resize->resizeImage($width, $height, $filter, 1, $bestFit = TRUE); $resize->writeImage($destination); $resize->clear(); $resize->destroy(); }
private static function instanceExists($name = NULL) { \apf\validate\String::mustBeNotEmpty($name, "When checking for existing instance, name can't be empty"); return array_key_exists($name, self::$instances); }
public function addSchema($name = NULL) { $name = trim($name); if (strpos($name, ' ')) { throw new \Exception("Schema name must NOT have any spaces in it"); } if (in_array($name, $this->schemas)) { throw new \Exception("Duplicated schema name \"{$name}\""); } $this->schemas[] = \apf\validate\String::mustBeNotEmpty($name, "Schema name can't be empty"); }
public function setName($hostName) { $this->name = StringValidate::mustBeNotEmpty($hostName, $useTrim = TRUE, 'Host name can not be empty'); return $this; }
public function setText($text) { $this->text = ValidateString::mustBeNotEmpty($text, $trim = TRUE, 'Text to translate must be not empty'); return $this; }
public function setURI($uri) { $this->uri = StringValidate::mustBeNotEmpty($uri, $trim = TRUE, 'Asset URI must be not empty'); return $this; }
public static function toSlug($string, $char = '-') { StringValidate::mustBeNotEmpty($string, $trim = TRUE, "Must provide a string to slugify"); $string = preg_replace('/&/', '', $string); $string = preg_replace('/\\W/', $char, self::toAscii($string)); $string = strtolower(preg_replace('/[-]{2,}/', '-', $string)); $string = preg_replace('/[^a-zA-Z0-9\\-]/', '', $string); return trim($string, '-'); }
public function setDatabase($database) { $this->database = StringValidate::mustBeNotEmpty($database, $useTrim = TRUE, 'Database name can not be empty'); return $this; }
public function loadFragmentAsString($name = NULL, $folder = NULL, $data = NULL) { $args = func_get_args(); $data = NULL; if (array_key_exists(2, $args)) { $data = $args[2]; if (empty($data)) { return FALSE; } } String::mustBeNotEmpty($name, "Fragment name must be a non empty string"); if (!String::isString($folder)) { $folder = $this->_controller; } $name = trim($name); $fw = DI::get('config')->framework; if (!isset($fw->fragments) || empty($fw->fragments)) { throw new \Exception("Don't know how to load fragments, no path was specified in configuration"); } $ds = DIRECTORY_SEPARATOR; $fragment = sprintf('%s%s%s%s', Kernel::getAppDir(), $ds, $fw->fragments, $ds); $fragment = sprintf('%s%s%s%s', $fragment, $folder, $ds, $name); $fragment = new \apf\core\File($fragment); $this->assignConfigVars(); ob_start(); if ($this->fragmentDebug) { echo "<div class=\"__apf_fragment_debug\">"; } require $fragment; if ($this->fragmentDebug) { echo "</div>"; } $content = ob_get_contents(); ob_end_clean(); return $content; }