php Grav-Common-File-CompiledYamlFile类(方法)实例源码

下面列出了php Grav-Common-File-CompiledYamlFile 类(方法)源码代码实例,从而了解它的用法。

作者:indigo42    项目:blog.no42.or   
/**
  * @return $this
  */
 public function init()
 {
     $locator = new UniformResourceLocator(GRAV_ROOT);
     $files = [];
     $guard = 5;
     do {
         $check = $files;
         $this->initializeLocator($locator);
         $files = $locator->findResources('config://streams.yaml');
         if ($check === $files) {
             break;
         }
         // Update streams.
         foreach (array_reverse($files) as $path) {
             $file = CompiledYamlFile::instance($path);
             $content = $file->content();
             if (!empty($content['schemes'])) {
                 $this->items['streams']['schemes'] = $content['schemes'] + $this->items['streams']['schemes'];
             }
         }
     } while (--$guard);
     if (!$guard) {
         throw new \RuntimeException('Setup: Configuration reload loop detected!');
     }
     // Make sure we have valid setup.
     $this->check($locator);
     return $this;
 }

作者:loci    项目:corporation-documentatio   
/**
  * Get blueprint.
  *
  * @param  string  $type  Blueprint type.
  * @return Blueprint
  * @throws \RuntimeException
  */
 public function get($type)
 {
     if (!isset($this->instances[$type])) {
         if (is_string($this->search)) {
             $filename = $this->search . $type . YAML_EXT;
         } else {
             $filename = isset($this->search[$type]) ? $this->search[$type] : '';
         }
         if ($filename && is_file($filename)) {
             $file = CompiledYamlFile::instance($filename);
             $blueprints = $file->content();
         } else {
             $blueprints = [];
         }
         $blueprint = new Blueprint($type, $blueprints, $this);
         if (isset($blueprints['@extends'])) {
             // Extend blueprint by other blueprints.
             $extends = (array) $blueprints['@extends'];
             if (is_string(key($extends))) {
                 $extends = [$extends];
             }
             foreach ($extends as $extendConfig) {
                 $extendType = !is_string($extendConfig) ? empty($extendConfig['type']) ? false : $extendConfig['type'] : $extendConfig;
                 if (!$extendType) {
                     continue;
                 }
                 $context = is_string($extendConfig) || empty($extendConfig['context']) ? $this : new self(self::getGrav()['locator']->findResource($extendConfig['context']));
                 $blueprint->extend($context->get($extendType));
             }
         }
         $this->instances[$type] = $blueprint;
     }
     return $this->instances[$type];
 }

作者:qb    项目:datenknoten.m   
/**
  * Get blueprint.
  *
  * @param  string  $type  Blueprint type.
  * @return Blueprint
  * @throws \RuntimeException
  */
 public function get($type)
 {
     if (!isset($this->instances[$type])) {
         if (is_string($this->search)) {
             $filename = $this->search . $type . YAML_EXT;
         } else {
             $filename = isset($this->search[$type]) ? $this->search[$type] : '';
         }
         if ($filename && is_file($filename)) {
             $file = CompiledYamlFile::instance($filename);
             $blueprints = $file->content();
         } else {
             // throw new \RuntimeException("Blueprints for '{$type}' cannot be found! {$this->search}{$type}");
             $blueprints = [];
         }
         $blueprint = new Blueprint($type, $blueprints, $this);
         if (isset($blueprints['@extends'])) {
             // Extend blueprint by other blueprints.
             $extends = (array) $blueprints['@extends'];
             foreach ($extends as $extendType) {
                 $blueprint->extend($this->get($extendType));
             }
         }
         $this->instances[$type] = $blueprint;
     }
     return $this->instances[$type];
 }

作者:loci    项目:corporation-documentatio   
/**
  * Load global blueprints.
  *
  * @param string $key
  * @param array $files
  */
 public function loadBlueprints($key, array $files = null)
 {
     if (is_null($files)) {
         $files = $this->files[$key];
     }
     foreach ($files as $name => $item) {
         $file = CompiledYamlFile::instance($item['file']);
         $this->blueprints->embed($name, $file->content(), '/');
     }
 }

