本文整理汇总了PHP中Symfony\Component\Yaml\Yaml::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaml::load方法的具体用法?PHP Yaml::load怎么用?PHP Yaml::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Yaml\Yaml
的用法示例。
在下文中一共展示了Yaml::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadClassMetadata
/**
* {@inheritDoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
if (null === $this->classes) {
$this->classes = Yaml::load($this->file);
}
// TODO validation
if (isset($this->classes[$metadata->getClassName()])) {
$yaml = $this->classes[$metadata->getClassName()];
if (isset($yaml['constraints'])) {
foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
$metadata->addConstraint($constraint);
}
}
if (isset($yaml['properties'])) {
foreach ($yaml['properties'] as $property => $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
$metadata->addPropertyConstraint($property, $constraint);
}
}
}
if (isset($yaml['getters'])) {
foreach ($yaml['getters'] as $getter => $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
$metadata->addGetterConstraint($getter, $constraint);
}
}
}
return true;
}
return false;
}
示例2: load
/**
* Loads a Yaml file.
*
* @param string $file A Yaml file path
* @param string $type The resource type
*
* @return RouteCollection A RouteCollection instance
*
* @throws \InvalidArgumentException When route can't be parsed
*/
public function load($file, $type = null)
{
$path = $this->locator->locate($file);
$config = Yaml::load($path);
$collection = new RouteCollection();
$collection->addResource(new FileResource($path));
// empty file
if (null === $config) {
$config = array();
}
// not an array
if (!is_array($config)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $file));
}
foreach ($config as $name => $config) {
$config = $this->normalizeRouteConfig($config);
if (isset($config['resource'])) {
$type = isset($config['type']) ? $config['type'] : null;
$prefix = isset($config['prefix']) ? $config['prefix'] : null;
$this->setCurrentDir(dirname($path));
$collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix);
} elseif (isset($config['pattern'])) {
$this->parseRoute($collection, $name, $config, $path);
} else {
throw new \InvalidArgumentException(sprintf('Unable to parse the "%s" route.', $name));
}
}
return $collection;
}
示例3: load
/**
* Load configuration for a given command.
* Loading happens only once, after that cached info is returned
*
* @param string $file Config file path
*
* @return array Array of loaded config data
*/
private function load($file)
{
if (null === $this->command) {
$this->command = Yaml::load($file);
}
return $this->command;
}
示例4: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = Yaml::load($resource);
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例5: __construct
/**
* Create phrozn command
*
* @param array $paths Folder paths
*/
public function __construct($paths)
{
// load main config
$config = Yaml::load($paths['configs'] . 'phrozn.yml');
parent::__construct($config['command']);
$this->configureCommand($paths, $config); // load all necessary sub-commands
}
示例6: __construct
/**
* Create runner
*
* @param \Phrozn\Autoloader $loader Instance of auto-loader
* @param array $paths Folder paths
*/
public function __construct($loader)
{
$this->paths = $loader->getPaths();
$this->loader = $loader;
// load main config
$this->config = Yaml::load($this->paths['configs'] . 'phrozn.yml');
}
示例7: __construct
/**
* @throws InvalidArgumentException from sfYaml::load
* @throws Zend_Config_Exception
* @param string $filename
* @param boolean $allowModifications
*/
public function __construct($filename, $allowModifications = false)
{
$this->filename = $filename;
$this->checkIfFilenameIsFile();
$content = SymfonyYaml::load($this->filename);
if (is_null($content)) {
$content = array();
}
parent::__construct($content, $allowModifications);
}
示例8: __construct
public function __construct()
{
parent::__construct();
//Load Configuration
$locator = new FileLocator(CFG_PATH);
$this->setConfig(Yaml::load($locator->locate('config.yml')));
//Load Extensions
$this->loadExtensions();
//Add template globals
$this->defineTemplateGlobals();
}
示例9: __construct
/**
* Setup config aggregator
*
* @param string $path Path to config folder
*
* @return
*/
public function __construct($path)
{
$dir = new \DirectoryIterator($path);
foreach ($dir as $item) {
if ($item->isFile()) {
if (substr($item->getBasename(), -3) === 'yml') {
$this->configs[$item->getBasename('.yml')] = Yaml::load($item->getRealPath());
}
}
}
$this->updatePaths(); // make sure that config.yml paths are absolute
}
示例10: load
/**
* Loads the sitemap tree from config or cache
* If loading from config, caches the result
*
* @return NodePub\Navigation\SitemapTree
*/
public function load()
{
$sitemapTree = new SitemapTree('root');
$sitemapTree->setIsRoot(true);
$cache = new SitemapCache($this->cacheFile);
if ($serializedArray = $cache->load()) {
$sitemapTree->unserialize($serializedArray);
} elseif (is_file($this->configFile)) {
$sitemapTree = $this->expandChildNodes($parent, Yaml::load($this->configFile));
$cache->cacheSerializedArray($sitemapTree->serialize());
}
return $sitemapTree;
}
示例11: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = Yaml::load($resource);
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
示例12: loadClassMetadata
/**
* {@inheritDoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
if (null === $this->classes) {
$this->classes = Yaml::load($this->file);
// empty file
if (null === $this->classes) {
return false;
}
// not an array
if (!is_array($this->classes)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $this->file));
}
if (isset($this->classes['namespaces'])) {
foreach ($this->classes['namespaces'] as $prefix => $namespace) {
$this->namespaces[$prefix] = $namespace;
}
unset($this->classes['namespaces']);
}
}
// TODO validation
if (isset($this->classes[$metadata->getClassName()])) {
$yaml = $this->classes[$metadata->getClassName()];
if (isset($yaml['constraints'])) {
foreach ($this->parseNodes($yaml['constraints']) as $constraint) {
$metadata->addConstraint($constraint);
}
}
if (isset($yaml['properties'])) {
foreach ($yaml['properties'] as $property => $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
$metadata->addPropertyConstraint($property, $constraint);
}
}
}
if (isset($yaml['getters'])) {
foreach ($yaml['getters'] as $getter => $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
$metadata->addGetterConstraint($getter, $constraint);
}
}
}
return true;
}
return false;
}
示例13: getMetadata
/**
* Get an array of ClassMetadataInfo instances from the passed
* Doctrine 1 schema
*
* @return array $metadatas An array of ClassMetadataInfo instances
*/
public function getMetadata()
{
$schema = array();
foreach ($this->_from as $path) {
if (is_dir($path)) {
$files = glob($path . '/*.yml');
foreach ($files as $file) {
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($file));
}
} else {
$schema = array_merge($schema, (array) \Symfony\Component\Yaml\Yaml::load($path));
}
}
$metadatas = array();
foreach ($schema as $className => $mappingInformation) {
$metadatas[] = $this->_convertToClassMetadataInfo($className, $mappingInformation);
}
return $metadatas;
}
示例14: _load
/**
* @inheritdoc
*/
protected function _load($file)
{
$array = Yaml::load($file);
if (isset($array['name'])) {
$this->setName($array['name']);
}
if (isset($array['table_name'])) {
$this->setMigrationsTableName($array['table_name']);
}
if (isset($array['migrations_namespace'])) {
$this->setMigrationsNamespace($array['migrations_namespace']);
}
if (isset($array['migrations_directory'])) {
$migrationsDirectory = $this->_getDirectoryRelativeToFile($file, $array['migrations_directory']);
$this->setMigrationsDirectory($migrationsDirectory);
$this->registerMigrationsFromDirectory($migrationsDirectory);
}
if (isset($array['migrations']) && is_array($array['migrations'])) {
foreach ($array['migrations'] as $migration) {
$this->registerMigration($migration['version'], $migration['class']);
}
}
}
示例15: loadFile
protected function loadFile($file)
{
return $this->validate(Yaml::load($file), $file);
}