Пример #1
0
 public function generate($args)
 {
     if (count($args) != 1) {
         die(self::$usageMessage);
     }
     $model = $args[0];
     $table = Str::plural(Str::lower($model));
     $options = array('Model' => $model, 'Table' => $table, 'DefaultField' => 'text', 'ParentID' => 'parent_id', 'Leaf' => 'leaf');
     $r = new ReflectionClass($model);
     preg_match_all('#@(.*?)\\n#s', $r->getDocComment(), $annotations);
     if (!empty($annotations)) {
         foreach ($annotations[0] as $annotation) {
             preg_match('#@(?P<name>\\w+)[ ]*(\\([ ]*(?P<value>\\w+)[ ]*\\))?\\n#s', $annotation, $a);
             if (array_key_exists($a['name'], $options)) {
                 $options[$a['name']] = $a['value'];
             }
         }
     }
     $columns = DB::query('SHOW columns from ' . $table);
     if (Cache::has('ext' . $model, $columns)) {
         $was_cached = true;
     } else {
         Cache::forever('ext' . $model, $columns);
         $was_cached = false;
     }
     // Generate code
     $this->generateExtModel($columns, $model, $options);
     $this->generateGrid($columns, $model, $options, $was_cached);
     $this->generateForm($columns, $model, $options, $was_cached);
     $this->generateTree($model, $options, $was_cached);
     /**************************************************************/
     echo 'Task executed successfully';
 }
Пример #2
0
 public function render()
 {
     $key = md5($this->getPath());
     $lastModified = $this->files->lastModified($this->getPath());
     $generate = false;
     if ($lastModifiedCache = \Cache::get("{$key}.lastmodified", false) !== false && \Cache::has($key)) {
         if ($lastModified !== $lastModified) {
             $generate = true;
         }
     } else {
         $generate = true;
     }
     if (config('app.debug')) {
         $generate = true;
     }
     $rendered = '';
     if ($generate === true) {
         $rendered = $this->parser->parse($this->files->get($this->getPath()));
         \Cache::forever($key, $rendered);
         \Cache::forever("{$key}.lastmodified", $lastModified);
     } else {
         $rendered = \Cache::get($key, false);
     }
     return $rendered;
 }
Пример #3
0
 /**
  * Fetch setting
  *
  * @param $key
  * @return null
  */
 public function get($key)
 {
     /**
      * Setup cache key
      */
     $cacheKey = 'setting_' . md5($key);
     /**
      * Check if in cache
      */
     if (\Cache::has($cacheKey)) {
         return \Cache::get($cacheKey);
     }
     /**
      * Fetch from database
      */
     $setting = Setting::where('key', '=', $key)->first();
     /**
      * If a row was found, return the value
      */
     if (is_object($setting) && $setting->getId()) {
         /**
          * Store in cache
          */
         \Cache::forever($cacheKey, $setting->getValue());
         /**
          * Return the data
          */
         return $setting->getValue();
     }
     return null;
 }
Пример #4
0
 public function testConfigReadsValuesFromCache()
 {
     Cache::forever('config:all', 'foo');
     $config = App::make('App\\Models\\Config');
     $value = $config->all();
     $this->assertSame('foo', $value);
 }
Пример #5
0
 private function _setModuleList()
 {
     if (\Cache::has('modules.backend.list')) {
         $this->_moduleList = \Cache::get('modules.backend.list');
         return;
     }
     $moduleDir = app_path() . '/../modules/';
     $result = array();
     if ($handle = opendir($moduleDir)) {
         while (false !== ($dir = readdir($handle))) {
             if ($dir != '.' && $dir != '..') {
                 if (is_dir($moduleDir . $dir)) {
                     $backendData = false;
                     if (file_exists($moduleDir . $dir . '/backend.json')) {
                         $backendData = json_decode(file_get_contents($moduleDir . $dir . '/backend.json'));
                     }
                     $result[] = ['name' => $dir, "dir" => $moduleDir . $dir, 'backend' => $backendData];
                 }
             }
         }
         closedir($handle);
     }
     $this->_moduleList = $result;
     \Cache::forever('modules.backend.list', $result);
 }