作者:dweeli    项目:gra   
/**
  * Load single configuration file and append it to the correct position.
  *
  * @param  string  $name  Name of the position.
  * @param  string  $filename  File to be loaded.
  */
 protected function loadFile($name, $filename)
 {
     $file = CompiledYamlFile::instance($filename);
     if (preg_match('|languages\\.yaml$|', $filename)) {
         $this->object->mergeRecursive($file->content());
     } else {
         $this->object->join($name, $file->content(), '/');
     }
     $file->free();
 }

作者:lithre    项目:grav-plugin-yn   
/**
  * Create admin user for Yunohost install
  */
 protected function createUserFromYnh()
 {
     $auth = HttpbasicauthPlugin::extractFromHeaders();
     $username = $auth['username'];
     $user = new User(['password' => $auth['password'], 'email' => !empty($_SERVER['HTTP_EMAIL']) ? $_SERVER['HTTP_EMAIL'] : '', 'fullname' => !empty($_SERVER['HTTP_NAME']) ? $_SERVER['HTTP_NAME'] : '', 'title' => 'Administrator', 'state' => 'enabled', 'access' => ['admin' => ['login' => true, 'super' => true], 'site' => ['login' => true]]]);
     $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));
     $user->file($file);
     $user->save();
     return $username;
 }

作者:qb    项目:datenknoten.m   
/**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  * @return User
  */
 public static function load($username)
 {
     // FIXME: validate directory name
     $blueprints = new Blueprints('blueprints://user');
     $blueprint = $blueprints->get('account');
     $file = CompiledYamlFile::instance(ACCOUNTS_DIR . $username . YAML_EXT);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     return $user;
 }

作者:mcspronk    项目:grav-plugin-newslette   
/**
  * Load subscriber
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  * @return Subscriber
  */
 public static function load($email, array $post = [])
 {
     /** @var ResourceLocatorInterface $locator */
     $locator = self::getGrav()['locator'];
     // force lowercase of username
     $email = strtolower($email);
     /** @var  $content */
     $filePath = $locator->findResource('user://data/newsletter/subscribers/' . $email . YAML_EXT);
     $file = CompiledYamlFile::instance($filePath);
     $subscriber = new Subscriber(array_merge($file->content(), $post));
     if ($subscriber) {
         $subscriber->file($file);
     }
     return $subscriber;
 }

作者:sunilkgra    项目:grav-tes   
/**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  * @return User
  */
 public static function load($username)
 {
     $locator = self::getGrav()['locator'];
     $blueprints = new Blueprints('blueprints://');
     $blueprint = $blueprints->get('user/account');
     $file_path = $locator->findResource('account://' . $username . YAML_EXT);
     $file = CompiledYamlFile::instance($file_path);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     return $user;
 }

作者:indigo42    项目:blog.no42.or   
/**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->options = ['user' => $this->input->getOption('user'), 'password1' => $this->input->getOption('password')];
     $this->validateOptions();
     $helper = $this->getHelper('question');
     $data = [];
     $this->output->writeln('<green>Changing User Password</green>');
     $this->output->writeln('');
     if (!$this->options['user']) {
         // Get username and validate
         $question = new Question('Enter a <yellow>username</yellow>: ');
         $question->setValidator(function ($value) {
             return $this->validate('user', $value);
         });
         $username = $helper->ask($this->input, $this->output, $question);
     } else {
         $username = $this->options['user'];
     }
     if (!$this->options['password1']) {
         // Get password and validate
         $password = $this->askForPassword($helper, 'Enter a <yellow>new password</yellow>: ', function ($password1) use($helper) {
             $this->validate('password1', $password1);
             // Since input is hidden when prompting for passwords, the user is asked to repeat the password
             return $this->askForPassword($helper, 'Repeat the <yellow>password</yellow>: ', function ($password2) use($password1) {
                 return $this->validate('password2', $password2, $password1);
             });
         });
         $data['password'] = $password;
     } else {
         $data['password'] = $this->options['password1'];
     }
     // Lowercase the username for the filename
     $username = strtolower($username);
     // Grab the account file and read in the information before setting the file (prevent setting erase)
     $oldUserFile = CompiledYamlFile::instance(self::getGrav()['locator']->findResource('account://' . $username . YAML_EXT, true, true));
     $oldData = $oldUserFile->content();
     //Set the password feild to new password
     $oldData['password'] = $data['password'];
     // Create user object and save it using oldData (with updated password)
     $user = new User($oldData);
     $file = CompiledYamlFile::instance(self::getGrav()['locator']->findResource('account://' . $username . YAML_EXT, true, true));
     $user->file($file);
     $user->save();
     $this->output->writeln('');
     $this->output->writeln('<green>Success!</green> User <cyan>' . $username . '\'s</cyan> password changed.');
 }

作者:mcspronk    项目:grav-plugin-newslette   
public function subscribers()
 {
     // Initialize subscriber class.
     require_once __DIR__ . '/subscriber.php';
     /** @var ResourceLocatorInterface $locator */
     $locator = $this->grav['locator'];
     $dataDir = $locator->findResource('user://data/newsletter/subscribers');
     $fullPath = $dataDir;
     $iterator = new \DirectoryIterator($fullPath);
     $subscribers = [];
     foreach ($iterator as $file) {
         if (!$file->isFile()) {
             continue;
         }
         $name = $file->getBasename();
         $subscribers[$name] = CompiledYamlFile::instance($dataDir . DS . $name)->content();
     }
     return $subscribers;
 }

