/** * Str */ public function registerStr() { //Create the Str object $this->app['str'] = new Str(Config::get('application.encoding')); \Str::macro('replaceAccents', function ($value) { return $this->app['str']->replaceAccents($value); }); \Str::macro('arrayStripTags', function ($value) { return $this->app['str']->arrayStripTags($value); }); }
/** * Bootstrap the application events. * * @return void */ public function boot() { $this->package('jlem/fields'); \App::bind('field', function () { return \App::make('Jlem\\Fields\\FormField'); }); \Str::macro('spaceCase', function ($string) { return ucwords(str_replace('_', ' ', \snake_case($string))); }); \App::bind('Jlem\\Fields\\Arguments\\LabelTranslator', \Config::get('fields::config.label_translator')); \App::bind('Jlem\\Fields\\Arguments\\ArgumentMerger', \Config::get('fields::config.argument_merger')); }
protected function setupMacros() { \Str::macro('creditCode', function ($length) { $pool = '123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; return substr(str_shuffle(str_repeat($pool, 5)), 0, $length); }); }
<?php /** * Extend Str class to add number to alpha * * @return string * @author Gat **/ Str::macro('numToAlpha', function ($n) { $r = ''; for ($i = 1; $n >= 0 && $i < 10; $i++) { $r = chr(0x41 + $n % pow(26, $i) / pow(26, $i - 1)) . $r; $n -= pow(26, $i); } return $r; });