Пример #6
0
 /**
  * Runs all jobs that do not have a cool down.
  * Returns false or the number of executed jobs.
  * 
  * @return boolean|int
  */
 public function run()
 {
     $now = time();
     if ($this->cache->has($this->cacheKey)) {
         $executed = $this->cache->get($this->cacheKey);
         if ($now - $executed < $this->coolDown * 60) {
             return false;
         }
     }
     $this->cache->forever($this->cacheKey, $now);
     $counter = 0;
     foreach ($this->jobs as $name => $jobBag) {
         $job = $this->getOrMake($name);
         $key = $this->makeCacheKey($name);
         $executed = null;
         if ($this->cache->has($key)) {
             $executed = $this->cache->get($key);
             if ($now - $executed < $job->getInterval() * 60) {
                 continue;
             }
         }
         if ($job->getActive()) {
             $now = time();
             $job->run($executed);
             $this->cache->forever($key, $now);
             $counter++;
         }
     }
     return $counter;
 }
Пример #7
0
 /**
  * 设置缓存
  * @param string $cachename
  * @param mixed $value
  * @param int $expired
  * @return boolean
  */
 public static function setCache($cachename, $value, $expired = null)
 {
     $data = array('value' => $value);
     if ($expired) {
         $data['expires_at'] = time() + $expired;
     }
     \Cache::forever($cachename, json_encode($data));
 }
Пример #8
0
 public function update(Request $request)
 {
     $this->authorize('authorizeAccess', 'contactus');
     $this->contactus->update($request->except('_token'));
     $contactInfo = $this->contactus->first();
     \Cache::forget('contactusInfo');
     \Cache::forever('contactusInfo', $contactInfo);
     return redirect()->back()->with('success', 'Contact Us Information has been updated');
 }
Пример #9
0
 private function getDefaultCityList($country_code, $province_code)
 {
     $cityCodes = \Cache::get('bgcountry_city_' . $country_code . '_' . $province_code);
     if (!$cityCodes) {
         $cityCodes = $this->db->table('bgcity')->where(strlen($country_code) == 2 ? 'cty_code_2' : 'cty_code_3', '=', $country_code)->where(strlen($province_code) < 4 ? 'prov_short_code' : 'prov_long_code', '=', $province_code)->orderBy('city_name')->lists('city_name', $this->city_value_field);
         \Cache::forever('bgcountry_city_' . $country_code . '_' . $province_code, $cityCodes);
     }
     return $cityCodes;
 }
Пример #10
0
 public static function get($arrArg = [])
 {
     if (Cache::has('categories')) {
         $cache = Cache::get('categories');
     } else {
         $cache = self::getRecursive($arrArg);
         Cache::forever('categories', $cache);
     }
     return $cache;
 }
Пример #11
0
 /**
  * Cache the data.
  *
  * @param string $index
  * @param array $data
  * @param bool|int $period Hours
  *
  * @return bool
  */
 public function setCache($index, $data, $period = false)
 {
     if (!$this->getCache($index)) {
         $data = serialize($data);
         if (!$period) {
             \Cache::forever($index, $data);
         }
     }
     return false;
 }
Пример #12
0
 public function getList()
 {
     if (\Cache::has('widgets-list')) {
         return \Cache::get('widgets-list');
     } else {
         $lists = $this->model->where('status', 1)->get();
         \Cache::forever($lists, 'widgets-list');
         return $lists;
     }
 }
Пример #13
0
 /**
  * Create a new URL Generator instance.
  *
  * @param  \Illuminate\Routing\RouteCollection $routes
  * @param  \Illuminate\Http\Request $request
  * @return void
  */
 public function __construct(RouteCollection $routes, Request $request)
 {
     parent::__construct($routes, $request);
     if (\Cache::has('assets-cdn::commitID')) {
         $this->commitID = \Cache::get('assets-cdn::commitID');
     } else {
         $this->commitID = exec('git rev-parse HEAD');
         \Cache::forever('assets-cdn::commitID', $this->commitID);
     }
     $this->cdnURL = config('assets-cdn.cdn-url');
 }