作者:statrixbo    项目:gravblo   
/**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->options = ['user' => $this->input->getOption('user'), 'state' => $this->input->getOption('state')];
     $this->validateOptions();
     $helper = $this->getHelper('question');
     $data = [];
     $this->output->writeln('<green>Setting User State</green>');
     $this->output->writeln('');
     if (!$this->options['user']) {
         // Get username and validate
         $question = new Question('Enter a <yellow>username</yellow>: ');
         $question->setValidator(function ($value) {
             return $this->validate('user', $value);
         });
         $username = $helper->ask($this->input, $this->output, $question);
     } else {
         $username = $this->options['user'];
     }
     if (!$this->options['state'] && !count(array_filter($this->options))) {
         // Choose State
         $question = new ChoiceQuestion('Please choose the <yellow>state</yellow> for the account:', array('enabled' => 'Enabled', 'disabled' => 'Disabled'), 'enabled');
         $question->setErrorMessage('State %s is invalid.');
         $data['state'] = $helper->ask($this->input, $this->output, $question);
     } else {
         $data['state'] = $this->options['state'] ?: 'enabled';
     }
     // Lowercase the username for the filename
     $username = strtolower($username);
     // Grab the account file and read in the information before setting the file (prevent setting erase)
     $oldUserFile = CompiledYamlFile::instance(self::getGrav()['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));
     $oldData = $oldUserFile->content();
     //Set the state feild to new state
     $oldData['state'] = $data['state'];
     // Create user object and save it using oldData (with updated state)
     $user = new User($oldData);
     $file = CompiledYamlFile::instance(self::getGrav()['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));
     $user->file($file);
     $user->save();
     $this->output->writeln('');
     $this->output->writeln('<green>Success!</green> User <cyan>' . $username . '</cyan> state set to .' . $data['state']);
 }

作者:dweeli    项目:gra   
/**
  * Load user account.
  *
  * Always creates user object. To check if user exists, use $this->exists().
  *
  * @param string $username
  *
  * @return User
  */
 public static function load($username)
 {
     $grav = Grav::instance();
     $locator = $grav['locator'];
     $config = $grav['config'];
     // force lowercase of username
     $username = strtolower($username);
     $blueprints = new Blueprints();
     $blueprint = $blueprints->get('user/account');
     $file_path = $locator->findResource('account://' . $username . YAML_EXT);
     $file = CompiledYamlFile::instance($file_path);
     $content = $file->content();
     if (!isset($content['username'])) {
         $content['username'] = $username;
     }
     if (!isset($content['state'])) {
         $content['state'] = 'enabled';
     }
     $user = new User($content, $blueprint);
     $user->file($file);
     // add user to config
     $config->set("user", $user);
     return $user;
 }

