Пример #1
0
 public function save($item, $value, $environment, $group, $namespace = null)
 {
     $path = DIR_APPLICATION . '/config/generated_overrides';
     if (!$this->files->exists($path)) {
         $this->files->makeDirectory($path, 0777);
     } elseif (!$this->files->isDirectory($path)) {
         $this->files->delete($path);
         $this->files->makeDirectory($path, 0777);
     }
     if ($namespace) {
         $path = "{$path}/{$namespace}";
         if (!$this->files->exists($path)) {
             $this->files->makeDirectory($path, 0777);
         } elseif (!$this->files->isDirectory($path)) {
             $this->files->delete($path);
             $this->files->makeDirectory($path, 0777);
         }
     }
     $file = "{$path}/{$group}.php";
     $current = array();
     if ($this->files->exists($file)) {
         $current = $this->files->getRequire($file);
     }
     array_set($current, $item, $value);
     $renderer = new Renderer($current);
     return $this->files->put($file, $renderer->render()) !== false;
 }
 /**
  * Magic Method allows for user input to set a value inside the options array.
  *
  * @param $option
  * @param $value
  *
  * @throws InvalidPrice
  * @throws InvalidQuantity
  * @throws InvalidTaxableValue
  */
 public function __set($option, $value)
 {
     switch ($option) {
         case CartItem::ITEM_QTY:
             if (!is_numeric($value) || $value < 0) {
                 throw new InvalidQuantity('The quantity must be a valid number');
             }
             break;
         case CartItem::ITEM_PRICE:
             if (!is_numeric($value)) {
                 throw new InvalidPrice('The price must be a valid number');
             }
             break;
         case CartItem::ITEM_TAX:
             if (!empty($value) && (!is_numeric($value) || $value > 1)) {
                 throw new InvalidTaxableValue('The tax must be a float less than 1');
             }
             break;
         case CartItem::ITEM_TAXABLE:
             if (!is_bool($value) && $value != 0 && $value != 1) {
                 throw new InvalidTaxableValue('The taxable option must be a boolean');
             }
             break;
     }
     array_set($this->options, $option, $value);
     if (is_callable([$this, 'generateHash'])) {
         $this->generateHash();
     }
 }
Пример #3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $input = $request->all();
     array_set($input, 'match.id', $request->route('matchId'));
     $request->replace($input);
     return $next($request);
 }
Пример #4
0
 public static function set($identifier, $value)
 {
     $key = $identifier;
     // Initiates everything
     static::load();
     array_set($key, static::$stack);
 }
 public function checkout($attributes)
 {
     return DB::transaction(function ($attributes) use($attributes) {
         $shipping_address_same_as_billing_address = array_get($attributes, 'shipping_address_same_as_billing_address', false);
         if ($shipping_address_same_as_billing_address) {
             array_set($attributes, 'shipping_address_first_name', array_get($attributes, 'billing_address_first_name'));
             array_set($attributes, 'shipping_address_last_name', array_get($attributes, 'billing_address_last_name'));
             array_set($attributes, 'shipping_address_company', array_get($attributes, 'billing_address_company'));
             array_set($attributes, 'shipping_address_address_1', array_get($attributes, 'billing_address_address_1'));
             array_set($attributes, 'shipping_address_address_2', array_get($attributes, 'billing_address_address_2'));
             array_set($attributes, 'shipping_address_city', array_get($attributes, 'billing_address_city'));
             array_set($attributes, 'shipping_address_postal_code', array_get($attributes, 'billing_address_postal_code'));
             array_set($attributes, 'shipping_address_country_id', array_get($attributes, 'billing_address_country_id'));
             array_set($attributes, 'shipping_address_zone_id', array_get($attributes, 'billing_address_zone_id'));
         }
         $order = $this->create($attributes);
         //add line items
         $line_items = [];
         foreach (array_get($attributes, 'line_items', []) as $line_item) {
             $line_items[] = new LineItem($line_item);
         }
         $order->lineItems()->saveMany($line_items);
         //add totals
         $totals = [];
         foreach (array_get($attributes, 'totals', []) as $total) {
             $totals[] = new OrderTotal($total);
         }
         $order->totals()->saveMany($totals);
         return $order;
     });
 }
 protected function fixRequestForArrayFields(SS_HTTPRequest $request)
 {
     $postVars = $request->postVars();
     $fileVars = array_intersect_key($postVars, $_FILES);
     $fieldName = $this->owner->Name;
     foreach ($fileVars as $name => $attributes) {
         $nameParts = explode('][', trim(substr($fieldName, strlen($name) + 1), ']'));
         $newAttributes = [];
         $newValue = [];
         $values = null;
         foreach ($attributes as $attributeName => $attributeValues) {
             $values = array_get($attributeValues, implode('.', $nameParts));
             if (!$values || is_array($values) && empty($values)) {
                 break;
             }
             array_set($newAttributes, implode('.', $nameParts) . '.' . $attributeName, $values);
             $newValue[$attributeName] = $values;
         }
         if (!$values) {
             continue;
         }
         $postVars[$name] = $newAttributes;
         $postVars[$fieldName] = $newValue;
     }
     return new SS_HTTPRequest($request->httpMethod(), $request->getURL(true), $request->getVars(), $postVars, $request->getBody());
 }