Пример #14
0
 public function page($page_index)
 {
     $isSuperAdmin = Auth::user()->isSuperAdmin();
     $cacheKey = sprintf('wall.%d.%d', (bool) $isSuperAdmin, (int) $page_index);
     $wallContent = Cache::get($cacheKey);
     if (empty($wallContent)) {
         $wallContent = View::make('partials.wall.page', array('isSuperAdmin' => $isSuperAdmin, 'page_index' => $page_index))->render();
         Cache::forever($cacheKey, $wallContent);
     }
     return $wallContent;
 }
Пример #15
0
 protected function initShopConfig()
 {
     if (!Cache::get('shop_config')) {
         $shop_config = new Shop_config();
         $shop_config_arr = $shop_config->all()->toArray();
         foreach ($shop_config_arr as $key => $value) {
             $shop_configs[$value['model']][$value['name']] = $value['value'];
         }
         Cache::forever('shop_config', $shop_configs);
     }
 }
Пример #16
0
 /**
  * Возвращает возможные типы (работает только для postgre)
  * 
  * @return array
  */
 public static function getPossibleTypes()
 {
     $types = \Cache::get('MediaType::possibleTypes', array());
     if (empty($types)) {
         $stdTypes = \DB::select('SELECT unnest(enum_range(NULL::mediatypes))');
         foreach ($stdTypes as $type) {
             $types[] = $type->unnest;
         }
         \Cache::forever('MediaType::possibleTypes', $types);
     }
     return $types;
 }
Пример #17
0
function get_option($name)
{
    $cache = Cache::get('system-options');
    if (empty($cache)) {
        $options = App\Option::get(['name', 'value']);
        foreach ($options as $option) {
            $data[$option->name] = $option->value;
        }
        Cache::forever('system-options', $data);
        $cache = Cache::get('system-options');
    }
    return htmlspecialchars_decode($cache[$name]);
}
Пример #18
0
 public function __construct()
 {
     if (!Auth::guest()) {
         $user_id = Auth::user()->id;
         $modules = Cache::get($user_id . 'modules', function () use($user_id) {
             $group_id = Auth::user()->group_id;
             $modules = Group::find($group_id)->modules()->order_by('order', 'asc')->get();
             Cache::forever($user_id . 'modules', $modules);
             return $modules;
         });
         return View::share('navigation_modules', $modules);
     }
 }
Пример #19
0
 public function testRemoveCommand()
 {
     $scannerMock = $this->getMockedScanner($this->getGeneratedFilePath());
     $commandMock = $this->getMockedCommand($scannerMock, [__DIR__ . '/emptyscans']);
     Cache::forever('skimia.assets.collections.builded', ['angularjs', 'jquery']);
     //var_dump(Cache::get('skimia.assets.collections.builded', []));
     $this->invokeCommandWithPrompt($commandMock);
     $this->assertTrue($this->getCommandOutput()->contains('removed collections'));
     //verifie si la question a été posée
     $this->assertTrue($this->getCommandOutput()->contains('<ask>Update Assets'));
     $this->assertTrue(File::exists($this->getGeneratedFilePath()));
     File::delete($this->getGeneratedFilePath());
 }
Пример #20
0
 /**
  * @param $userId
  *
  * @return Collection
  */
 public function capabilities($userId = null)
 {
     $userId = $userId ?: $this->id;
     if (\Cache::has('user_capabilities_' . $userId)) {
         return $value = \Cache::get('user_capabilities_' . $userId);
     }
     $user = static::with(['roles', 'roles.capabilities'])->findOrFail($userId);
     $capabilities = new Collection();
     foreach ($user->roles as $role) {
         $capabilities = $capabilities->merge($role->capabilities);
     }
     \Cache::forever('user_capabilities_' . $userId, $capabilities);
     return $capabilities;
 }
Пример #21
0
 public static function getCategories()
 {
     $arrData = '';
     if (Cache::has('categories')) {
         $arrData = Cache::get('categories');
     } else {
         $categories = Category::orderBy('order_no')->get();
         $arrData = [];
         if (!$categories->isEmpty()) {
             $arrData = $categories->toArray();
         }
         Cache::forever('categories', $arrData);
     }
     return $arrData;
 }
