Ejemplo n.º 1
0
 /**
  * Get the message data.
  *
  * @param  string $key|null
  * @param  string $default|null
  * @return mixed
  */
 public function data($key = null, $default = null)
 {
     if ($key) {
         return Arr::get($this->data, $key, $default);
     }
     return $this->data;
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $roles = $this->file->getRequire(base_path(config('trust.permissions')));
     $this->call('trust:permissions');
     $all = Permission::all(['id', 'slug']);
     $create = 0;
     $update = 0;
     foreach ($roles as $slug => $attributes) {
         $role = $this->findRole($slug);
         if ($role) {
             if ($this->option('force')) {
                 ++$update;
                 $role->update($attributes + compact('slug'));
             }
         } else {
             ++$create;
             $role = Role::create($attributes + compact('slug'));
         }
         $permissions = array_reduce(Arr::get($attributes, 'permissions', []), function (Collection $result, string $name) use($all) {
             if (hash_equals('*', $name)) {
                 return $all->pluck('id');
             }
             if ($all->count() === $result->count()) {
                 return $result;
             }
             $filtered = $all->filter(function (Permission $permission) use($name) {
                 return Str::is($name, $permission->slug);
             })->pluck('id');
             return $result->merge($filtered);
         }, new Collection());
         $role->permissions()->sync($permissions->toArray());
     }
     $total = $create + $update;
     $this->line("Installed {$total} roles. <info>({$create} new roles, {$update} roles synced)</info>");
 }
 /**
  * Create an instance of the SendGrid Swift Transport driver.
  *
  * @return Transport\SendgridTransport
  */
 protected function createSendgridDriver()
 {
     $config = $this->app['config']->get('services.sendgrid', []);
     $client = new Client(Arr::get($config, 'guzzle', []));
     $pretend = isset($config['pretend']) ? $config['pretend'] : false;
     return new SendgridTransport($client, $config['api_key'], $pretend);
 }
