/** * Retrieves the location from the driver MaxMind and returns a location object. * * @param string $ip * * @return Location */ public function get($ip) { $location = new Location(); $settings = $this->config->get('location' . $this->instance->getConfigSeparator() . 'drivers.MaxMind.configuration'); try { if ($settings['web_service']) { $maxmind = new Client($settings['user_id'], $settings['license_key']); } else { $path = app_path('database/maxmind/GeoLite2-City.mmdb'); /* * Laravel 5 compatibility */ if ($this->instance->getConfigSeparator() === '.') { $path = base_path('database/maxmind/GeoLite2-City.mmdb'); } $maxmind = new Reader($path); } $record = $maxmind->city($ip); $location->ip = $ip; $location->isoCode = $record->country->isoCode; $location->countryName = $record->country->name; $location->cityName = $record->city->name; $location->postalCode = $record->postal->code; $location->latitude = $record->location->latitude; $location->driver = get_class($this); } catch (\Exception $e) { $location->error = true; } return $location; }
/** * Determines if a user has certain permission. * If user is not logged then checks for role permission. * * @param $identifier * @param null $arg0 * @param null $arg1 * @param null $arg2 * @param null $arg3 * @param null $arg4 * @return bool */ public function can($identifier, $arg0 = null, $arg1 = null, $arg2 = null, $arg3 = null, $arg4 = null) { $ignoreSuper = $this->ignoreSuper; $this->ignoreSuper = false; $ignoreCallback = $this->ignoreCallback; $this->ignoreCallback = false; if (!is_null($this->user())) { if (!$ignoreSuper) { if ($this->user()->can($this->config->get('rbauth::super_permission'))) { return true; } } if (!$ignoreCallback) { if (isset($this->rules[$identifier])) { if (!is_null($this->route)) { $resolved = $this->resolveFromRoute($this->route, array($arg0, $arg1, $arg2, $arg3, $arg4)); foreach ($resolved as $key => $value) { ${'arg' . $key} = $value; } $this->route = null; } return $this->callCallback($identifier, $arg0, $arg1, $arg2, $arg3, $arg4); } } return $this->user()->can($identifier); } else { $role = $this->roleProvider->getByName($this->config->get('rbauth::default_role')); if ($role) { return $role->can($identifier); } } return false; }
/** * Get the evaluated contents of the view. * * @param string $path * @param array $data * * @throws \Exception * @return string */ public function get($path, array $data = array()) { ob_start(); try { $smarty = new \Smarty(); $smarty->caching = $this->config->get('smarty-view::caching'); $smarty->debugging = $this->config->get('smarty-view::debugging'); $smarty->cache_lifetime = $this->config->get('smarty-view::cache_lifetime'); $smarty->compile_check = $this->config->get('smarty-view::compile_check'); $smarty->error_reporting = $this->config->get('smarty-view::error_reporting'); if (\App::environment('local')) { $smarty->force_compile = true; } $smarty->setTemplateDir($this->config->get('smarty-view::template_dir')); $smarty->setCompileDir($this->config->get('smarty-view::compile_dir')); $smarty->setCacheDir($this->config->get('smarty-view::cache_dir')); $smarty->registerResource('view', new ViewResource()); $smarty->addPluginsDir(__DIR__ . '/plugins'); foreach ((array) $this->config->get('smarty-view::plugins_path', array()) as $pluginPath) { $smarty->addPluginsDir($pluginPath); } foreach ($data as $key => $value) { $smarty->assign($key, $value); } $smarty->display($path); } catch (\Exception $e) { ob_get_clean(); throw $e; } return ltrim(ob_get_clean()); }
/** * Return disabled class name when needed. * * @param string $className * * @return mixed|string */ public function disabled($className = '') { if (!$className) { $className = $this->config->get('crumbs.disabled_item_class'); } return $this->isDisabled() ? $className : ''; }
/** * Get the prepared validation rules. * * @return array */ protected function getPreparedRules() { $forbidden = $this->config->get('config.forbidden_usernames'); $forbidden = implode(',', $forbidden); $this->rules['username'] .= '|not_in:' . $forbidden; return $this->rules; }
/** * Force SSl if it's enabled by the configuration * * @return bool|\Illuminate\HTTP\RedirectResponse|null */ protected function redirect() { if ($this->config->get('larapress.settings.ssl')) { return $this->helpers->forceSSL(); } return false; }
/** * @param Config $config * @param DatabaseManager $database */ public function __construct(Config $config, DatabaseManager $database) { $this->database = $database; $this->entities = new EntityCollection(); $this->entities->setConfig($config->get('auth.multiauth.entities')); $this->identifierKey = $config->get('auth.multiauth.identifier_key'); }
/** * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file * * @return string */ protected function uploadSingleFile($file) { $filename = uniqid() . '.' . $file->getClientOriginalExtension(); $targetDirectory = public_path($this->config->get('paxifi.files.uploads_directory')); $file->move($targetDirectory, $filename); return $this->config->get('app.url') . '/' . basename($targetDirectory) . '/' . $filename; }
public function anyUpload(InterfaceFileStorage $userFileStorage, AmqpWrapper $amqpWrapper, Server $server, UploadEntity $uploadEntity) { /* @var \App\Components\UserFileStorage $userFileStorage */ $responseVariables = ['uploadStatus' => false, 'storageErrors' => [], 'uploadEntities' => []]; if ($this->request->isMethod('post') && $this->request->hasFile('file') && $this->request->file('file')->isValid()) { $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-user-files-to-storage' . DIRECTORY_SEPARATOR; $tmpFilePath = $tmpDir . $this->request->file('file')->getClientOriginalName(); $this->request->file('file')->move($tmpDir, $this->request->file('file')->getClientOriginalName()); $userFileStorage->setValidationRules($this->config->get('storage.userfile.validation')); $newStorageFile = $userFileStorage->addFile($tmpFilePath); if ($newStorageFile && !$userFileStorage->hasErrors()) { /* @var \SplFileInfo $newStorageFile */ // AMQP send $newfile, to servers foreach ($server->all() as $server) { if (count($server->configs) > 0) { foreach ($server->configs as $config) { // Send server and file info to upload queue task $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $config->auth . '@' . $server->host . '/' . trim($config->path, '\\/')])); } } else { // The server has no configuration $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $server->host])); } } $responseVariables['uploadStatus'] = true; } else { $responseVariables['storageErrors'] = $userFileStorage->getErrors(); } if ($this->request->ajax()) { return $this->response->json($responseVariables); } } $responseVariables['uploadEntities'] = $uploadEntity->limit(self::UPLOAD_ENTITIES_LIMIT)->orderBy('created_at', 'DESC')->get(); return $this->view->make('upload.index', $responseVariables); }
public function __construct(Config $config, SessionStore $session) { if ($config->has('ttwitter::config')) { $this->tconfig = $config->get('ttwitter::config'); } else { if ($config->get('ttwitter')) { $this->tconfig = $config->get('ttwitter'); } else { throw new Exception('No config found'); } } $this->debug = isset($this->tconfig['debug']) && $this->tconfig['debug'] ? true : false; $this->parent_config = []; $this->parent_config['consumer_key'] = $this->tconfig['CONSUMER_KEY']; $this->parent_config['consumer_secret'] = $this->tconfig['CONSUMER_SECRET']; $this->parent_config['token'] = $this->tconfig['ACCESS_TOKEN']; $this->parent_config['secret'] = $this->tconfig['ACCESS_TOKEN_SECRET']; if ($session->has('access_token')) { $access_token = $session->get('access_token'); if (is_array($access_token) && isset($access_token['oauth_token']) && isset($access_token['oauth_token_secret']) && !empty($access_token['oauth_token']) && !empty($access_token['oauth_token_secret'])) { $this->parent_config['token'] = $access_token['oauth_token']; $this->parent_config['secret'] = $access_token['oauth_token_secret']; } } $this->parent_config['use_ssl'] = $this->tconfig['USE_SSL']; $this->parent_config['user_agent'] = 'LTTW ' . parent::VERSION; $config = array_merge($this->parent_config, $this->tconfig); parent::__construct($this->parent_config); }
public function __construct(ConfigRepository $config, QueryFormatter $formatter) { $this->_defer = $config->get('dbprofiler.slow.defer', true); $this->_formatter = $formatter; $this->_filename = storage_path('/logs/query.' . date('d.m.y') . '.slow.log'); $this->_time = $config->get('dbprofiler.slow.time', 500); }
/** * Creates an Response object and executes the magic of the LAPI response layer. * * @param \Illuminate\Support\Contracts\ArrayableInterface|array $data * @param int $code * @param \Illuminate\Support\Contracts\ArrayableInterface|array $headers * * @return \Illuminate\Http\Response */ public function make($data, $code = 200, array $headers = array()) { $httpHeaderConfig = $this->config->get('lapi::http_header_parameters'); $headers = array_merge(array($httpHeaderConfig['http_header_contenttype'] => $this->getResponseContentType()), $headers); $data = $this->formatData($data); return new Response($data, $code, $headers); }
/** * Generate a new instance of the EloquentRouteRepository instance * * @param \Leitom\Role\Eloquent\Route $route * @param \Illuminate\Config\repository $config * @return void */ public function __construct(Route $routes, Repository $config) { $this->routes = $routes; $this->config = $config; // Set role sync $this->roleSync = $this->config->get('role::super.admin.sync'); }
/** * Create an instance of EloquentRoleRepository * * @param \Leitom\Role\Eloquent\Role $roles * @param \Illuminate\Config\repository $config * @return void */ public function __construct(Role $roles, Repository $config) { $this->roles = $roles; $this->config = $config; // Set the super admin identifier $this->superAdminIdentifier = $this->config->get('role::super.admin.id'); }
public function it_should_allow_a_put(FakeCacheStore $cache, Config $config) { $config->get(Argument::any())->shouldBeCalled()->willReturn(10); $config->get('forrest.storage.store_forever')->shouldBeCalled()->willReturn(false); $cache->put(Argument::any(), Argument::any(), Argument::type('integer'))->shouldBeCalled(); $this->put('test', 'value'); }
/** * Render the notifications' script tag * * @return string * @internal param bool $flashed Whether to get the * */ public function render() { $notifications = $this->session->get('toastr::notifications'); if (!$notifications) { $notifications = []; } $output = '<script type="text/javascript">'; $lastConfig = []; foreach ($notifications as $notification) { $config = $this->config->get('toastr.options'); if (count($notification['options']) > 0) { // Merge user supplied options with default options $config = array_merge($config, $notification['options']); } // Config persists between toasts if ($config != $lastConfig) { $output .= 'toastr.options = ' . json_encode($config) . ';'; $lastConfig = $config; } // Toastr output $output .= 'toastr.' . $notification['type'] . "('" . str_replace("'", "\\'", $notification['message']) . "'" . (isset($notification['title']) ? ", '" . str_replace("'", "\\'", $notification['title']) . "'" : null) . ');'; } $output .= '</script>'; return $output; }
public function boot(Dispatcher $events, ConfigRepository $config) { $configPath = __DIR__ . '/../../config/dbprofiler.php'; if (function_exists('config_path')) { $publishPath = config_path('dbprofiler.php'); } else { $publishPath = base_path('config/dbprofiler.php'); } $this->publishes([$configPath => $publishPath], 'config'); if (!$config->get('dbprofiler.enabled')) { return; } if ($config->get('dbprofiler.request.enabled')) { $requestHandler = new Handlers\RequestQueryHandler($config); $events->listen(QueryExecuted::class, [$requestHandler, 'handle']); $events->listen('kernel.handled', [$requestHandler, 'onFinish']); } if ($config->get('dbprofiler.all.enabled')) { $allHandler = new Handlers\AllQueryHandler($config, app(QueryFormatter::class)); $events->listen(QueryExecuted::class, [$allHandler, 'handle']); $events->listen('kernel.handled', [$allHandler, 'onFinish']); } if ($config->get('dbprofiler.slow.enabled')) { $slowHandler = new Handlers\SlowQueryHandler($config, app(QueryFormatter::class)); $events->listen(QueryExecuted::class, [$slowHandler, 'handle']); $events->listen('kernel.handled', [$slowHandler, 'onFinish']); } }
/** * Gets the menu items indexed by their name with a value of the title. * * @param array $subMenu (used for recursion) * * @return array */ public function getMenu($subMenu = null) { $menu = array(); if (!$subMenu) { $subMenu = $this->config->get('administrator.menu'); } //iterate over the menu to build the return array of valid menu items foreach ($subMenu as $key => $item) { //if the item is a string, find its config if (is_string($item)) { //fetch the appropriate config file $config = $this->configFactory->make($item); //if a config object was returned and if the permission passes, add the item to the menu if (is_a($config, 'Frozennode\\Administrator\\Config\\Config') && $config->getOption('permission')) { $menu[$item] = $config->getOption('title'); } elseif ($config === true) { $menu[$item] = $key; } } elseif (is_array($item)) { $menu[$key] = $this->getMenu($item); //if the submenu is empty, unset it if (empty($menu[$key])) { unset($menu[$key]); } } } return $menu; }
/** * get config file values and store them in attributes. */ private function readConfigFile() { // reading the config file to be stored in the 'configurations' variable below $configurations = $this->config_reader->get('api'); $this->mappers_base_namespace = $configurations['mappers']; $this->limit = $configurations['limit']; }
/** * Execute the console command. * * @return mixed */ public function fire() { $database = $this->option('database') ?: $this->config->get('database.default'); if (!is_dir(storage_path() . '/aperture')) { mkdir(storage_path() . '/aperture'); } $selection = array(); foreach (scandir(storage_path() . '/aperture', SCANDIR_SORT_DESCENDING) as $file) { if (strpos($file, $this->argument('table') . '_' . $database)) { $selection[] = $file; } } if (count($selection) === 0) { return $this->error('No snapshots found.'); } elseif (count($selection) === 1) { $choice = 0; } else { foreach ($selection as $key => $file) { echo '[' . $key . '] Snapshot from '; $parts = explode('_', $file); echo date('H:i, M jS', $parts[0]) . "\n"; } $choice = (int) $this->ask('Which snapshot do you want to restore from? '); } if ($this->snapshot->hasRows($database, $this->argument('table'), $this->option('chunk')) && !$this->confirm('This will clear any existing data in ' . $this->argument('table') . '. Continue? [y|N]', false)) { return $this->error('Restoration aborted'); } $file = fopen(storage_path() . '/aperture/' . $selection[$choice], 'r'); $this->snapshot->handle = $file; $this->snapshot->restore($database, $this->argument('table'), $this->option('chunk')); fclose($file); $this->info('Snapshot restored!'); }
/** * Handle the event. */ public function handle() { if (!$this->config->get('app.debug') && !$this->session->get(__CLASS__ . 'warned') && $this->request->path() == 'admin/dashboard' && $this->modules->get('anomaly.module.installer')) { $this->session->set(__CLASS__ . 'warned', true); $this->messages->error('streams::message.delete_installer'); } }
/** * Twig compiler. * * @param Twig_Loader_Filesystem $loader * @return Twig_Environment */ public function getTwigCompiler($loader) { $this->twig = new Twig_Environment($loader, array('cache' => storage_path() . '/views', 'autoescape' => false, 'auto_reload' => true)); // Hook twig to do what you want. $hooks = $this->config->get('theme::twig.hooks'); $this->twig = $hooks($this->twig); // Get facades aliases. $aliases = $this->config->get('app.aliases'); // Laravel alias to allow. $allows = $this->config->get('theme::twig.allows'); foreach ($aliases as $alias => $class) { // Nothing allow if not exists in twig config. if (!in_array($alias, $allows)) { continue; } // Clasname with namspacing. $className = '\\' . $alias; // Some method is not in facade like Str. if (!method_exists($className, 'getFacadeRoot')) { $this->twig->addGlobal($alias, new $className()); } else { $this->twig->addGlobal($alias, $className::getFacadeRoot()); } } /*$function = new Twig_SimpleFunction('call', function($function) { $args = func_get_args(); $args = array_splice($args, 1); return call_user_func_array($function, $args); }); $this->twig->addFunction($function);*/ return $this->twig; }
public function __construct(Repository $config) { $this->config = $config; $sid = $this->config->get('twiliosms::sid'); $token = $this->config->get('twiliosms::token'); $this->from = $this->config->get('twiliosms::default_number'); $this->twilio = new \Services_Twilio($sid, $token); }
/** * to get config value via Laravel Config Object * * @param string $key * @return string * @throws Muratsplat\Multilang\Exceptions\MultiLangConfigNotCorrect */ protected function getConfig($key) { $name = $this->config->get('multilang::' . $key); if (is_null($name)) { throw new MultiLangConfigNotCorrect("It looks Multilang configuration is not correct! " . "[{$key}] key is not found MultiLang's configuration."); } return $name; }
/** * Check if the config file exist and return it or * throw an exception. * * @throws Exceptions\MissingConfigurationFileException * * @return array */ public function getConfigurations() { $configurations = $this->configurations->get('cdn'); if (!$configurations) { throw new MissingConfigurationFileException("CDN 'config file' (cdn.php) not found"); } return $configurations; }
public function __construct(Config $config, Cache $cache) { $this->path = $config->get('forrest.storage.path'); $this->cache = $cache; if ($minutes = $config->get('forrest.storage.expire_in')) { $this->minutes = $minutes; } }
/** * Get User * * @return \Illuminate\Contracts\Auth\Authenticatable */ protected function getUser() { if (!$this->user) { $authGuard = $this->config->get('nwlaravel.activity.auth_guard') ?: $this->auth->getDefaultDriver(); $this->user = $this->auth->guard($authGuard)->user(); } return $this->user; }
/** * @param \Illuminate\Http\Request $request * * @return bool */ private function isDebugBarRequest($request) { $enabled = $this->config->get('debugbar.enabled'); if (!$enabled) { return false; } return starts_with($request->path(), $this->config->get('debugbar.route_prefix')); }
protected function setEnvironment() { if ($this->config->has('custom.environment')) { $this->environment = $this->config->get('custom.environment'); } else { $this->environment = $this->config->get('general.environment'); } }
public function __construct(Session $session, Config $config, Auth $auth) { $this->session = $session; $this->timeout = $config->get('session.lifetime') * 60; $this->login = $config->get('liveorletdie.login', 'login'); $this->logout = $config->get('liveorletdie.logout', 'logout'); $this->auth = $auth; }