Пример #22
0
 public function post_setAddress()
 {
     $data = Input::all();
     //get user cart cache
     $Cart = Cache::get("user_cart." . Sentry::user()->id);
     switch ($data['type']) {
         case 'delivery':
             $Cart['Addresses']['delivery'] = $data['addrID'];
             break;
         case 'billing':
             $Cart['Addresses']['billing'] = $data['addrID'];
             break;
     }
     Cache::forever("user_cart." . Sentry::user()->id, $Cart);
     $AddressInfo = Address::with(array('getCity', 'getTown'))->where('id', '=', $data['addrID'])->first();
     return Response::eloquent($AddressInfo);
 }
Пример #23
0
 public static function getGoogleDrive()
 {
     if (Cache::has('googleDrive')) {
         return Cache::get('googleDrive');
     } else {
         $googleDrive = self::select('ckey', 'cvalue')->where('active', 1)->where('ckey', 'like', 'google_drive_%')->get();
         if (!$googleDrive->isEmpty()) {
             $arrData = [];
             foreach ($googleDrive as $key) {
                 $arrData[$key->ckey] = $key->cvalue;
             }
             Cache::forever('googleDrive', $arrData);
             return $arrData;
         }
         return [];
     }
 }
Пример #24
0
 public function postSetupNexmo()
 {
     $nexmo_key = Input::get('nexmo_key');
     $nexmo_secret = Input::get('nexmo_secret');
     $nexmo = new NexmoAccount($nexmo_key, $nexmo_secret);
     try {
         // check nexmo credentials
         $credit_balance = $nexmo->getBalance();
         // check db connection
         DB::connection()->getDatabaseName();
         // migrate db
         Artisan::call('migrate');
         // truncate number table
         DB::table('number')->truncate();
         // set nexmo credentials to env
         Cache::forever('NEXMO_KEY', $nexmo_key);
         Cache::forever('NEXMO_SECRET', $nexmo_secret);
         // add numbers to db
         $numbers = $nexmo->getInboundNumbers();
         if ($numbers['count'] > 0) {
             foreach ($numbers['numbers'] as $num) {
                 $number = new Number();
                 $number->number = $num['msisdn'];
                 $number->country_code = $num['country'];
                 $number->type = $num['type'];
                 $number->features = $num['features'];
                 $number->voice_callback_type = $num['voiceCallbackType'];
                 $number->voice_callback_value = $num['voiceCallbackValue'];
                 $number->save();
             }
         }
         // set dn callback url
         // $nexmo->updateAccountSettings(array('drCallBackUrl' => url('callback/dn')));
         Queue::getIron()->addSubscriber('setupDnCallbackUrl', array('url' => url('queue/receive')));
         Queue::push('HomeController@setupDnCallbackUrl', array('nexmo_key' => $nexmo_key, 'nexmo_secret' => $nexmo_secret), 'setupDnCallbackUrl');
         // set balance to cache
         Cache::put('nexmo', $credit_balance, 10);
         if (Auth::check()) {
             return Redirect::to('/');
         }
         return Redirect::to('/register');
     } catch (Exception $e) {
         return Redirect::to('start')->with('message', $e->__toString());
     }
 }
Пример #25
0
 public function getAllStatic()
 {
     if ($this->settings) {
         return $this->settings;
     }
     $cachedVal = \Cache::get('settings');
     if ($cachedVal) {
         return $cachedVal;
     }
     $all = \DB::table('settings')->get();
     $settings = array();
     array_walk($all, function ($val) use(&$settings) {
         $settings[$val['name']] = $val['value'];
     });
     \Cache::forever('settings', $settings);
     $this->settings = $settings;
     return $settings;
 }
Пример #26
0
 function cacheif($condition, $key, Closure $closure)
 {
     if (!$condition) {
         return $closure();
     }
     $content = Cache::get($key);
     if (!$content) {
         ob_start();
         $closure();
         $content = ob_get_contents();
         ob_end_clean();
         Cache::forever($key, $content);
         Log::debug('writing cache', [$key]);
     } else {
         Log::debug('reading cache', [$key]);
     }
     return $content;
 }
