本文整理汇总了PHP中Grav\Common\File\CompiledYamlFile类的典型用法代码示例。如果您正苦于以下问题:PHP CompiledYamlFile类的具体用法?PHP CompiledYamlFile怎么用?PHP CompiledYamlFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompiledYamlFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* @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;
}
示例2: get
/**
* 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];
}
示例3: get
/**
* 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];
}
示例4: loadBlueprints
/**
* 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(), '/');
}
}
示例5: loadFile
/**
* 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();
}
示例6: createUserFromYnh
/**
* 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;
}
示例7: load
/**
* 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;
}
示例8: load
/**
* 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;
}
示例9: load
/**
* 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;
}
示例10: serve
/**
* @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.');
}
示例11: subscribers
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;
}
示例12: serve
/**
* @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']);
}
示例13: load
/**
* 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;
}
示例14: loadConfiguration
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);
}
}
}
示例15: createUser
/**
* 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;
}