Пример #7
0
 /**
  * Set a configuration item's value.
  *
  * <code>
  *      // Set the "session" configuration array
  *      Config::set('session', $array);
  *
  *      // Set a configuration option that belongs by a bundle
  *      Config::set('admin::names.first', 'Taylor');
  *
  *      // Set the "timezone" option in the "application" configuration file
  *      Config::set('application.timezone', 'UTC');
  * </code>
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return void
  */
 public static function set($key, $value, $persistence = true)
 {
     list($bundle, $file, $item) = static::parse($key);
     static::load($bundle, $file);
     // If the item is null, it means the developer wishes to set the entire
     // configuration array to a given value, so we will pass the entire
     // array for the bundle into the array_set method.
     if (is_null($item)) {
         // @TODO handle saving of
         // nested array configuration
         array_set(static::$items[$bundle], $file, $value);
     } else {
         if ($persistence) {
             $setting = Model\Setting::where_slug($item)->first();
             if (!empty($setting)) {
                 array_set(static::$items[$bundle][$file], $item, $value);
                 $setting->value = $value;
                 $setting->save();
             } else {
                 \Log::error('"' . __CLASS__ . '": Trying to persist a non existent setting "' . $item . '".');
                 return null;
             }
         } else {
             array_set(static::$items[$bundle][$file], $item, $value);
         }
     }
 }
 /**
  * Create's an application form.
  *
  * @param User $user
  * @param array $attributes
  * @return mixed
  */
 public function create(User $user, $attributes = array())
 {
     array_set($attributes, 'user_id', $user->id);
     $application = Application::create($attributes);
     Event::fire(new ApplicationSubmittedEvent($application));
     return $application;
 }
 protected function fixTrackingCode()
 {
     $this->output(t('Updating tracking code.'));
     $service = \Core::make('site');
     $site = $service->getDefault();
     $config = $site->getConfigRepository();
     $proceed = true;
     $tracking = $config->get('seo.tracking');
     if (is_array($tracking) && isset($tracking['header']) && $tracking['header']) {
         $proceed = false;
     }
     if (is_array($tracking) && isset($tracking['footer']) && $tracking['footer']) {
         $proceed = false;
     }
     if ($proceed) {
         // we saved it in the wrong place on the 8.0 upgrade.
         $tracking = (array) \Config::get('concrete.seo.tracking', []);
         $trackingCode = array_get($tracking, 'code');
         if (!is_array($trackingCode)) {
             array_set($tracking, 'code', ['header' => '', 'footer' => '']);
             $trackingCode = (string) $trackingCode;
             switch (array_get($tracking, 'code_position')) {
                 case 'top':
                     array_set($tracking, 'code.header', $trackingCode);
                     break;
                 case 'bottom':
                 default:
                     array_set($tracking, 'code.footer', $trackingCode);
                     break;
             }
         }
         unset($tracking['code_position']);
         $config->save('seo.tracking', $tracking);
     }
 }
