/** * Handle the command. * * @return array */ public function handle() { $options = []; $group = null; foreach (explode("\n", $this->options) as $option) { // Find option [groups] if (starts_with($option, '[')) { $group = trans(substr(trim($option), 1, -1)); $options[$group] = []; continue; } // Split on the first ":" if (str_is('*:*', $option)) { $option = explode(':', $option, 2); } else { $option = [$option, $option]; } $key = ltrim(trim(array_shift($option))); $value = ltrim(trim($option ? array_shift($option) : $key)); if ($group) { $options[$group][$key] = $value; } else { $options[$key] = $value; } } return $options; }
/** * Obtain the user information from GitHub. * * @return Response */ public function login_callback($provider) { switch (strtolower($provider)) { case 'facebook': case 'twitter': $user_sso = Socialite::driver(strtolower($provider))->user(); if (str_is(strtolower($provider), 'facebook')) { $result = $this->dispatch(new CreateMemberFromFacebook($user_sso)); } else { $result = $this->dispatch(new CreateMemberFromTwitter($user_sso)); } if ($result['status'] == 'success') { Auth::login($result['data']['data']); if ($result['data']['data']->is_complete) { if (Session::has('redirect')) { $redirect = Session::get('redirect', route('web.home')); Session::remove('redirect'); return redirect()->to($redirect); } else { return redirect()->route('web.home'); } } else { return redirect()->route('web.me.profile.complete'); } } else { return redirect()->route('web.login')->withErrors($result['data']['message']); } break; default: App::abort(404); break; } }
/** * Get current state. * * @return boolean */ public function is() { $this->routes = array(); foreach (func_get_args() as $param) { if (!is_array($param)) { $this->routes[] = $param; continue; } foreach ($param as $p) { $this->routes[] = $p; } } $this->request = Request::path(); $this->parseRoutes(); foreach ($this->routes as $route) { if (!Request::is($route)) { continue; } foreach ($this->bad_routes as $bad_route) { if (str_is($bad_route, $this->request)) { return false; } } return true; } return false; }
function __construct() { //////// // Me // //////// $this->me = null; /////////////////// // Init Template // /////////////////// $this->version = env('WEB_VERSION', 'default'); $this->layout = view($this->version . '.templates.html'); ////////////// // Init API // ////////////// $this->api_url = $this->layout->api_url = env('API_URL', 'http://capcusapi'); $this->api = new \GuzzleHttp\Client(['base_url' => $this->api_url]); //////////////// // Init Alert // //////////////// foreach (Session::all() as $k => $v) { if (str_is('_alert_*', $k)) { $this->layout->{$k} = $v; } } }
function post_login() { $input = request()->input(); /////////////////////// // Validate remotely // /////////////////////// $data['email'] = $input['username']; $data['password'] = $input['password']; $data['grant_type'] = 'password'; $data['key'] = env('CAPCUS_API_KEY', 'qwerty123'); $data['secret'] = env('CAPCUS_API_SECRET', 'qwerty123'); $api_response = json_decode($this->api->post($this->api_url . '/authorized/client', ['form_params' => $data])->getBody()); ////////////// // redirect // ////////////// if (str_is('success', $api_response->status)) { foreach ($api_response->data->whoami->auths as $key => $value) { if (str_is('cms', $value->app)) { Session::put('access_token', $api_response->data->access_token); Session::put('refresh_token', $api_response->data->refresh_token); Session::put('expired_at', $api_response->data->expired_at); Session::put('me', $api_response->data->whoami); Session::put('auth_cms', $value->roles); return redirect()->intended(route('dashboard')); } } } return redirect()->back()->withErrors(new MessageBag(['auth' => "Unauthorized Access"])); }
/** * Dynamically access the user's attributes. * * @param string $key * @return mixed */ public function __get($key) { if (str_is($key, 'id')) { return (string) $this->attributes['_id']; } return $this->attributes[$key]; }
/** * Detect the application's current environment. * * @param array|string $environments * * @return string */ public function detectEnvironment($environments) { $args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null; if (php_sapi_name() == 'cli' && !is_null($value = $this->getEnvironmentArgument($args))) { //running in console and env param is set return $this['env'] = head(array_slice(explode('=', $value), 1)); } else { //running as the web app if ($environments instanceof Closure) { // If the given environment is just a Closure, we will defer the environment check // to the Closure the developer has provided, which allows them to totally swap // the webs environment detection logic with their own custom Closure's code. return $this['env'] = call_user_func($environments); } elseif (is_array($environments)) { foreach ($environments as $environment => $hosts) { // To determine the current environment, we'll simply iterate through the possible // environments and look for the host that matches the host for this request we // are currently processing here, then return back these environment's names. foreach ((array) $hosts as $host) { if (str_is($host, gethostname())) { return $this['env'] = $environment; } } } } elseif (is_string($environments)) { return $this['env'] = $environments; } } return $this['env'] = 'production'; }
public function updated($model) { if (!str_is($model->{$model->getPathField()}, $model->getOriginal($model->getPathField()))) { foreach ($model->children as $x) { $x->save(); } } }
public function __call($method, $parameters) { if (str_is('show*', $method)) { $alias = mb_strtolower(substr($method, 4)); return $this->pageCreateView($this->context, $alias); } throw new BadMethodCallException("Method [{$method}] does not exist."); }
public function testStrIs() { $this->assertTrue(str_is('*.dev', 'localhost.dev')); $this->assertTrue(str_is('a', 'a')); $this->assertTrue(str_is('*dev*', 'localhost.dev')); $this->assertFalse(str_is('*something', 'foobar')); $this->assertFalse(str_is('foo', 'bar')); }
public function allowRules($rule) { $allow = array_first($this->getRules(), function ($index, $instance) use($rule) { if (str_is($instance, $rule)) { return true; } }); return $allow !== null; }
/** * @param $incoming * @param $target * @return bool */ protected function checkPattern($incoming, $target) { if ($this->{$target} !== '*') { if (!str_is($this->{$target}, $incoming) && !str_is($incoming, $this->{$target})) { return false; } } return true; }
/** * Determine whether the given item is currently active. * @param array $item * @param string $url * @return bool */ protected function isActiveItem(array $item, $url) { foreach ($item['active'] as $active) { if (str_is($active, $url)) { return true; } } return false; }
/** * Normalize button input. * * @param TreeBuilder $builder */ public function normalize(TreeBuilder $builder) { $buttons = $builder->getButtons(); foreach ($buttons as $key => &$button) { /* * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /* * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /* * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /* * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /* * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /* * Move all data-* keys * to attributes. */ foreach ($button as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute)); } } /* * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } /* * Use small buttons for trees. */ $button['size'] = array_get($button, 'size', 'xs'); } $builder->setButtons($buttons); }
function getImageGalleryAttribute() { foreach ($this->images as $image) { if (str_is('gallery*', strtolower($image->name))) { $galleries[] = $image; } } return $galleries; }
public function __call($name, $arguments) { foreach ($this->magicCalls() as $pattern => $closure) { if (!str_is($pattern, $name)) { continue; } return call_user_func_array($closure, array_merge([$name], $arguments)); } throw new LegoException("Method `{$name}` not found."); }
/** * Publish a source file and/or pass to $next. * * @param Source $source * @param Closure $next * @param array $excluded * @return mixed */ public function handle(Source $source, Closure $next, ...$excluded) { foreach ($excluded as $pattern) { $value = str_contains($pattern, DIRECTORY_SEPARATOR) ? $source->getPathname() : $source->getFilename(); if (str_is($pattern, $value)) { return; } } $next($source); }
protected function element(array $Element) { $markup = ''; if (str_is('h*', $Element['name'])) { $link = str_replace(' ', '-', strtolower($Element['text'])); $markup = '<a class="header-link" href="#' . $link . '" id="' . $link . '"><i class="glyphicon glyphicon-link"></i></a>'; } $markup .= parent::element($Element); return $markup; }
/** * Remove scope from the query. * * @param \Illuminate\Database\Eloquent\Builder $builder * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function remove(Builder $builder, Model $model) { $query = $builder->getQuery(); $bindingKey = 0; foreach ((array) $query->wheres as $key => $where) { if (str_is('is_admin', $key)) { $this->removeWhere($query, $key); } } }
function scopeInDestinationByIds($q, $v = null) { if (!$v || is_array($v) && empty($v)) { return $q; } else { return $q->whereHas('destinations', function ($q) use($v) { $q->whereIn('destinations.id', is_array($v) ? $v : (str_is('*Collection', get_class($v)) ? $v->toArray() : [$v])); }); } }
/** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { //auto generate cheapest tour $schedule->command('capcus:cheapesttour')->dailyAt('02:00'); $schedule->command('capcus:consolidatehomepage')->dailyAt('01:00'); $env = env('ADS_ENGINE'); if (str_is('on', $env)) { $schedule->command('capcus:calcadsbalance')->dailyAt('00:10'); } }
private function match($pages) { $current_route = $this->app->request->path(); foreach ($pages as $page) { if (str_is($page, $current_route)) { return true; } } return false; }
protected function process($key, $button) { /** * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /** * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /** * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /** * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /** * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /** * Move all data-* keys * to attributes. */ foreach ($button as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute)); } } /** * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } if (isset($button['dropdown'])) { foreach ($button['dropdown'] as $key => &$dropdown) { $dropdown = $this->process($key, $dropdown); } } return $button; }
public function source() { list($controller, $method) = explode('@', \Route::current()->getAction()['controller']); $source = Documenter::showMethod($controller, [$method]); foreach ($this->views as $v) { if (!str_is('*/layout/*', $v)) { $source .= Documenter::showCode($v); } } return $source; }
/** * Set active navbar element as active * * @param $route * @param $name * @return string */ public static function isActive($route, $name) { if (method_exists($route, 'getName')) { if (str_is($name . '*', $route->getName())) { return 'active'; } return ''; } else { return ''; } }
/** * Execute the console command. * * @return mixed */ public function handle() { // ------------------------------------------------------------------------------------------------------------ // GET HEADLINE // ------------------------------------------------------------------------------------------------------------ $headlines = \App\Headline::with('travel_agent')->activeOn(\Carbon\Carbon::now())->orderBy('priority')->get(); $headlines = $headlines->sortByDesc(function ($data) { return $data->travel_agent->active_packages[0]->priority; }); // ------------------------------------------------------------------------------------------------------------ // GET HOMEGRID // ------------------------------------------------------------------------------------------------------------ $homegrids = \App\HomegridSetting::orderby('name')->get(); // get upcoming package schedules $homegrid_destination_ids = new Collection(); foreach ($homegrids as $k => $v) { if (str_is('destination', $v->type)) { $homegrid_destination_ids->push($v->destination); } } if ($homegrid_destination_ids->count()) { $homegrid_destinations = \App\Destination::with('tours', 'tours.schedules')->whereIn('id', $homegrid_destination_ids)->get(); foreach ($homegrids as $k => $v) { $homegrids[$k]->destination_detail = $homegrid_destinations->find($v->destination); } } // ------------------------------------------------------------------------------------------------------------ // QUERY PAKET PROMO TERBARU // ------------------------------------------------------------------------------------------------------------ $tours = \App\Tour::with('destinations', 'schedules', 'destinations.images', 'places', 'places.images', 'travel_agent', 'travel_agent.images', 'images')->has('schedules')->select('tours.*')->join('travel_agencies', 'travel_agencies.id', '=', 'travel_agent_id')->published()->latest('tours.created_at')->limit(8)->groupBy('travel_agent_id')->get(); // ------------------------------------------------------------------------------------------------------------ // GET BLOG TERBARU // ------------------------------------------------------------------------------------------------------------ $articles = Article::with('images')->published()->latest('published_at')->take(6)->get(); // ------------------------------------------------------------------------------------------------------------ // GET USER // ------------------------------------------------------------------------------------------------------------ $total_subscriber = \App\Subscriber::active()->count(); $this->info(' ---------------------------------------------------------------------------------------------- '); $this->info(' BLAST NEWSLETTER '); $this->info(' ---------------------------------------------------------------------------------------------- '); $this->info(' * Sending Newsletter to ' . $total_subscriber . ' subscribers'); \App\Subscriber::with('user')->active()->orderby('id')->chunk(100, function ($subscribers) { foreach ($subscribers as $subscriber) { Mail::queue('web.v4.emails.newsletters.weekly', ['headlines' => $headlines, 'homegrids' => $homegrids, 'tours' => $tours, 'articles' => $articles, 'subscriber' => $subscriber], function ($m) use($subscriber) { $m->to($subscriber->email, $subscriber->user ? $subscriber->user->name : $subscriber->email)->subject('CAPCUS.id - Newsletter Edisi ' . \Carbon\Carbon::now()->year . '.' . \Carbon\Carbon::now()->format('W')); }); $this->info(' * Newsletter sent to ' . $subscriber->email . ' *'); } }); $this->info(' ---------------------------------------------------------------------------------------------- '); $this->info(' BLAST NEWSLETTER COMPLETED'); $this->info(' ---------------------------------------------------------------------------------------------- '); }
/** * Search for and return matching extensions. * * @param mixed $pattern * @param bool $strict * @return ExtensionCollection */ public function search($pattern, $strict = false) { $matches = []; foreach ($this->items as $item) { /* @var Extension $item */ if (str_is($pattern, $item->getProvides())) { $matches[] = $item; } } return self::make($matches); }
/** * Return files of a desired mime type. * * @param $type * @return static|FileCollection */ public function mimeType($type) { $files = []; /* @var FileInterface $item */ foreach ($this->items as $item) { if (str_is($type, $item->getMimeType())) { $files[] = $item; } } return new static($files); }
static function boot() { parent::boot(); Static::observe(new TourSchedulePromoObserver()); Static::observe(new TourScheduleVoucherObserver()); Static::observe(new TourCalculationObserver()); $env = env('ADS_ENGINE'); if (str_is('on', $env)) { Static::observe(new TourAdsObserver()); } Static::observe(new TourObserver()); }
function _resolveAddonNamespace($namespace, $shared) { $shared = $shared ? 'shared' : app('Anomaly\\Streams\\Platform\\Application\\Application')->getReference(); if (!str_is('*.*.*', $namespace)) { throw new \Exception("The namespace should be snake case and formatted like: {vendor}.{type}.{slug}"); } list($vendor, $type, $slug) = array_map(function ($value) { return str_slug(strtolower($value), '_'); }, explode('.', $namespace)); $type = str_singular($type); return [$vendor, $type, $slug, base_path("addons/{$shared}/{$vendor}/{$slug}-{$type}")]; }