/** * @param string $name * @param int $size * @param string $background_color * @param string $text_color * @param string $font_file * @return ImageManagerStatic * @throws Exception */ public static function create($name = '', $size = 512, $background_color = '#666', $text_color = '#FFF', $font_file = '../../../font/OpenSans-Semibold.ttf') { if (strlen($name) <= 0) { throw new Exception('Name must be at least 2 characters.'); } if ($size <= 0) { throw new Exception('Input must be greater than zero.'); } if ($font_file === '../../../font/OpenSans-Semibold.ttf') { $font_file = __DIR__ . "/" . $font_file; } if (!file_exists($font_file)) { throw new Exception("Font file not found"); } $str = ""; $name_ascii = strtoupper(Str::ascii($name)); $words = preg_split("/[\\s,_-]+/", $name_ascii); if (count($words) >= 2) { $str = $words[0][0] . $words[1][0]; } else { $str = substr($name_ascii, 0, 2); } $img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function ($font) use($size, $text_color, $font_file) { $font->file($font_file); $font->size($size / 2); $font->color($text_color); $font->align('center'); $font->valign('middle'); }); return $img; }
/** * Creates a new Lavary\Menu\MenuItem instance. * * @param string $title * @param string $url * @param array $attributes * @param int $parent * @param \Lavary\Menu\Menu $builder * @return void */ public function __construct($builder, $id, $title, $options) { $this->builder = $builder; $this->id = $id; $this->title = $title; $this->nickname = isset($options['nickname']) ? $options['nickname'] : camel_case(Str::ascii($title)); $this->attributes = $this->builder->extractAttributes($options); $this->parent = is_array($options) && isset($options['parent']) ? $options['parent'] : null; // Storing path options with each link instance. if (!is_array($options)) { $path = array('url' => $options); } elseif (isset($options['raw']) && $options['raw'] == true) { $path = null; } else { $path = array_only($options, array('url', 'route', 'action', 'secure')); } if (!is_null($path)) { $path['prefix'] = $this->builder->getLastGroupPrefix(); } $this->link = $path ? new Link($path) : null; // Activate the item if items's url matches the request uri if (true === $this->builder->conf('auto_activate')) { $this->checkActivationStatus(); } }
/** * Create a new file download response. * * @param \SplFileInfo|string $file * @param string $name * @param array $headers * @param null|string $disposition * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public static function download($file, $name = null, array $headers = array(), $disposition = 'attachment') { $response = new BinaryFileResponse($file, 200, $headers, true, $disposition); if (!is_null($name)) { return $response->setContentDisposition($disposition, $name, Str::ascii($name)); } return $response; }
public function loadApp() { $filename = 'stock-nth.apk'; $headers = array(); $disposition = 'attachment'; $response = new BinaryFileResponse(storage_path() . '/' . $filename, 200, $headers, true); return $response->setContentDisposition($disposition, $filename, Str::ascii($filename)); }
/** * Formatar float para o número de casas decimais correto. * @param $nome * @param $valor * @return string */ protected function formatar($nome, $valor) { $ref = new \ReflectionProperty(get_class($this), $nome); $factory = DocBlockFactory::createInstance(); $info = $factory->create($ref->getDocComment()); // Pegar o tipo da variavel $tipo = $info->getTagsByName('var'); $tipo = count($tipo) == 0 ? 'string' : $tipo[0]->getType(); $tipo = strtolower($tipo); switch ($tipo) { case 'string': case 'string|null': case '\\string': case '\\string|null': $valor = str_replace(['@'], ['#1#'], utf8_encode($valor)); // Ignorar alguns caracteres no ascii $valor = Str::ascii($valor); $valor = str_replace(['&'], ['e'], $valor); $valor = str_replace(['#1#'], ['@'], $valor); // Retornar caracteres ignorados $valor = Str::upper($valor); $valor = trim($valor); // Max $max = $info->getTagsByName('max'); if (count($max) > 0) { $max = intval($max[0]->getDescription()->render()); $valor = trim(substr($valor, 0, $max)); } return $valor; case 'float|null': case 'float': $dec = $info->getTagsByName('dec'); if (count($dec) == 0) { return $valor; } // Valor do @dec $dec = $dec[0]->getDescription()->render(); return number_format($valor, $dec, '.', ''); case 'datetime': case '\\datetime': case '\\datetime|null': case 'date': case 'date|null': case '\\date': case '\\date|null': if (is_int($valor)) { $valor = Carbon::createFromTimestamp($valor); } if (is_string($valor)) { return $valor; } $format = in_array($tipo, ['date', 'date|null', '\\date', '\\date|null']) ? 'Y-m-d' : Carbon::ATOM; return $valor->format($format); default: return $valor; } }
public static function createField($type, $title, $description, $validation = "", $value = "") { $field = new StdClass(); $field->type = $type; $field->name = str_replace("-", "_", str_replace(" ", "_", strtolower(Str::ascii($title)))); $field->title = $title; $field->description = $description; $field->validation = $validation; $field->value = $value; return $field; }
public function setDisposition($disposition) { $filename = basename($this->downloadable->filename()); $filenameFallback = str_replace('%', '', Str::ascii($filename)); if ($filenameFallback == $filename) { $filenameFallback = ''; } $dispositionHeader = $this->headers->makeDisposition($disposition, $filename, $filenameFallback); $this->headers->set('Content-Disposition', $dispositionHeader); return $this; }
public static function normalizeUrl($value) { $value = ltrim(trim($value), '/'); $value = Str::ascii($value); // Convert all dashes/underscores into separator $value = preg_replace('![_]+!u', '-', $value); // Remove all characters that are not the separator, letters, numbers, whitespace or forward slashes $value = preg_replace('![^-\\pL\\pN\\s/\\//]+!u', '', mb_strtolower($value)); // Replace all separator characters and whitespace by a single separator $value = preg_replace('![-\\s]+!u', '-', $value); return $value; }
/** * Create a new file download response. * * @param \SplFileInfo|string $file * @param string $name * @param array $headers * @param string|null $disposition * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function download($file, $name = null, array $headers = [], $options = [], $disposition = 'attachment') { $etag = isset($options['etag']) ? $options['etag'] : false; $last_modified = isset($options['last_modified']) ? $options['last_modified'] : true; !empty($options['cache']) && ($headers = array_merge($headers, ['Cache-Control' => 'private, max-age=3600, must-revalidate', 'Pragma' => 'cache'])); !empty($options['mime_type']) && ($headers = array_merge($headers, ['Content-Type' => $options['mime_type']])); $response = new BinaryFileResponse($file, 200, $headers, true, $disposition, $etag, $last_modified); if (!is_null($name)) { return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name))); } return $response; }
/** * Get ASCII index * @param string $value * @return string */ protected function getAsciiIndex($value) { return Str::ascii($value); }
public function getScheduleTemplateFile() { $template_file = storage_path(_('template') . '_' . LOCALE . '.csv'); if (!file_exists($template_file)) { $file = fopen($template_file, 'c'); $lines = [[_('Title'), _('Description'), _('Begin'), _('End')], [_('SAMPLE TALK (remove this line): Abnormalities on Catalysis'), _('This talk will walk us through some common abnormalities seen in some catalysis processes.'), _('Format: YYYY-MM-DD HH:mm'), _('Format: YYYY-MM-DD HH:mm')]]; foreach ($lines as $line) { array_walk($line, function (&$v) { $v = Str::ascii($v); }); fputcsv($file, $line); } fclose($file); } $download = response()->download($template_file); $download->headers->set('Content-Type', 'text/csv'); return $download; }
public function testStringAscii() { $str1 = 'Με λένε Μάριο!'; $str2 = Str::ascii($str1); $this->assertEquals($str2, 'Me lene Mario!'); }
/** * Translate a UTF-8 value to ASCII **/ public function ascii() { $this->value = Str::ascii($this->value); return $this; }
/** * Transliterate a UTF-8 value to ASCII. * * @return static */ public function toAscii() { return new static(Str::ascii($this->string)); }