Exemplo n.º 1
0
 public function afterFetch()
 {
     // dodawanie pól json
     if (empty($this->template_id) === false) {
         $jsonable = Cache::get("template{$this->template_id}_jsonable", function () {
             $jsonable = [];
             foreach ($this->template->field->toArray() as $key => $value) {
                 $code = \Yaml::parse($value['code']);
                 if (isset($code['jsonable']) && $code['jsonable'] == true) {
                     $jsonable[] = $value['name'];
                 }
             }
             Cache::put("template{$this->template_id}_jsonable", $jsonable, 3);
             return $jsonable;
         });
         foreach ($jsonable as $value) {
             $this->jsonable[] = $value;
         }
     }
     if (empty($this->additional) === false) {
         // wstrzykiwanie wartości pól do modelu
         foreach ($this->additional as $key => $value) {
             $this->{$key} = in_array($key, $this->jsonable) ? json_decode($value) : $value;
         }
     }
 }
Exemplo n.º 2
0
 public static function getConfig($key = null)
 {
     if (!static::$config) {
         $file = static::getConfigJson();
         if (!file_exists($file)) {
             file_put_contents($file, json_encode(Yaml::parse(static::getConfigYml())));
         }
         static::$config = json_decode(file_get_contents($file), true);
         static::_bindConfig(self::$config);
         static::_bindConfig(self::$config);
     }
     if (!$key) {
         return static::$config;
     }
     if (array_key_exists($key, static::$config)) {
         return static::$config[$key];
     }
     if (strpos($key, '.') !== false) {
         $parts = explode('.', $key, 2);
         $data = static::getConfig($parts[0]);
         $data = UtilArray::cascadeGet($data, $parts[1]);
         if ($data) {
             return $data;
         }
     }
     throw new Exception("Config '{$key}' not found");
 }
 /**
  * Loads the routes of a bundle.
  *
  * @param string $name Bundle name
  *
  * @return bool
  */
 public function loadBundleRoutes($name)
 {
     $routes_path = BUNDLE . $name . '/routing.yml';
     if (file_exists($routes_path)) {
         $content = file_get_contents($routes_path);
         $this->bundle_routes = Yaml::parse($content);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 4
0
 /**
  * Parses a YAML file or string
  * @param string $input The YAML file path or YAML string
  * @param bool $isString Switch to true for string input instead of file
  * @return array
  * @throws \InvalidArgumentException when config cannot be parsed
  */
 public static function fromYaml($input, $isString = false)
 {
     $contents = $isString ? $input : file_get_contents($input);
     $yaml = Yaml::parse(trim($contents));
     if (null === $yaml) {
         // empty file
         $yaml = [];
     }
     if (!is_array($yaml)) {
         // not an array
         throw new \InvalidArgumentException(sprintf('The input "%s" must ' . 'contain or be a valid YAML structure.', $input));
     }
     return $yaml;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function load(SetInterface $files) : MapInterface
 {
     if ((string) $files->type() !== 'string') {
         throw new InvalidArgumentException();
     }
     $config = (new Processor())->processConfiguration(new Configuration(), $files->reduce([], function (array $carry, string $file) {
         $carry[] = Yaml::parse(file_get_contents($file));
         return $carry;
     }));
     $directories = new Map('string', Directory::class);
     foreach ($config as $key => $value) {
         $directories = $directories->put($key, $this->loadDirectory($key, $value));
     }
     return $directories;
 }
 /**
  * Opens a translation file, and stores its content.
  *
  * @param string $file_path The path of the file to open
  */
 private function openFile($file_path, $stop = false)
 {
     if (file_exists($file_path)) {
         $this->file_content = Yaml::parse(file_get_contents($file_path));
         if (!empty($this->file_content)) {
             $this->file_path = $file_path;
         }
         return true;
     } else {
         if (ENVIRONMENT == 'production') {
             $this->file_content = '';
             return true;
         } else {
             if ($stop == false) {
                 $this->setVar('file_path', $file_path);
                 App::translate("translation_file_missing", $this, ['bundle' => false, 'theme' => 'sybil', 'domain' => 'debug'], true);
                 die;
             } else {
                 App::debug('[TRANSLATION_ERROR: File "' . $file_path . '" is missing.]');
                 die;
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  */
 private function loadPluginFiles()
 {
     $dir = $this->sitePath . '/config/plugins';
     if (is_readable($dir)) {
         $files = scandir($dir);
         foreach ($files as $file) {
             if ($file == '.' || $file == '..') {
                 continue;
             }
             $basename = pathinfo($file, PATHINFO_FILENAME);
             $content = $this->loadFile($dir . '/' . $file);
             $this->set('plugins.config.' . $basename, Yaml::parse($content));
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Get page
  *
  *  <code>
  *      $page = Pages::getPage('downloads');
  *  </code>
  *
  * @access  public
  * @param  string $url Url
  * @return array
  */
 public static function getPage($url)
 {
     // If url is empty that its a homepage
     if ($url) {
         $file = STORAGE_PATH . '/pages/' . $url;
     } else {
         $file = STORAGE_PATH . '/pages/' . 'index';
     }
     // Select the file
     if (is_dir($file)) {
         $file = STORAGE_PATH . '/pages/' . $url . '/index.md';
     } else {
         $file .= '.md';
     }
     // Get 404 page if file not exists
     if (!file_exists($file)) {
         $file = STORAGE_PATH . '/pages/' . '404.md';
         Response::status(404);
     }
     // Create Unique Cache ID for requested page
     $page_cache_id = md5('page' . ROOT_DIR . $file . filemtime($file));
     if (Cache::driver()->contains($page_cache_id) && Config::get('system.pages.flush_cache') == false) {
         return Cache::driver()->fetch($page_cache_id);
     } else {
         $content = file_get_contents($file);
         $_page = explode('---', $content, 3);
         $page = Yaml::parse($_page[1]);
         $url = str_replace(STORAGE_PATH . '/pages', Url::getBase(), $file);
         $url = str_replace('index.md', '', $url);
         $url = str_replace('.md', '', $url);
         $url = str_replace('\\', '/', $url);
         $url = rtrim($url, '/');
         $page['url'] = $url;
         $_content = $_page[2];
         // Parse page for summary <!--more-->
         if (($pos = strpos($_content, "<!--more-->")) === false) {
             $_content = Filter::apply('content', $_content);
         } else {
             $_content = explode("<!--more-->", $_content);
             $_content['summary'] = Filter::apply('content', $_content[0]);
             $_content['content'] = Filter::apply('content', $_content[0] . $_content[1]);
         }
         if (is_array($_content)) {
             $page['summary'] = $_content['summary'];
             $page['content'] = $_content['content'];
         } else {
             $page['content'] = $_content;
         }
         $page['slug'] = basename($file, '.md');
         // Overload page title, keywords and description if needed
         empty($page['title']) and $page['title'] = Config::get('site.title');
         empty($page['keywords']) and $page['keywords'] = Config::get('site.keywords');
         empty($page['description']) and $page['description'] = Config::get('site.description');
         Cache::driver()->save($page_cache_id, $page);
         return $page;
     }
 }
Exemplo n.º 9
0
 /**
  * Process a form submission
  *
  * @return void
  */
 private function process()
 {
     /*
     |--------------------------------------------------------------------------
     | Prep form and handler variables
     |--------------------------------------------------------------------------
     |
     | We're going to assume success = true here to simplify code readability.
     | Checks already exist for require and validation so we simply flip the
     | switch there.
     |
     */
     $success = true;
     $errors = array();
     /*
     |--------------------------------------------------------------------------
     | Hidden fields and $_POST hand off
     |--------------------------------------------------------------------------
     |
     | We slide the hidden key out of the POST data and assign the rest to a
     | cleaner $submission variable.
     |
     */
     $hidden = $_POST['hidden'];
     unset($_POST['hidden']);
     $submission = $_POST;
     /*
     |--------------------------------------------------------------------------
     | Grab formset and collapse settings
     |--------------------------------------------------------------------------
     |
     | Formset settings are merged on top of the default raven.yaml config file
     | to allow per-form overrides.
     |
     */
     $formset_name = array_get($hidden, 'formset');
     $formset = $formset_name . '.yaml';
     if (File::exists('_config/add-ons/raven/formsets/' . $formset)) {
         $formset = Yaml::parse('_config/add-ons/raven/formsets/' . $formset);
     } elseif (File::exists('_config/formsets/' . $formset)) {
         $formset = Yaml::parse('_config/formsets/' . $formset);
     } else {
         $formset = array();
     }
     if (!is_array($this->config)) {
         $this->log->warn('Could not find the config file.');
         $this->config = array();
     }
     $config = array_merge($this->config, $formset, array('formset' => $hidden['formset']));
     /*
     |--------------------------------------------------------------------------
     | Prep filters
     |--------------------------------------------------------------------------
     |
     | We jump through some PHP hoops here to filter, sanitize and validate
     | our form inputs.
     |
     */
     $allowed_fields = array_flip(array_get($formset, 'allowed', array()));
     $required_fields = array_flip(array_get($formset, 'required', array()));
     $validation_rules = isset($formset['validate']) ? $formset['validate'] : array();
     $messages = isset($formset['messages']) ? $formset['messages'] : array();
     $referrer = Request::getReferrer();
     $return = array_get($hidden, 'return', $referrer);
     $error_return = array_get($hidden, 'error_return', $referrer);
     /*
     |--------------------------------------------------------------------------
     | Allowed fields
     |--------------------------------------------------------------------------
     |
     | It's best to only allow a set of predetermined fields to cut down on
     | spam and misuse.
     |
     */
     if (count($allowed_fields) > 0) {
         $submission = array_intersect_key($submission, $allowed_fields);
     }
     /*
     |--------------------------------------------------------------------------
     | Required fields
     |--------------------------------------------------------------------------
     |
     | Requiring fields isn't required (ironic-five!), but if any are specified
     | and missing from the POST, we'll be squashing this submission right here
     | and sending back an array of missing fields.
     |
     */
     if (count($required_fields) > 0) {
         $missing = array_flip(array_diff_key($required_fields, array_filter($submission)));
         if (count($missing) > 0) {
             foreach ($missing as $key => $field) {
                 $errors['missing'][] = array('field' => $field);
             }
             $success = false;
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Validation
     |--------------------------------------------------------------------------
     |
     | Run optional per-field validation. Any data failing the specified
     | validation rule will squash the submission and send back error messages
     | as specified in the formset.
     |
     */
     $invalid = $this->validate($submission, $validation_rules);
     // Prepare a data array of fields and error messages use for template display
     if (count($invalid) > 0) {
         $errors['invalid'] = array();
         foreach ($invalid as $field) {
             $errors['invalid'][] = array('field' => $field, 'message' => isset($messages[$field]) ? $messages[$field] : null);
         }
         $success = false;
     }
     /*
     |--------------------------------------------------------------------------
     | Upload Files
     |--------------------------------------------------------------------------
     |
     | Upload any files to their specified destination.
     |
     */
     if (count($_FILES) > 0) {
         $files = array_intersect_key($_FILES, $allowed_fields);
         $upload_destination = array_get($config, 'upload_destination');
         foreach ($files as $name => $file) {
             $submission[$name] = File::upload($file, $upload_destination);
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Hook: Pre Process
     |--------------------------------------------------------------------------
     |
     | Allow pre-processing by other add-ons with the ability to kill the
     | success of the submission. Has access to the submission and config.
     |
     */
     $success = Hook::run('raven', 'pre_process', 'replace', $success, compact('submission', 'config', 'success'));
     /*
     |--------------------------------------------------------------------------
     | Form Identifier
     |--------------------------------------------------------------------------
     |
     | In the event of multiple forms on a page, we'll be able to determine
     | which one was the one that had been triggered.
     |
     */
     $this->flash->set('form_id', $hidden['raven']);
     /*
     |--------------------------------------------------------------------------
     | Finalize & determine action
     |--------------------------------------------------------------------------
     |
     | Send back the errors if validation or require fields are missing.
     | If successful, save to file (if enabled) and send notification
     | emails (if enabled).
     |
     */
     if ($success) {
         // Akismet?
         $is_spam = false;
         if ($akismet = array_get($config, 'akismet') && array_get($config, 'akismet_api_key')) {
             $is_spam = $this->tasks->akismetCheck(array('permalink' => URL::makeFull(URL::getCurrent()), 'comment_type' => $formset_name, 'comment_author' => array_get($submission, array_get($akismet, 'author')), 'comment_author_email' => array_get($submission, array_get($akismet, 'email')), 'comment_author_url' => array_get($submission, array_get($akismet, 'url')), 'comment_content' => array_get($submission, array_get($akismet, 'content'))));
         }
         // Shall we save?
         if (array_get($config, 'submission_save_to_file', false) === true) {
             $file_prefix = Parse::template(array_get($config, 'file_prefix', ''), $submission);
             $file_suffix = Parse::template(array_get($config, 'file_suffix', ''), $submission);
             $file_prefix = $is_spam ? '_' . $file_prefix : $file_prefix;
             $this->save($submission, $config, $config['submission_save_path'], $is_spam);
         }
         // Shall we send?
         if (!$is_spam && array_get($config, 'send_notification_email', false) === true) {
             $this->send($submission, $config);
         }
         /*
         |--------------------------------------------------------------------------
         | Hook: On Success
         |--------------------------------------------------------------------------
         |
         | Allow events after the form as been processed. Has access to the
         | submission and config.
         |
         */
         Hook::run('raven', 'on_success', null, null, array('submission' => $submission, 'config' => $config));
         $this->flash->set('success', true);
         URL::redirect(URL::format($return));
     } else {
         $this->flash->set('success', false);
         $this->flash->set('errors', $errors);
         $this->flash->set('old_values', $_POST);
         URL::redirect(URL::format($error_return));
     }
 }
Exemplo n.º 10
0
 public function testIncludeFiles()
 {
     $data = $this->parser->parse(__DIR__ . '/../../../support/fixtures/include.yml');
     $expectedData = array('Nelmio\\Alice\\fixtures\\Product' => array('product_base (template)' => array('status' => 'in_stock', 'site' => '<word()>', 'changed' => 'n', 'locked' => '<word()>', 'cancelled' => '<word()>', 'canBuy' => 'y', 'package' => 'n', 'price' => '<randomFloat()>', 'amount' => 1, 'markDeleted' => '<word()>', 'paid' => 'y'), 'product1' => array('amount' => 45, 'paid' => 'n', 'user' => '@user0'), 'product0' => array('changed' => 'y', 'user' => '@user1')), 'Nelmio\\Alice\\fixtures\\Shop' => array('shop2' => array('domain' => 'amazon.com'), 'shop1' => array('domain' => 'ebay.com')), 'Nelmio\\Alice\\fixtures\\User' => array('user_base (template)' => array('email' => '<email()>')));
     $this->assertEquals($expectedData, $data);
 }
Exemplo n.º 11
0
Arquivo: config.php Projeto: nob/joi
 /**
  * Is the task ticker running?
  *
  * @return boolean
  */
 public static function areTasksRunning()
 {
     $ticks_path = BASE_PATH . "/_cache/_add-ons/tasks/ticks.yaml";
     // check that the file exists
     if (!File::exists($ticks_path)) {
         return false;
     }
     // parse the ticks file
     $ticks = Yaml::parse($ticks_path);
     // check that last-tick exists
     if (!is_array($ticks) || !isset($ticks['last-tick'])) {
         return false;
     }
     // return whether the last tick was less than 5 minutes ago
     return time() - $ticks['last-tick'] < 60;
 }
Exemplo n.º 12
0
 /**
  * Loads a YAML file.
  *
  * @param string $file
  *
  * @return array The file content
  */
 private function loadFile($file)
 {
     return $this->validate(Yaml::parse($file), $file);
 }
 private function getRoutes()
 {
     $this->routes = \Yaml::parse(file_get_contents(_THEME_DIR_ . 'landing/' . $this->routesFile));
     error_log(print_r($this->routes));
 }