Пример #10
0
 /**
  * @return Array
  */
 public function getPreJson()
 {
     $result = [];
     $group = '';
     $g = 0;
     foreach ($this->stack as $item) {
         switch ($item['style']) {
             case 'group':
                 $name = 'group_' . $item['name'];
                 $group = $group == '' ? $name : $group . '.' . $name;
                 array_set($result, $group . '._time', $item['time']);
                 break;
             case 'groupend':
                 $group = substr($group, 0, strrpos($group, '.'));
                 break;
             default:
                 $keyName = $group == '' ? '' : $group . '.';
                 $name = $item['name'] ? $item['name'] : 'nn_' . ++$g;
                 $keyName .= str_slug($item['style'] . '_' . $name, '_');
                 if (isset($item['value'])) {
                     array_set($result, $keyName, $item['value']);
                 }
                 break;
         }
     }
     return $result;
 }
Пример #11
0
 private function appendFields($form, $inputs, $values)
 {
     foreach ($inputs as $name => $arg) {
         preg_match("/^([^[]+)\\[(.+)\\]\$/", $name, $m);
         if (!empty($m)) {
             $seq = (int) $m[2];
             $value = array_get($values, "{$m['1']}.{$seq}");
             $name = $m[1] . '[]';
         } else {
             $value = array_get($values, $name);
         }
         $arg['name'] = $name;
         $type = array_get($arg, '_type');
         unset($arg['_type']);
         array_set($arg, 'value', $value);
         $uio = 'form' . ucfirst($type);
         $input = uio($uio, $arg);
         $field = $this->wrapInput($name, $input);
         $sectionName = array_get($arg, '_section');
         unset($arg['_section']);
         $style = array_get($this->arguments, 'type', 'panel');
         $section = $this->getSection($form, $sectionName, $style);
         $field->appendTo($section);
     }
 }
Пример #12
0
 protected static function beforeOrAfterDotNotation(&$array, $key, $value, $keyNeighbor = null, $after = false)
 {
     if (is_null($keyNeighbor)) {
         return $after ? static::set($array, $key, $value) : static::prepend($array, $value, $key);
     }
     $segments = explode('.', $keyNeighbor);
     $keyNeighborLast = array_pop($segments);
     if (count($segments) > 0) {
         $leveledKey = implode('.', $segments);
         $leveledArray = array_get($array, $leveledKey);
         if (!is_array($leveledArray)) {
             return $array;
         }
     } else {
         $leveledKey = null;
         $leveledArray =& $array;
     }
     $keyNeighborIndex = array_search($keyNeighborLast, array_keys($leveledArray));
     if ($keyNeighborIndex !== false) {
         if (isset($leveledArray[$key])) {
             unset($leveledArray[$key]);
         }
         $leveledArray = array_slice($leveledArray, 0, $keyNeighborIndex + ($after ? 1 : 0)) + [$key => $value] + array_slice($leveledArray, $keyNeighborIndex);
     } else {
         array_set($leveledArray, $key, $value);
     }
     return array_set($array, $leveledKey, $leveledArray);
 }
Пример #13
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->config = $this->getConfig();
     $opts = $this->option();
     if ($opts['forget']) {
         if (isset(array_dot($this->config)[$opts['forget']])) {
             $keys = explode('.', $opts['forget']);
             array_forget($this->config, $opts['forget']);
             if (empty($this->config[$keys[0]])) {
                 DB::table('config')->where('name', $keys[0])->delete();
             } else {
                 DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]);
             }
             $this->info($opts['forget'] . ' removed.');
         }
         return $this->showList();
     }
     if ($opts['key'] && $opts['value']) {
         $value = trim($opts['value']);
         if (in_array($value, ['true', 'false', '0', '1'])) {
             $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
         }
         $old_config = $this->config;
         array_set($this->config, $opts['key'], $value);
         $keys = explode('.', $opts['key']);
         if (isset($old_config[$keys[0]])) {
             //update
             DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]);
         } else {
             //insert
             DB::table('config')->insert(['name' => $keys[0], 'value' => serialize($this->config[$keys[0]])]);
         }
     }
     return $this->showList();
 }