Ejemplo n.º 4
0
 public function setOriginal($data)
 {
     $relations = Arr::get($data, $this->column);
     foreach ($relations as $relation) {
         $this->original[] = array_pop($relation['pivot']);
     }
 }
 /**
  * Run migrations for the specified module.
  *
  * @param string $slug
  *
  * @return mixed
  */
 protected function migrate($slug = null)
 {
     $pretend = Arr::get($this->option(), 'pretend', false);
     if (!is_null($slug) && $this->module->exists($slug)) {
         $path = $this->getMigrationPath($slug);
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         $this->migrator->run($path, $pretend);
         // Once the migrator has run we will grab the note output and send it out to
         // the console screen, since the migrator itself functions without having
         // any instances of the OutputInterface contract passed into the class.
         foreach ($this->migrator->getNotes() as $note) {
             if (!$this->option('quiet')) {
                 $this->line($note);
             }
         }
         // Finally, if the "seed" option has been given, we will re-run the database
         // seed task to re-populate the database, which is convenient when adding
         // a migration and a seed at the same time, as it is only this command.
         if ($this->option('seed')) {
             $this->call('module:seed', ['module' => $slug, '--force' => true]);
         }
     } else {
         $modules = $this->module->all();
         if (count($modules) == 0) {
             return $this->error("Your application doesn't have any modules.");
         }
         $migrationsAll = [];
         foreach ($modules as $module) {
             $path = $this->getMigrationPath($module['slug']);
             $files = $this->migrator->getMigrationFiles($path);
             $ran = $this->migrator->getRepository()->getRan();
             $migrations = array_diff($files, $ran);
             $this->migrator->requireFiles($path, $migrations);
             $migrationsAll = array_merge($migrationsAll, $migrations);
         }
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         sort($migrationsAll);
         $this->migrator->runMigrationList($migrationsAll, $pretend);
         // Once the migrator has run we will grab the note output and send it out to
         // the console screen, since the migrator itself functions without having
         // any instances of the OutputInterface contract passed into the class.
         foreach ($this->migrator->getNotes() as $note) {
             if (!$this->option('quiet')) {
                 $this->line($note);
             }
         }
         // Finally, if the "seed" option has been given, we will re-run the database
         // seed task to re-populate the database, which is convenient when adding
         // a migration and a seed at the same time, as it is only this command.
         if ($this->option('seed')) {
             foreach ($modules as $module) {
                 $this->call('module:seed', ['module' => $module['slug'], '--force' => true]);
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Create a new PDO connection.
  *
  * @param  string $dsn
  * @param  array $config
  * @param  array $options
  * @return PDO
  * @throws Exception
  */
 public function createConnection($dsn, array $config, array $options)
 {
     $username = Arr::get($config, 'username');
     $password = Arr::get($config, 'password');
     $create_pdo = function ($dsn, $username, $password, $options) {
         try {
             $pdo = new PDO($dsn, $username, $password, $options);
         } catch (Exception $e) {
             $pdo = $this->tryAgainIfCausedByLostConnection($e, $dsn, $username, $password, $options);
         }
         $this->isClusterNodeReady($pdo);
         return $pdo;
     };
     if (is_array($dsn)) {
         foreach ($dsn as $idx => $dsn_string) {
             try {
                 return $create_pdo($dsn_string, $username, $password, $options);
             } catch (Exception $e) {
                 if (!$this->causedByLostConnection($e) || $idx >= count($dsn) - 1) {
                     throw $e;
                 }
             }
         }
     }
     return $create_pdo($dsn, $username, $password, $options);
 }
 /**
  * Register new BroadcastManager in boot
  *
  * @return void
  */
 public function boot()
 {
     $self = $this;
     $this->app->make(BroadcastManager::class)->extend('redisreliable', function ($app, $config) use($self) {
         return new RedisReliableBroadcaster($app->make('redis'), Arr::get($config, 'connection'), Arr::get($config, 'sub_min'), Arr::get($config, 'sub_list'));
     });
 }
Ejemplo n.º 8
0
 public function matter(string $key = null, $default = null)
 {
     if ($key) {
         return Arr::get($this->matter, $key, $default);
     }
     return $this->matter;
 }
Ejemplo n.º 9
0
 /**
  * @return array
  */
 public static function getRules($scene = 'saving')
 {
     $rules = [];
     array_walk(static::$_rules, function ($v, $k) use(&$rules, $scene) {
         $rules[$k] = [];
         array_walk($v, function ($vv, $kk) use(&$rules, $scene, $k) {
             if (isset($v['on'])) {
                 $scenes = explode(',', $vv['on']);
                 $rule = Arr::get($vv, 'rule', false);
                 if ($rule && in_array($scene, $scenes)) {
                     $rules[$k][] = $rule;
                 }
             } else {
                 if ($scene == 'saving') {
                     $rule = Arr::get($vv, 'rule', false);
                     if ($rule) {
                         $rules[$k][] = $rule;
                     }
                 }
             }
         });
         if (empty($rules[$k])) {
             unset($rules[$k]);
         } else {
             $rules[$k] = implode('|', $rules[$k]);
         }
     });
     return $rules;
 }
Ejemplo n.º 10
0
 /**
  * Modules of installed or not installed.
  *
  * @param bool $installed
  *
  * @return \Illuminate\Support\Collection
  */
 public function getModules($installed = false)
 {
     if ($this->modules->isEmpty()) {
         if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) {
             (new Collection($directories))->each(function ($directory) use($installed) {
                 if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
                     $package = new Collection(json_decode($this->files->get($file), true));
                     if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) {
                         $module = new Module($name);
                         $module->setAuthor(Arr::get($package, 'authors'));
                         $module->setDescription(Arr::get($package, 'description'));
                         if ($installed) {
                             $module->setInstalled($installed);
                         }
                         if ($entries = data_get($package, 'autoload.psr-4')) {
                             foreach ($entries as $namespace => $entry) {
                                 $module->setEntry($namespace . 'ModuleServiceProvider');
                             }
                         }
                         $this->modules->put($directory, $module);
                     }
                 }
             });
         }
     }
     return $this->modules;
 }
 /**
  * Bootstrap the application services.
  */
 public function boot()
 {
     app('swift.transport')->extend('mailjet', function () {
         $config = $this->app['config']->get('services.mailjet', []);
         return new MailjetTransport(new HttpClient(Arr::get($config, 'guzzle', [])), $config['public'], $config['private']);
     });
 }
Ejemplo n.º 12
0
 /**
  * CurrencyManager constructor.
  *
  * @param  array  $configs
  */
 public function __construct(array $configs)
 {
     $this->default = Arr::get($configs, 'default', 'USD');
     $this->supported = Arr::get($configs, 'supported', ['USD']);
     $this->nonIsoIncluded = Arr::get($configs, 'include-non-iso', false);
     $this->currencies = new CurrencyCollection();
 }
Ejemplo n.º 13
0
 static function larakitRegisterMenuSubpages($package, $alias)
 {
     //автоматическая регистрация дочерних страниц Subpages
     $dir = base_path('vendor/' . $package . '/src/config/larakit/subpages/');
     $dir = HelperFile::normalizeFilePath($dir);
     if (file_exists($dir)) {
         $dirs = rglob('*.php', 0, $dir);
         foreach ($dirs as $d) {
             $d = str_replace($dir, '', $d);
             $d = str_replace('.php', '', $d);
             $d = trim($d, '/');
             $menus_subpages = (array) \Config::get($alias . '::larakit/subpages/' . $d);
             if (count($menus_subpages)) {
                 foreach ($menus_subpages as $page => $items) {
                     $manager = \Larakit\Widget\WidgetSubpages::factory($page);
                     foreach ($items as $as => $props) {
                         $style = Arr::get($props, 'style', 'bg-aqua');
                         $is_curtain = Arr::get($props, 'is_curtain', false);
                         $manager->add($as, $style, $is_curtain);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $response = $next($request);
     $config = Config::get('session');
     $response->headers->setCookie(new Cookie($config['cookie'], $request->cookies->get($config['cookie']), $this->getCookieExpirationDate(), $config['path'], $config['domain'], Arr::get($config, 'secure', false)));
     return $response;
 }
Ejemplo n.º 15
0
 /**
  * Get an element from an array.
  *
  * @param  array  $array
  * @param  string $key     Specify a nested element by separating keys with full stops.
  * @param  mixed  $default If the element is not found, return this.
  *
  * @return mixed
  */
 public static function get($array, $key, $default = null)
 {
     if (is_array($key)) {
         return static::getArray($array, $key, $default);
     }
     return parent::get($array, $key, $default);
 }
Ejemplo n.º 16
0
 /**
  * Get the class's history.
  *
  * @param string|null $type
  *
  * @return array
  */
 public function getHistory($type = null)
 {
     $handle = $this->getHistoryHandle();
     $history = $this->history[$handle];
     $history = Arr::get($history, $type);
     return $history;
 }
Ejemplo n.º 17
0
 /**
  * Get recipe files location
  *
  * @return string
  */
 public function getRecipePath()
 {
     $directory = $this->getDirectoryPath();
     $content = $this->filesystem->get($directory . '/' . self::CONFIGFILE);
     $contentArr = json_decode($content, true);
     return Arr::get($contentArr, 'recipe_path', null);
 }
Ejemplo n.º 18
0
 /**
  * Update documentation.
  *
  * @param  string $doc
  * @param  string $version
  * @return void
  */
 protected function updateDoc($doc, $version = null)
 {
     $path = config('docs.path');
     if (!($data = Arr::get($this->docs->getDocs(), $doc))) {
         return;
     }
     if (!$this->files->exists("{$path}/{$doc}")) {
         $this->git->clone($data['repository'], "{$path}/{$doc}");
     }
     $this->git->setRepository("{$path}/{$doc}");
     $this->git->checkout('master');
     $this->git->pull('origin');
     if ($version) {
         $versions = [$version];
     } else {
         $versions = $this->getVersions();
     }
     foreach ($versions as $version) {
         $this->git->checkout($version);
         $this->git->pull('origin', $version);
         $this->git->checkout($version);
         $storagePath = storage_path("docs/{$doc}/{$version}");
         $this->files->copyDirectory("{$path}/{$doc}", $storagePath);
         $this->docs->clearCache($doc, $version);
     }
 }
Ejemplo n.º 19
0
 public function getConnector()
 {
     $options = Arr::get($this->config, 'options', []);
     $user = $this->request->user();
     $accessControl = Arr::get($this->config, 'accessControl');
     $roots = Arr::get($options, 'roots', []);
     foreach ($roots as $key => $disk) {
         $disk['driver'] = empty($disk['driver']) === true ? 'LocalFileSystem' : $disk['driver'];
         $disk['autoload'] = true;
         if (empty($disk['path']) === false && $disk['path'] instanceof Closure === true) {
             $disk['path'] = call_user_func($disk['path']);
         }
         switch ($disk['driver']) {
             case 'LocalFileSystem':
                 if (strpos($disk['path'], '{user_id}') !== -1 && is_null($user) === true) {
                     continue;
                 }
                 $userId = $user->id;
                 $disk['path'] = str_replace('{user_id}', $userId, $disk['path']);
                 $disk['URL'] = $this->urlGenerator->to(str_replace('{user_id}', $userId, $disk['URL']));
                 if ($this->filesystem->exists($disk['path']) === false) {
                     $this->filesystem->makeDirectory($disk['path'], 0755, true);
                 }
                 $disk = array_merge(['mimeDetect' => 'internal', 'utf8fix' => true, 'tmbCrop' => false, 'tmbBgColor' => 'transparent', 'accessControl' => $accessControl], $disk);
                 break;
         }
         $roots[$key] = $disk;
     }
     $options = array_merge($options, ['roots' => $roots, 'session' => $this->session]);
     return new Connector(new BaseElfinder($options));
 }
Ejemplo n.º 20
0
 static function denormalize($phone)
 {
     $p = self::normalize($phone);
     $length = mb_strlen($p);
     if (6 == $length) {
         $p = '83522' . $p;
         $length = mb_strlen($p);
     }
     $config = \Config::get('larakit::phones.' . $length, []);
     if (!count($config)) {
         return $p;
     }
     $codes = array_keys($config);
     rsort($codes);
     foreach ($codes as $code) {
         if ($code == mb_substr($p, 0, mb_strlen($code))) {
             $mask = Arr::get($config, $code . '.mask');
             $phone_array = str_split(mb_substr($p, mb_strlen($code)));
             $mask_array = str_split($mask);
             foreach ($mask_array as $key => $symbol) {
                 if ('#' == $symbol) {
                     $mask_array[$key] = array_shift($phone_array);
                 }
             }
             return implode('', $mask_array);
         }
     }
     return null;
 }
Ejemplo n.º 21
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $models = ManagerMigrator::get();
     foreach ($models as $class => $migrators) {
         foreach ($migrators as $data) {
             $this->rows = [];
             //            $this->error(str_repeat('=', 80));
             $this->error(str_pad(' ' . $class . ' ', 80, '=', STR_PAD_BOTH));
             //            $this->error(str_repeat('=', 80));
             $vendor = Arr::get($data, 'vendor');
             $type = Arr::get($data, 'type');
             $v = $vendor ? $vendor . '::' : '';
             $key = $v . 'migrator/' . $type;
             $config = \Config::get($key, false);
             if (!$config) {
                 $this->error('Не обнаружен конфиг мигратора ' . $key);
                 continue;
             }
             $indexes = Arr::get($config, 'indexes', []);
             $fields = Arr::get($config, 'fields', []);
             /** @var Model $model */
             $model = new $class();
             $table_name = $model->getTable();
             $this->syncFields($table_name, $fields);
             $this->rows[] = new TableSeparator();
             $this->syncIndexes($table_name, $indexes);
             $this->table(['[#]', 'Тип', 'Имя', 'Дополнительные характеристики', 'Результат'], $this->rows);
         }
     }
     echo PHP_EOL;
     $this->question('Синхронизация зарегистрированных типов структур завершена');
 }
Ejemplo n.º 22
0
 /**
  * Get the core informations to inject in the configuration created.
  *
  * @return array
  */
 protected function getConfigurationInformations()
 {
     // Replace credentials
     $repositoryCredentials = $this->connections->getRepositoryCredentials();
     $name = basename($this->app['path.base']);
     return array_merge($this->connections->getServerCredentials(), ['connection' => preg_replace('/#[0-9]+/', null, $this->connections->getConnection()), 'scm_repository' => Arr::get($repositoryCredentials, 'repository'), 'scm_username' => Arr::get($repositoryCredentials, 'username'), 'scm_password' => Arr::get($repositoryCredentials, 'password'), 'application_name' => $this->command->ask('What is your application\'s name ? (' . $name . ')', $name)]);
 }
Ejemplo n.º 23
0
 public function __construct(array $res)
 {
     $this->index = Arr::get($res, '_index');
     $this->type = Arr::get($res, '_type');
     $this->id = Arr::get($res, '_id');
     $this->source = Arr::get($res, '_source', []);
 }
Ejemplo n.º 24
0
 /**
  * Delete this customer credit card in the billing gateway.
  *
  * @return Creditcard
  */
 public function delete()
 {
     if (!$this->model->readyForBilling()) {
         return $this;
     }
     $this->card->delete();
     $cards = array();
     foreach ($this->model->billing_cards as $c) {
         if (Arr::get($c, 'id') != $this->id) {
             $cards[] = $c;
         }
     }
     $this->model->billing_cards = $cards;
     $this->model->save();
     // Refresh all subscription records that referenced this card.
     if ($subscriptions = $this->model->subscriptionModelsArray()) {
         foreach ($subscriptions as $subscription) {
             if ($subscription->billingIsActive() && $subscription->billing_card == $this->id) {
                 $subscription->subscription()->refresh();
             }
         }
     }
     $this->info = array('id' => $this->id);
     return $this;
 }
Ejemplo n.º 25
0
 /**
  * Create a new menu.
  *
  * @return $this
  */
 public function create()
 {
     $menu = $this->handler->add($this->name, $this->getAttribute('position'))->title($this->getAttribute('title'))->link($this->getAttribute('link'))->handles(Arr::get($this->menu, 'link'));
     $this->attachIcon($menu);
     $this->handleNestedMenu();
     return $this;
 }
Ejemplo n.º 26
0
 /**
  * Run migrations for the specified module.
  *
  * @param  string $slug
  * @return mixed
  */
 protected function migrate($slug)
 {
     if ($this->module->exists($slug)) {
         $pretend = Arr::get($this->option(), 'pretend', false);
         $options = ['pretend' => $pretend];
         $path = $this->getMigrationPath($slug);
         $this->migrator->run($path, $options);
         // Once the migrator has run we will grab the note output and send it out to
         // the console screen, since the migrator itself functions without having
         // any instances of the OutputInterface contract passed into the class.
         foreach ($this->migrator->getNotes() as $note) {
             if (!$this->option('quiet')) {
                 $this->line($note);
             }
         }
         // Finally, if the "seed" option has been given, we will re-run the database
         // seed task to re-populate the database, which is convenient when adding
         // a migration and a seed at the same time, as it is only this command.
         if ($this->option('seed')) {
             $this->call('module:seed', ['module' => $slug, '--force' => true]);
         }
     } else {
         return $this->error("Module does not exist.");
     }
 }
Ejemplo n.º 27
0
 /**
  * Establish a queue connection.
  *
  * @param array $config        	
  * @return \Illuminate\Contracts\Queue\Queue
  */
 public function connect(array $config)
 {
     $config = $this->getDefaultConfiguration($config);
     if ($config['key'] && $config['secret']) {
         $config['credentials'] = Arr::only($config, ['key', 'secret']);
     }
     return new SqsQueue(new SqsClient($config), $config['queue'], Arr::get($config, 'prefix', ''));
 }
Ejemplo n.º 28
0
 private function prepareMethods(\Illuminate\Routing\Route $route)
 {
     $methods = array_diff($route->getMethods(), config('arcanesoft.foundation.routes-viewer.methods.hide', ['HEAD']));
     $colors = config('arcanesoft.foundation.routes-viewer.methods.colors', ['GET' => 'success', 'HEAD' => 'default', 'POST' => 'primary', 'PUT' => 'warning', 'PATCH' => 'info', 'DELETE' => 'danger']);
     return array_map(function ($method) use($colors) {
         return ['name' => $method, 'color' => Arr::get($colors, $method)];
     }, $methods);
 }
Ejemplo n.º 29
0
 function tpl()
 {
     $c = explode('Widget\\Widget', get_called_class());
     $widget_name = Arr::get($c, 1);
     $namespace = Arr::get($c, 0);
     $namespace = str_replace('\\', '', $namespace);
     return ($namespace ? snake_case($namespace, '-') . '::' : '') . '!.widgets.' . snake_case($widget_name);
 }
Ejemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function get($key)
 {
     $expression = A::get($this->expressions, $key, null);
     if (is_null($expression)) {
         throw new MissingExpressionException("Expression {{$key}} is not defined");
     }
     return $expression;
 }