public function testGetOwner() { Config::shouldReceive('get')->once()->with('auth.model')->andReturn('TestUser'); $stub = m::mock('TestUserTeamTraitStub[hasOne]'); $stub->shouldReceive('hasOne')->once()->with('User', 'user_id', 'owner_id')->andReturn([]); $this->assertEquals([], $stub->owner()); }
/** * List of users * * @return View */ public function index() { $dynamicItems = $this->userRepo->getAllPaginated(50, true); $operationColumn = 'admin.pages.user.partials._operation'; $columns = Config::get('dynamic_data/datatables.users'); return $this->view($this->getView('admin.pages.user.index', 'admin.pages.common.index'), compact('dynamicItems', 'operationColumn', 'columns')); }
function __construct() { $this->default = Config::get("nlp.default"); $this->api_key = Config::get("nlp.connections.{$this->default}.API_KEY"); $this->result_type = \Config::get("nlp.result"); $this->cache_type = \Config::get("nlp.cache"); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = Auth::user(); $pusher = new Pusher(Config::get('services.pusher.key'), Config::get('services.pusher.secret'), Config::get('services.pusher.id')); $pusher->trigger('my-channel', 'my-event', array('message' => $user->name . ': ' . Input::get('msg'), 'user_id' => $user->id)); return 'done'; }
public function __construct() { // setup PayPal api context $paypal_conf = Config::get('paypal'); $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret'])); $this->_api_context->setConfig($paypal_conf['settings']); }
/** * 用户通过邮箱和密码进行登录操作 * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function login(Request $request) { //获取当前访问的全部的地址 $request_url = str_replace("http://" . Config::get('app.url'), "", $request->url()); //验证参数 $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required']); //验证参数完整性 if ($validator->fails()) { // var_dump($validator); $error = $validator->errors()->all(); //写入日志 Log::error(['error' => $error, 'request' => $request->all(), 'header' => $request->headers, 'client_ip' => $request->getClientIp()]); //返回错误信息 return Error::returnError($request_url, 1001); } $email = $request->get('email'); $password = $request->get('password'); //检查有没有 $user_model = User::checkUserLogin($email, $password); if ($user_model == false) { return Error::returnError($request_url, 2001); } //更新token $token = User::updateToken($user_model); //返回对应的结果 $json_arr = ['request' => $request_url, 'ret' => User::getUserInfo($user_model->id), 'token' => $token]; return Common::returnResult($json_arr); }
public function setUp() { // set up config Config::shouldReceive('get')->zeroOrMoreTimes()->with("datatable::engine")->andReturn(array('exactWordSearch' => false)); $this->collection = new Collection(); $this->engine = new CollectionEngine($this->collection); }
protected function bootSilverstripe($url = null) { $flush = $this->option('flush'); // to allow the Silverstripe command line to know what the server URL should be ... // sadly, setting a global $_FILE_TO_URL_MAPPING variable is not enough because Silverstripe's Core.php (or // Constants.php in newer versions) doesn't declare it as global - it assumes it's declared in the // _ss_environment.php file which is _included_ not _required_. Boo. // global $_FILE_TO_URL_MAPPING; // $_FILE_TO_URL_MAPPING[base_path()] = Config::get('app.url'); $base = base_path(); $envPath = $base . '/_ss_environment.php'; if (!file_exists($envPath)) { $appUrl = Config::get('app.url'); file_put_contents($envPath, <<<EOT <?php global \$_FILE_TO_URL_MAPPING; \$_FILE_TO_URL_MAPPING['{$base}'] = '{$appUrl}'; EOT ); App::shutdown(function ($app) use($envPath) { unlink($envPath); }); } // taken from silverstripe's framework/cli-script.php if ($flush) { $_REQUEST['flush'] = $flush === true ? 1 : $flush; $_GET['flush'] = $flush === true ? 1 : $flush; } if ($url) { $_REQUEST['url'] = $url; $_GET['url'] = $url; } Silverstripe::start(); }
public function handle($payload) { $this->folder = $payload['folder']; $this->cleanUp(); if (isset($payload['bucket'])) { Config::set('S3_BUCKET', $payload['bucket']); } if (isset($payload['region'])) { Config::set('S3_REGION', $payload['region']); } if (isset($payload['secret'])) { Config::set('S3_SECRET', $payload['secret']); } if (isset($payload['key'])) { Config::set('S3_KEY', $payload['key']); } if (isset($payload['destination'])) { $this->thumbnail_destination = $payload['destination']; } else { $this->thumbnail_destination = base_path("storage"); } if (!Storage::exists($this->thumbnail_destination)) { Storage::makeDirectory($this->thumbnail_destination, 0755, true); } $files = Storage::disk('s3')->allFiles($this->folder); Log::info(print_r($files, 1)); $this->getAndMake($files); $this->uploadFilesBacktoS3(); $this->cleanUp(); }
/** * Bootstrap the application events. * * @return void */ public function boot() { $this->package('mmanos/laravel-casset'); if ($route = Config::get('laravel-casset::route')) { Route::get(trim($route, '/') . '/{type}', 'Mmanos\\Casset\\CassetController@getIndex'); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $days_to_wait = Config::get('store.days_to_remind'); //\DB::enableQueryLog(); $this->info("Checks If there are orders to be rated ({$days_to_wait} Days Old)"); //Checks all closed orders that has not been rated nor mail has been sent and where updated 5 days ago //and the mails has not been sent yet $orders = Order::where('rate', null)->where('status', 'closed')->where('rate_mail_sent', false)->where('updated_at', '<', Carbon::now()->subDays($days_to_wait))->get(); //$this->info(print_r(\DB::getQueryLog())); $this->info("Orders That need mail: " . $orders->count()); foreach ($orders as $order) { $this->info("Order: " . $order->id . ' Needs to be rated, and mail has not been sent'); $buyer = User::find($order->user_id); if ($buyer) { $email = $buyer->email; $mail_subject = trans('email.cron_emails.remind_rate_order_subject'); $data = ['email_message' => $mail_subject, 'email' => $email, 'subject' => $mail_subject, 'order_id' => $order->id]; Mail::queue('emails.cron.rate_order', $data, function ($message) use($data) { $message->to($data['email'])->subject($data['subject']); }); $order->rate_mail_sent = true; $order->save(); } } }
/** * Route53 constructor. * * @param null $access_key * @param null $secret_key */ public function __construct($access_key = null, $secret_key = null) { $this->access_key = Config::get('aws_sdk.access_key', $access_key); $this->secret_key = Config::get('aws_sdk.secret_key', $secret_key); $this->host = Config::get('aws_sdk.route53_host', 'route53.amazonaws.com'); $this->api_version = self::API_VERSION; }
/** * Register the service provider. * * @return void */ public function register() { $this->app['router']->before(function ($request) { // First clear out all "old" visitors Visitor::clear(); $page = Request::path(); $ignore = Config::get('visitor-log::ignore'); if (is_array($ignore) && in_array($page, $ignore)) { //We ignore this site return; } $visitor = Visitor::getCurrent(); if (!$visitor) { //We need to add a new user $visitor = new Visitor(); $visitor->ip = Request::getClientIp(); $visitor->useragent = Request::server('HTTP_USER_AGENT'); $visitor->sid = str_random(25); } $user = null; $usermodel = strtolower(Config::get('visitor-log::usermodel')); if (($usermodel == "auth" || $usermodel == "laravel") && Auth::check()) { $user = Auth::user()->id; } if ($usermodel == "sentry" && class_exists('Cartalyst\\Sentry\\SentryServiceProvider') && Sentry::check()) { $user = Sentry::getUser()->id; } //Save/Update the rest $visitor->user = $user; $visitor->page = $page; $visitor->save(); }); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (Config::get("customer_portal.ticketing_enabled") !== true) { return redirect()->back()->withErrors(trans("errors.sectionDisabled")); } return $next($request); }
/** * Obtain the user that needs to be notificated on registration * * @return array */ public function getNotificationRegistrationUsersEmail() { $group_name = Config::get('laravel-authentication-acl::permissions.profile_notification_group'); $user_r = App::make('user_repository'); $users = $user_r->findFromGroupName($group_name)->lists('email'); return $users; }
/** * 付款成功通知 * @param $order * @return bool */ public function sendPaidMsg($order) { $seller = $order->shop->seller; if (!$seller->wxUser) { return false; } $wxUser = Buyer::find($order->buyer_id)->wxUser; $this->_newOrderData['touser'] = $seller->wxUser->openId; $this->_newOrderData['template_id'] = Config::get('weixin.template_id.new_order_to_seller'); $this->_newOrderData['url'] = 'http://www.yayao.mobi'; //TODO $this->_newOrderData['data']['keyword1']['value'] = '¥' . $order->amount_tendered; // get order_items $itemsStr = ''; $orderItems = $order->orderItems; foreach ($orderItems as $oi) { $itemsStr .= $oi->name . ' x' . $oi->quantity . ' '; } $this->_newOrderData['data']['keyword2']['value'] = $itemsStr; // 商品名称 $this->_newOrderData['data']['keyword3']['value'] = $order->order_number; // 订单号 $this->_newOrderData['data']['keyword4']['value'] = $wxUser->nickname; $commission = 0; $commissionService = new CommissionService(); $sellerCommission = $commissionService->getSellerCommissionByOrder($seller->id, $order->id); if ($sellerCommission) { $commission = $sellerCommission->amount; } $this->_newOrderData['data']['remark']['value'] = "佣金:¥" . $commission . '。该张订单完成后,店铺提成可以在我的佣金页申请提现。'; $this->_sendTplMsg($this->_newOrderData); return true; }
/** * Dipsplay image for resizing * * @return mixed */ public function getResize() { $ratio = 1.0; $image = Input::get('img'); $dir = Input::get('dir'); $original_width = Image::make(base_path() . "/" . Config::get('lfm.images_dir') . $dir . "/" . $image)->width(); $original_height = Image::make(base_path() . "/" . Config::get('lfm.images_dir') . $dir . "/" . $image)->height(); $scaled = false; if ($original_width > 600) { $ratio = 600 / $original_width; $width = $original_width * $ratio; $height = $original_height * $ratio; $scaled = true; } else { $height = $original_height; $width = $original_width; } if ($height > 400) { $ratio = 400 / $original_height; $width = $original_width * $ratio; $height = $original_height * $ratio; $scaled = true; } return View::make('laravel-filemanager::resize')->with('img', Config::get('lfm.images_url') . $dir . "/" . $image)->with('dir', $dir)->with('image', $image)->with('height', number_format($height, 0))->with('width', $width)->with('original_height', $original_height)->with('original_width', $original_width)->with('scaled', $scaled)->with('ratio', $ratio); }
/** * Get the specified configuration value. * * @param string $key Name of the key * @param mixed $default Default value * @param bool $dbLookup If false, do not access the database table * @return mixed */ public static function get($key, $default = null, $dbLookup = true) { if (installed() and $dbLookup) { $dbChecked = Cache::has(self::CACHE_IN_DB_PREFIX . $key); if ($dbChecked) { $inDb = Cache::get(self::CACHE_IN_DB_PREFIX . $key); if ($inDb) { return Cache::get(self::CACHE_VALUES_PREFIX . $key); } } else { $result = DB::table('config')->whereName($key)->first(); if (is_null($result)) { Cache::put(self::CACHE_IN_DB_PREFIX . $key, false, self::CACHE_TIME); } else { Cache::put(self::CACHE_IN_DB_PREFIX . $key, true, self::CACHE_TIME); Cache::put(self::CACHE_VALUES_PREFIX . $key, $result->value, self::CACHE_TIME); return $result->value; } } } if ((strpos($key, '.') !== false or strpos($key, '::') !== false) and LaravelConfig::has($key)) { return LaravelConfig::get($key, $default); } return $default; }
public function __construct(array $form) { parent::__construct($form); $this->setModel('Clumsy\\FormBuilder\\Models\\ClumsyFormStructure'); $this->setResource(Config::get('clumsy/form-builder::resource')); $this->initializeForms(); }
/** * Returns configuration data * * @static * @param string $key * @return array */ public static function get($key) { if (!isset(static::$cache[$key])) { static::$cache[$key] = parent::get($key); } return static::$cache[$key]; }
/** * Setup for Google API authorization to retrieve directory data */ function __construct() { // set config options $clientId = Config::get('google.client_id'); $serviceAccountName = Config::get('google.service_account_name'); $delegatedAdmin = Config::get('google.admin_email'); $keyFile = base_path() . Config::get('google.key_file_location'); $appName = Config::get('google.app_name'); // array of scopes $scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.readonly'); // Create AssertionCredentails object for use with Google_Client $creds = new \Google_Auth_AssertionCredentials($serviceAccountName, $scopes, file_get_contents($keyFile)); // set admin identity for API requests $creds->sub = $delegatedAdmin; // Create Google_Client to allow making API calls $this->client = new \Google_Client(); $this->client->setApplicationName($appName); $this->client->setClientId($clientId); $this->client->setAssertionCredentials($creds); if ($this->client->getAuth()->isAccessTokenExpired()) { $this->client->getAuth()->refreshTokenWithAssertion($creds); } Cache::forever('service_token', $this->client->getAccessToken()); // Set instance of Directory object for making Directory API related calls $this->service = new \Google_Service_Directory($this->client); }
public function postIndex() { $imagem = Input::file('imagem'); if (is_null($imagem)) { throw new Exception('Você não selecionou um arquivo'); } $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'uploads'; $filename = date('YmdHis') . '_' . $imagem->getClientOriginalName(); if ($imagem->move($destinationPath, $filename)) { //Load view laravel paths $paths = Config::get('view.paths'); //Load file view $file = $paths[0] . DIRECTORY_SEPARATOR . Input::get('view') . '.blade.php'; $html = file_get_contents($file); //Init crawler $crawler = new HtmlPageCrawler($html); //Set filter $filter = '#' . Input::get('id'); //Edit node $crawler->filter($filter)->setAttribute('src', '/uploads/' . $filename); $newHTML = html_entity_decode($crawler->saveHTML()); $newHTML = str_replace('%7B%7B', '{{', $newHTML); $newHTML = str_replace('%7D%7D', '}}', $newHTML); $newHTML = str_replace('%24', '$', $newHTML); $newHTML = str_replace('%20', ' ', $newHTML); $newHTML = str_replace('%7C', '|', $newHTML); //write file file_put_contents($file, $newHTML); return Redirect::back()->with('alert', 'Banner enviado com sucesso!'); } }
/** * Returns the sum of all values a metric has by the hour. * * @param int $hour * * @return int */ public function getValuesByHour($hour) { $dateTimeZone = SettingFacade::get('app_timezone'); $dateTime = (new Date())->setTimezone($dateTimeZone)->sub(new DateInterval('PT' . $hour . 'H')); $hourInterval = $dateTime->format('YmdH'); if (Config::get('database.default') === 'mysql') { if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) { $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = ' . $hourInterval)->groupBy(DB::raw('HOUR(created_at)'))->sum('value'); } elseif ($this->calc_type == self::CALC_AVG) { $value = (int) $this->points()->whereRaw('DATE_FORMAT(created_at, "%Y%m%d%H") = ' . $hourInterval)->groupBy(DB::raw('HOUR(created_at)'))->avg('value'); } } else { // Default metrics calculations. if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) { $queryType = 'sum(metric_points.value)'; } elseif ($this->calc_type == self::CALC_AVG) { $queryType = 'avg(metric_points.value)'; } else { $queryType = 'sum(metric_points.value)'; } $query = DB::select("select {$queryType} as aggregate FROM metrics JOIN metric_points ON metric_points.metric_id = metrics.id WHERE metric_points.metric_id = {$this->id} AND to_char(metric_points.created_at, 'YYYYMMDDHH24') = :timestamp GROUP BY to_char(metric_points.created_at, 'H')", ['timestamp' => $hourInterval]); if (isset($query[0])) { $value = $query[0]->aggregate; } else { $value = 0; } } if ($value === 0 && $this->default_value != $value) { return $this->default_value; } return $value; }
public function register() { $url = parse_url(url()->current()); if (isset($url['path']) && substr($url['path'], 1, 7) == 'backend') { $this->app->register(\Shopvel\ServiceProvider\BackendServiceProvider::class); } else { $this->app->register(\Shopvel\ServiceProvider\FrontendServiceProvider::class); } $loader = \Illuminate\Foundation\AliasLoader::getInstance(); /* * Theme Setup */ $loader->alias('Theme', \Shopvel\Facade\ThemeFacade::class); $this->app->singleton('shopvel.theme', function () { return new \Shopvel\Component\Theme\Themes(); }); $this->app->singleton('view.finder', function ($app) { $paths = $app['config']['view.paths']; return new \Shopvel\Component\Theme\ThemeViewFinder($app['files'], $paths, null, $app['shopvel.theme']); }); $theme = $this->app->make('shopvel.theme'); $theme->set(Config::get('theme.name')); /* * Language Setup */ $loader->alias('Language', \Shopvel\Facade\LanguageFacade::class); $this->app->singleton('shopvel.language', function () { return new \Shopvel\Component\Language\Language(); }); }
public function scopeActive($query) { if ($experiments = Config::get('ab.experiments')) { return $query->whereIn('name', Config::get('ab.experiments')); } return $query; }
/** * Store the job in the database. * * Returns the id of the job. * * @param string $job * @param mixed $data * @param int $delay * * @return int */ public function storeJob($job, $data, $delay = 0) { $payload = $this->createPayload($job, $data); $database = Config::get('database'); if ($database['default'] === 'odbc') { $row = DB::select(DB::raw("SELECT laq_async_queue_seq.NEXTVAL FROM DUAL")); $id = $row[0]->nextval; $job = new Job(); $job->id = $id; $job->status = Job::STATUS_OPEN; $job->delay = $delay; $job->payload = $payload; $job->save(); } else { if ($database['default'] === 'mysql') { $payload = $this->createPayload($job, $data); $job = new Job(); $job->status = Job::STATUS_OPEN; $job->delay = $delay; $job->payload = $payload; $job->save(); $id = $job->id; } } return $id; }
public function saveThumb($thumb) { $root = Config::get('consts.note_root'); $time = time(); ImageService::savePic($root . 'thumb/', $this, $thumb, 'thumb', false, $time, 400, 300); $this->save(); }
public function __construct($appId) { $this->appId = $appId; $this->input = new Input(); $this->http = new ComponentHttp(new ComponentAccessToken()); $this->component_appid = Config::get('wechat.componentAppId'); }
public function boot() { if (!($model = $this->getModelClass())) { return; } parent::boot(); // Flush nested set caches related to the object if (Config::get('app.debug')) { Log::info('Binding heirarchical caches', ['model' => $model]); } // Trigger save events after move events // Flushing parent caches directly causes an infinite recursion $touch = function ($node) { if (Config::get('app.debug')) { Log::debug('Touching parents to trigger cache flushing.', ['parent' => $node->parent]); } // Force parent caches to flush if ($node->parent) { $node->parent->touch(); } }; $model::moved($touch); // Flush caches related to the ancestors $flush = function ($node) { $tags = $this->make($node)->getParentTags(); if (Config::get('app.debug')) { Log::debug('Flushing parent caches', ['tags' => $tags]); } Cache::tags($tags)->flush(); }; $model::saved($flush); $model::deleted($flush); }
/** * Setup the layout used by the controller. * * @return void */ protected function setupLayout() { $this->layout = View::make(Config::get('syntara::views.master')); $this->layout->title = 'VietSol CMS'; $this->layout->breadcrumb = array(); View::share('siteName', 'VietSol CMS'); }