Пример #14
0
 /**
  * @param null $connection
  * @return bool
  * @throws \Exception
  */
 public function send($connection = null)
 {
     $notifiers = Config::get('notifiers');
     if (!is_null($connection) && array_has($notifiers, $connection)) {
         $notifiers = array_only($notifiers, [$connection]);
     }
     $factory = new NotifyMeFactory();
     $successes = 0;
     foreach ($notifiers as $notifier) {
         if ($this->sender) {
             array_set($notifier, 'from', $this->sender);
         }
         $service = $factory->make($notifier);
         switch (array_get($notifier, 'driver')) {
             case 'hipchat':
                 $response = $service->notify(array_get($notifier, 'room'), $this->message);
                 break;
             default:
                 throw new \Exception("Driver not yet supported.");
         }
         if ($response->isSent()) {
             $successes++;
         } else {
             throw new \Exception($response->message());
         }
     }
     return $successes == count($notifiers);
 }
Пример #15
0
 /**
  * Add an element to an array using "dot" notation if it doesn't exist.
  *
  * @param  array   $array
  * @param  string  $key
  * @param  mixed   $value
  * @return array
  */
 function array_add($array, $key, $value)
 {
     if (is_null(array_get($array, $key))) {
         array_set($array, $key, $value);
     }
     return $array;
 }
Пример #16
0
 protected function processGroup($group, $lines)
 {
     // Do nothing if there is no line
     if (empty($lines) || is_string($lines)) {
         return;
     }
     array_set($this->missing, $group, array());
     $this->line("Processing {$group} group...");
     $this->progress->start($this->output, count($lines, COUNT_RECURSIVE));
     // Iterate over passed lines
     foreach ($lines as $line => $translation) {
         // Run recursive if translation is an array
         if (is_array($translation)) {
             $this->processGroup($group . '.' . $line, $line);
         } else {
             if ($this->manager->findLineCount($group, $line) == 0) {
                 array_push($this->missing[$group], $line);
             }
             $this->progress->advance();
         }
     }
     $this->line(" ");
     // Add line break to stop lines from joining
     if ($missing = array_get($this->missing, $group)) {
         foreach ($missing as $m) {
             if ($this->input->getOption('silent') or $confirm = $this->confirm("{$group}.{$m} is missing. Remove? [yes/no]")) {
                 $this->manager->removeLine($group, $m);
                 $this->info("Removed {$m} from {$group}");
             }
         }
     }
 }
Пример #17
0
 /**
  * Store value into registry
  *
  * @param  string $key
  * @param  mixed  $value
  *
  * @return bool
  */
 public function set($key, $value)
 {
     list($baseKey, $searchKey) = $this->fetchKey($key);
     $existingValue = $this->get($baseKey);
     if ($baseKey != $searchKey) {
         $object = !is_null($existingValue) && is_array($existingValue) ? $existingValue : [];
         $level = '';
         $keys = explode('.', $searchKey);
         foreach ($keys as $key) {
             $level .= '.' . $key;
             if (trim($level, '.') == $searchKey) {
                 array_set($object, trim($level, '.'), $value);
             } else {
                 array_set($object, trim($level, '.'), []);
             }
         }
         $value = $object;
     }
     if (!is_null($existingValue)) {
         $this->app['db']->table($this->table)->where('key', '=', $baseKey)->update(['value' => json_encode($value)]);
     } else {
         $this->app['db']->table($this->table)->insert(['key' => $baseKey, 'value' => json_encode($value)]);
     }
     $this->cacheData[$baseKey] = $value;
     Cache::forever($this->cache, $this->cacheData);
     return true;
 }
 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function index()
 {
     // dd(hash_file('crc32b', app_path('Support/helpers.php')));
     // hash_file(app_path(), filename);
     // dd(disk_free_space('/') / disk_total_space('/') * 100);
     function outputList($list)
     {
         $out = '<ul>';
         foreach ($list as $key => $value) {
             $out .= '<li class="' . (is_array($value) ? 'array' : 'string') . '">';
             $out .= '<h2 style="display:inline;">' . $key . '</h2> ';
             $out .= is_array($value) ? outputList($value) : $value;
             $out .= '</li>';
         }
         $out .= '</ul>';
         return $out;
     }
     // $trans = trans('copy.site.title');
     // $output = [];
     // foreach ($trans as $key => $value) {
     // 	$output[md5($key)] = $key;
     // }
     // return $output;
     // return $trans;
     $lang = ['passwords' => trans('passwords'), 'pagination' => trans('pagination'), 'validation' => trans('validation'), 'copy' => trans('copy')];
     $langDot = array_dot($lang);
     $langFinal = [];
     foreach ($langDot as $key => $value) {
         array_set($langFinal, $key, $value);
     }
     $langinfo = outputList($langFinal);
     return $this->view('welcome')->with('langinfo', $langinfo);
 }