作者:sunilkgra    项目:grav-tes   
protected function loadConfiguration($name, Config $config)
 {
     $themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content();
     $config->joinDefaults("themes.{$name}", $themeConfig);
     if ($this->config->get('system.languages.translations', true)) {
         $languages = CompiledYamlFile::instance("themes://{$name}/languages" . YAML_EXT)->content();
         if ($languages) {
             $config->getLanguages()->mergeRecursive($languages);
         }
     }
 }

作者:tuxknigh    项目:daocloud-doc   
/**
  * Create user.
  *
  * @param  string $data['username']   The username of the OAuth user
  * @param  string $data['password']   The unique id of the Oauth user
  *                                    setting as password
  * @param  string $data['email']      The email of the OAuth user
  * @param  string $data['language']   Language
  * @param  bool   $save               Save user
  *
  * @return User                       A user object
  */
 protected function createUser($data, $save = false)
 {
     /** @var User $user */
     $user = $this->grav['user'];
     $accountFile = Inflector::underscorize($data['username']);
     $accountFile = $this->grav['locator']->findResource('user://accounts/' . strtolower("{$accountFile}.{$this->action}") . YAML_EXT, true, true);
     $user->set('username', $data['username']);
     $user->set('password', md5($data['id']));
     $user->set('email', $data['email']);
     $user->set('lang', $data['lang']);
     // Set access rights
     $user->join('access', $this->grav['config']->get('plugins.login.oauth.user.access', []));
     // Authorize OAuth user to access page(s)
     $user->authenticated = $user->authorize('site.login');
     if ($save) {
         $user->file(CompiledYamlFile::instance($accountFile));
         $user->save();
     }
     return $user;
 }

作者:qb    项目:datenknoten.m   
/**
  * Add meta file for the medium.
  *
  * @param $type
  * @return $this
  */
 public function addMetaFile($type)
 {
     $this->meta[$type] = $type;
     $path = $this->get('path') . '/' . $this->get('filename') . '.meta.' . $type;
     if ($type == 'yaml') {
         $this->merge(CompiledYamlFile::instance($path)->content());
     } elseif (in_array($type, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->set('thumb', $path);
     }
     $this->reset();
     return $this;
 }

作者:allenclou    项目:daocloud-doc   
/**
  * Process a registration form. Handles the following actions:
  *
  * - register_user: registers a user
  *
  * @param Event $event
  */
 public function onFormProcessed(Event $event)
 {
     $form = $event['form'];
     $action = $event['action'];
     $params = $event['params'];
     switch ($action) {
         case 'register_user':
             if (!$this->config->get('plugins.login.enabled')) {
                 throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.PLUGIN_LOGIN_DISABLED'));
             }
             if (!$this->config->get('plugins.login.user_registration.enabled')) {
                 throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.USER_REGISTRATION_DISABLED'));
             }
             $data = [];
             $username = $form->value('username');
             if (file_exists($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT))) {
                 $this->grav->fireEvent('onFormValidationError', new Event(['form' => $form, 'message' => $this->grav['language']->translate(['PLUGIN_LOGIN.USERNAME_NOT_AVAILABLE', $username])]));
                 $event->stopPropagation();
                 return;
             }
             if ($this->config->get('plugins.login.user_registration.options.validate_password1_and_password2', false)) {
                 if ($form->value('password1') != $form->value('password2')) {
                     $this->grav->fireEvent('onFormValidationError', new Event(['form' => $form, 'message' => $this->grav['language']->translate('PLUGIN_LOGIN.PASSWORDS_DO_NOT_MATCH')]));
                     $event->stopPropagation();
                     return;
                 }
                 $data['password'] = $form->value('password1');
             }
             $fields = $this->config->get('plugins.login.user_registration.fields', []);
             foreach ($fields as $field) {
                 // Process value of field if set in the page process.register_user
                 $default_values = $this->config->get('plugins.login.user_registration.default_values');
                 if ($default_values) {
                     foreach ($default_values as $key => $param) {
                         $values = explode(',', $param);
                         if ($key == $field) {
                             $data[$field] = $values;
                         }
                     }
                 }
                 if (!isset($data[$field]) && $form->value($field)) {
                     $data[$field] = $form->value($field);
                 }
             }
             if ($this->config->get('plugins.login.user_registration.options.validate_password1_and_password2', false)) {
                 unset($data['password1']);
                 unset($data['password2']);
             }
             // Don't store the username: that is part of the filename
             unset($data['username']);
             if ($this->config->get('plugins.login.user_registration.options.set_user_disabled', false)) {
                 $data['state'] = 'disabled';
             } else {
                 $data['state'] = 'enabled';
             }
             // Create user object and save it
             $user = new User($data);
             $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));
             $user->file($file);
             $user->save();
             $user = User::load($username);
             if ($data['state'] == 'enabled' && $this->config->get('plugins.login.user_registration.options.login_after_registration', false)) {
                 //Login user
                 $this->grav['session']->user = $user;
                 unset($this->grav['user']);
                 $this->grav['user'] = $user;
                 $user->authenticated = $user->authorize('site.login');
             }
             if ($this->config->get('plugins.login.user_registration.options.send_activation_email', false)) {
                 $this->sendActivationEmail($user);
             } else {
                 if ($this->config->get('plugins.login.user_registration.options.send_welcome_email', false)) {
                     $this->sendWelcomeEmail($user);
                 }
                 if ($this->config->get('plugins.login.user_registration.options.send_notification_email', false)) {
                     $this->sendNotificationEmail($user);
                 }
             }
             if ($redirect = $this->config->get('plugins.login.user_registration.redirect_after_registration', false)) {
                 $this->grav->redirect($redirect);
             }
             break;
     }
 }