Пример #27
0
 public function postLogin()
 {
     $emailOrUsername = Input::get('email');
     $password = Input::get('password');
     //        dd(Hash::make(Input::get('password')));
     if (Auth::attempt(array('username' => $emailOrUsername, 'password' => $password), true)) {
         Cache::forever('username', $emailOrUsername);
         Cache::forever('HId', User::where('username', '=', $emailOrUsername)->first()['id']);
         Cache::forever('HName', User::where('username', '=', $emailOrUsername)->first()['HName']);
         return Redirect::route('hospital-list');
     }
     if (Auth::attempt(array('email' => $emailOrUsername, 'password' => $password), true)) {
         Cache::forever('id', User::where('email', '=', $emailOrUsername)->first()['id']);
         Cache::forever('username', User::where('email', '=', $emailOrUsername)->first()['username']);
         return View::make('supplier');
     }
     return Redirect::route('account-login')->with('global', '用户名或密码错误');
 }
Пример #28
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(Requests\EditAd $request)
 {
     $this->authorize('authorizeAccess', 'ad_edit');
     $ad = $this->ad->where(['id' => $request->get('id')])->first();
     /*
      * Abstract CreateImages Job (Model , $request, FolderName, [FieldsName] , [Default thumbnail sizes] , [Default large sizes]
      * */
     $updateAdImages = $this->dispatch(new CreateImages($ad, $request, 'ads', ['ads'], ['200', '50'], ['500', '120']));
     if ($updateAdImages) {
         $ad->update(['url' => $request->url]);
         $ad->save();
         $allAds = $this->ad->all();
         \Cache::forget('allAds');
         \Cache::forever('allAds', $allAds);
         return redirect()->action('Backend\\AdsController@index')->with(['success' => trans('sucess.updated')]);
     }
     return redirect()->action('Backend\\AdsController@index')->with(['error' => trans('error.updated')]);
 }
Пример #29
0
 public function postResolveNames()
 {
     // Create an array from the ids and make them unique
     $ids = explode(',', Input::get('ids'));
     $ids = array_unique($ids);
     // Set the array that we will eventually return, containing the resolved
     // names
     $return = array();
     // Start by doing a cache lookups for each of the ids to see what we have
     // already resolved
     foreach ($ids as $id) {
         if (Cache::has('nameid_' . $id)) {
             // Retreive the name from the cache and place it in the results.
             $return[$id] = Cache::get('nameid_' . $id);
             // Remove it from the $ids array as we don't need to lookup
             // this one.
             unset($ids[$id]);
         }
     }
     // Check if there is anything left to lookup, and prepare a pheal instance
     // to handle the API call for this
     if (count($ids) > 0) {
         // Get pheal ready
         BaseApi::bootstrap();
         $pheal = new Pheal();
         // Loop over the ids for a max of 30 ids, and resolve the names
         foreach (array_chunk($ids, 15) as $resolvable) {
             // Attempt actual API lookups
             try {
                 $names = $pheal->eveScope->CharacterName(array('ids' => implode(',', $resolvable)));
             } catch (Exception $e) {
                 throw $e;
             }
             // Add the results to the cache and the $return array
             foreach ($names->characters as $lookup_result) {
                 Cache::forever('nameid_' . $lookup_result->characterID, $lookup_result->name);
                 $return[$lookup_result->characterID] = $lookup_result->name;
             }
         }
     }
     // With all the work out of the way, return the $return array as Json
     return Response::json($return);
 }
Пример #30
0
 public function getAllStatic()
 {
     if ($this->translates) {
         return $this->translates;
     }
     $cachedVal = \Cache::get('translations');
     if ($cachedVal) {
         return $cachedVal;
     }
     $all = \DB::table('translations')->get();
     $translations = array();
     foreach ($all as $item) {
         foreach ($this->locales as $locale) {
             $translations[$locale][$item['namespace']][$item['key']] = $item['value_' . $locale];
         }
     }
     \Cache::forever('translations', $translations);
     $this->translates = $translations;
     return $translations;
 }