Пример #19
0
 /**
  * Return the tag links.
  *
  * @param array $attributes
  * @return string
  */
 public function tagLinks(array $attributes = [])
 {
     array_set($attributes, 'class', array_get($attributes, 'class', 'label label-default'));
     return array_map(function ($label) use($attributes) {
         return $this->html->link(implode('/', [$this->config->get('anomaly.module.posts::paths.module'), $this->config->get('anomaly.module.posts::paths.tag'), $label]), $label, $attributes);
     }, (array) $this->object->getTags());
 }
Пример #20
0
 public function sendHeader()
 {
     // session必须要先于header处理
     // 否则会覆盖header内对于Cache-Control的处理
     if ($this->session) {
         if (!isset($_SESSION)) {
             session_start();
         }
         foreach ($this->session as $sess) {
             list($path, $val) = $sess;
             array_set($_SESSION, $path, $val);
         }
         $this->session = array();
     }
     foreach ($this->cookie as $name => $config) {
         list($value, $expire, $path, $domain, $secure, $httponly) = $config;
         setCookie($name, $value, $expire, $path, $domain, $secure, $httponly);
     }
     $this->cookie = array();
     if (is_integer($this->code) && $this->code != 200) {
         if ($status = self::httpStatus($this->code)) {
             header($status);
         }
     }
     foreach ($this->header as $name => $value) {
         $header = $value === null ? $name : $name . ': ' . $value;
         header($header);
     }
     $this->header = array();
     return $this;
 }
Пример #21
0
 public function set($key, $value = null)
 {
     if (func_num_args() == 1 && !empty($this->hold_key_name)) {
         return $this->set($this->hold_key_name, $key);
     }
     return array_set($this->items, $key, $value);
 }
Пример #22
0
 /**
  * 사용자가 위젯 설정 페이지에 입력한 설정값을 저장하기 전에 전처리 한다.
  *
  * @param array $inputs 사용자가 입력한 설정값
  *
  * @return array
  */
 public function resolveSetting(array $inputs = [])
 {
     $content = array_get($inputs, 'content');
     //$content = '<![CDATA['.$content.']]>';
     array_set($inputs, 'content', $content);
     return $inputs;
 }
Пример #23
0
 /**
  * Set a URL segment OR query string using "dot" notation.
  *
  * <code>
  * // Set the name of service.
  * $this->set('name', 'place');
  * </code>
  *
  * @param  string $key
  * @param  string $val
  * @return array
  */
 public function set($key, $val)
 {
     if (isset($this->segments[$key])) {
         return $this->segments = array_set($this->segments, $key, $val);
     }
     return $this->query = array_set($this->query, $key, $val);
 }