作者:qb    项目:datenknoten.m   
protected function loadConfiguration($name, Config $config)
 {
     $themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content();
     $config->joinDefaults("themes.{$name}", $themeConfig);
 }

作者:indigo42    项目:blog.no42.or   
/**
  * Process the admin registration form.
  *
  * @param Event $event
  */
 public function onFormProcessed(Event $event)
 {
     $form = $event['form'];
     $action = $event['action'];
     switch ($action) {
         case 'register_admin_user':
             if (!$this->config->get('plugins.login.enabled')) {
                 throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.PLUGIN_LOGIN_DISABLED'));
             }
             $data = [];
             $username = $form->value('username');
             if ($form->value('password1') != $form->value('password2')) {
                 $this->grav->fireEvent('onFormValidationError', new Event(['form' => $form, 'message' => $this->grav['language']->translate('PLUGIN_LOGIN.PASSWORDS_DO_NOT_MATCH')]));
                 $event->stopPropagation();
                 return;
             }
             $data['password'] = $form->value('password1');
             $fields = ['email', 'fullname', 'title'];
             foreach ($fields as $field) {
                 // Process value of field if set in the page process.register_user
                 if (!isset($data[$field]) && $form->value($field)) {
                     $data[$field] = $form->value($field);
                 }
             }
             unset($data['password1']);
             unset($data['password2']);
             // Don't store the username: that is part of the filename
             unset($data['username']);
             // Extra lowercase to ensure file is saved lowercase
             $username = strtolower($username);
             $inflector = new Inflector();
             $data['fullname'] = isset($data['fullname']) ? $data['fullname'] : $inflector->titleize($username);
             $data['title'] = isset($data['title']) ? $data['title'] : 'Administrator';
             $data['state'] = 'enabled';
             $data['access'] = ['admin' => ['login' => true, 'super' => true], 'site' => ['login' => true]];
             // Create user object and save it
             $user = new User($data);
             $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://accounts/' . $username . YAML_EXT, true, true));
             $user->file($file);
             $user->save();
             $user = User::load($username);
             //Login user
             $this->grav['session']->user = $user;
             unset($this->grav['user']);
             $this->grav['user'] = $user;
             $user->authenticated = $user->authorize('site.login');
             $messages = $this->grav['messages'];
             $messages->add($this->grav['language']->translate('PLUGIN_ADMIN.LOGIN_LOGGED_IN'), 'info');
             $this->grav->redirect($this->admin_route);
             break;
     }
 }

作者:krsreenath    项目:gra   
/**
  * Add meta file for the medium.
  *
  * @param $filepath
  */
 public function addMetaFile($filepath)
 {
     $this->merge(CompiledYamlFile::instance($filepath)->content());
 }


问题


面经


文章

微信
公众号

扫码关注公众号