Пример #24
0
 public function render()
 {
     $this->loadFiles();
     $args = $this->arguments;
     $seq = $this->seq();
     // set default file upload options
     $fileuploadOptions = ['previewMaxWidth' => 280, 'previewMaxHeight' => 120, 'previewCrop' => false, 'autoUpload' => false, 'acceptFileTypes' => "(\\.|\\/)(.*)\$", 'maxFileSize' => 5000000, 'replaceFileInput' => false, 'disableImageResize' => true, 'imageCrop' => false, 'imageMaxWidth' => 480, 'imageMaxHeight' => 240];
     // set file
     if (isset($args['file'])) {
         $file = File::find($args['file']);
         if ($file === null) {
             unset($args['file']);
         } else {
             $filename = $file->clientname;
             $args['file'] = $filename;
         }
     }
     // resolve arguments
     $fileuploadOptions = array_merge($fileuploadOptions, array_get($args, 'fileuploadOptions', []));
     $args = array_add($args, 'width', 420);
     $args = array_add($args, 'height', 240);
     array_set($fileuploadOptions, 'previewMaxWidth', $args['width']);
     array_set($fileuploadOptions, 'previewMaxHeight', $args['height']);
     $types = array_get($args, 'types');
     if ($types !== null) {
         array_set($fileuploadOptions, 'acceptFileTypes', '(\\.|\\/)(' . implode('|', (array) $types) . ')$');
     }
     array_set($args, 'fileuploadOptions', $fileuploadOptions);
     // render template
     $this->template = \View::make($this->view, ['args' => $args, 'seq' => $seq])->render();
     return parent::render();
 }
 function trait_config_set($clz, $key, $value)
 {
     if (!property_exists($clz, 'traitConfigs')) {
         $clz::$traitConfigs = [];
     }
     array_set($clz::$traitConfigs, $key, $value);
 }
Пример #26
0
 /**
  * Return the tag links.
  *
  * @param array $attributes
  * @return string
  */
 public function tagLinks(array $attributes = [])
 {
     array_set($attributes, 'class', array_get($attributes, 'class', 'label label-default'));
     return array_map(function ($label) use($attributes) {
         return $this->html->link(implode('/', [$this->settings->value('anomaly.module.posts::module_segment', 'posts'), $this->settings->value('anomaly.module.posts::tag_segment', 'tag'), $label]), $label, $attributes);
     }, (array) $this->object->getTags());
 }
Пример #27
0
 /**
  * Translate form fields.
  *
  * @param FormBuilder $builder
  */
 public function translate(FormBuilder $builder)
 {
     $translations = [];
     $defaultLocale = config('streams::locales.default');
     $enabledLocales = config('streams::locales.enabled');
     /*
      * For each field if the assignment is translatable
      * then duplicate it and set a couple simple
      * parameters to assist in rendering.
      */
     foreach ($builder->getFields() as $field) {
         if (!array_get($field, 'translatable', false)) {
             $translations[] = $field;
             continue;
         }
         foreach ($enabledLocales as $locale) {
             $translation = $field;
             array_set($translation, 'locale', $locale);
             array_set($translation, 'hidden', $locale !== $locale);
             if ($value = array_get($field, 'values.' . $locale)) {
                 array_set($translation, 'value', $value);
             }
             if ($defaultLocale !== $locale) {
                 array_set($translation, 'hidden', true);
                 array_set($translation, 'required', false);
                 array_set($translation, 'rules', array_diff(array_get($translation, 'rules', []), ['required']));
             }
             $translations[] = $translation;
         }
     }
     $builder->setFields($translations);
 }
Пример #28
0
 /**
  * Get the config.
  *
  * @return array
  */
 public function getConfig()
 {
     $config = parent::getConfig();
     /**
      * If images only manually set
      * the allowed mimes.
      */
     if (array_get($config, 'image')) {
         array_set($config, 'mimes', ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'svg']);
     }
     /**
      * If restricting mimes then prepend
      * with a period as Dropzone requires.
      */
     if (isset($config['mimes'])) {
         foreach ($config['mimes'] as &$extension) {
             $extension = '.' . $extension;
         }
     }
     /**
      * Determine the default max upload size.
      */
     if (!array_get($config, 'max')) {
         $post = str_replace('M', '', ini_get('post_max_size'));
         $file = str_replace('M', '', ini_get('upload_max_filesize'));
         array_set($config, 'max', $file > $post ? $post : $file);
     }
     return $config;
 }
Пример #29
0
 function input_only($array, $keys)
 {
     $results = [];
     foreach ($keys as $key) {
         array_set($results, $key, array_get($array, $key));
     }
     return $results;
 }
Пример #30
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $posts = PostService::getPosts();
     foreach ($posts as $post) {
         array_set($post, 'commentsCount', PostService::getComments($post->id)->count());
     }
     return view('posts.index', compact('posts'));
 }