/** * Load the given configuration group. * * @param string $environment * @param string $group * @param string $namespace * @return array */ public function load($environment, $group, $namespace = null) { $yaml = new \Symfony\Component\Yaml\Parser(); $items = array(); // First we'll get the root configuration path for the environment which is // where all of the configuration files live for that namespace, as well // as any environment folders with their specific configuration items. $path = $this->getPath($namespace); if (is_null($path)) { return $items; } // First we'll get the main configuration file for the groups. Once we have // that we can check for any environment specific files, which will get // merged on top of the main arrays to make the environments cascade. $file = "{$path}/{$group}.yml"; if ($this->files->exists($file)) { // $items = $this->files->getRequire($file); $items = $yaml->parse(utf8_encode(file_get_contents($file))); } // Finally we're ready to check for the environment specific configuration // file which will be merged on top of the main arrays so that they get // precedence over them if we are currently in an environments setup. $file = "{$path}/{$environment}/{$group}.yml"; if ($this->files->exists($file)) { // $items = $this->mergeEnvironment($items, $file); $items = array_replace_recursive($items, $yaml->parse(utf8_encode(file_get_contents($file)))); } return $items; }
function insertAnalytics() { $yamlparser = new \Symfony\Component\Yaml\Parser(); $config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); if (empty($config['webproperty'])) { $config['webproperty'] = "property-not-set"; } $html = <<<EOM <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '%webproperty%']); _gaq.push(['_setDomainName', '%domainname%']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> EOM; $html = str_replace("%webproperty%", $config['webproperty'], $html); $html = str_replace("%domainname%", $_SERVER['HTTP_HOST'], $html); return $html; }
function it_should_extends_standard_templates() { $yaml = new \Symfony\Component\Yaml\Parser(); $value = $yaml->parse(file_get_contents(realpath(__DIR__ . '/../../../../Action/Template/edit.yml'))); $options = array_merge($value, $this->getOptions()); $this->useDefaults($this->getOptions())->shouldBe($options); }
public function __construct(array $files = null) { $files = is_null($files) ? $this->findAllConfigurationFiles() : $files; if (count($files) == 0) { throw new \StackFormation\Exception\NoBlueprintsFoundException("Could not find any blueprints.yml configuration files"); } $yamlParser = new \Symfony\Component\Yaml\Parser(); $config = []; $stacknames = []; foreach ($files as $file) { $basePath = dirname(realpath($file)); $tmp = $yamlParser->parse(file_get_contents($file)); if (isset($tmp['blueprints']) && is_array($tmp['blueprints'])) { foreach ($tmp['blueprints'] as &$blueprintConfig) { // check for multiple usage of the same stackname $stackname = $blueprintConfig['stackname']; if (in_array($stackname, $stacknames)) { throw new \Exception("Stackname '{$stackname}' was declared more than once."); } if (empty($blueprintConfig['template'])) { throw new \Exception("Stackname '{$stackname}' does not specify a template."); } $stacknames[] = $stackname; $blueprintConfig['basepath'] = $basePath; } } $config[] = $tmp; } $processor = new \Symfony\Component\Config\Definition\Processor(); $this->conf = $processor->processConfiguration(new ConfigTreeBuilder(), $config); }
public function formatPsvAction() { $form = new \Zend\Form\Form(); $form->setAttribute('method', 'post'); $factory = $this->getServiceLocator()->get('DatabaseFactory'); $form->add(array('name' => 'psv', 'attributes' => array('type' => 'textarea', 'class' => 'input-lg', 'style' => 'width:900px;height:300px;'))); $form->add(array('name' => 'replacements', 'attributes' => array('type' => 'textarea', 'class' => 'input-lg', 'style' => 'width:900px;height:150px;'))); $form->add(array('name' => 'exclude', 'attributes' => array('type' => 'text', 'class' => 'input-lg', 'style' => 'width:900px;'))); $form->bind(new \ArrayObject($this->params()->fromPost())); $viewModel = new ViewModel(); $viewModel->setVariable('form', $form); $psv = $this->params()->fromPost('psv'); if ($psv) { // $parser = new \UnitTest\Lib\TestDbAcle // $results = ; $exclude = []; if ($this->params()->fromPost('exclude')) { $exclude = $this->params()->fromPost('exclude') ? explode(",", $this->params()->fromPost('exclude')) : []; } if ($this->params()->fromPost('replacements')) { $yamlParser = new \Symfony\Component\Yaml\Parser(); $replacements = $yamlParser->parse($this->params()->fromPost('replacements')); $results = $this->replacePlaceHolders($replacements, $replacements); } $formatted = \UnitTest\Lib\TestDbAcle\CsvFormatter::format($results, $exclude); $viewModel->setVariable("result", $formatted); } return $viewModel; }
public function testCreateSchemaFromYaml() { $yamlParser = new \Symfony\Component\Yaml\Parser(); $yaml = $yamlParser->parse(file_get_contents(__DIR__ . '/testSchema.yml')); $tuersteher = new \Tuersteher\Tuersteher(); $validatorResult = new \Tuersteher\Test\ValidatorResult(); $tuersteher->setValidatorResult($validatorResult); $schemaResult = new \Tuersteher\Test\SchemaResult(); $tuersteher->setSchemaResult($schemaResult); $schema = $tuersteher->createSchemaFromYaml($yaml); $this->assertInstanceOf('\\Tuersteher\\Validator\\Schema', $schema); $values = array('url' => 'http://google.com?q=bla', 'email' => '*****@*****.**', 'age' => '50'); $isValid1 = $schema->validate($values); $this->assertTrue($isValid1()); $values2 = array('url' => 'http://google.com', 'email' => 'keineemailadresse', 'age' => '5'); $isValid2 = $schema->validate($values2); $this->assertFalse($isValid2()); $values3 = array('url' => 'http://google.com?q=bla', 'age' => '50'); $isValid3 = $schema->validate($values3); $this->assertFalse($isValid3()); $values4 = array('email' => '*****@*****.**', 'age' => '50'); $isValid4 = $schema->validate($values4); $this->assertTrue($isValid4()); $this->setExpectedException('\\Tuersteher\\Exception\\InvalidArgument'); $schema->validate($this); }
function facebookLike() { global $app; $yamlparser = new \Symfony\Component\Yaml\Parser(); $config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); if (empty($config['style'])) { $config['style'] = "standard"; } if (empty($config['width'])) { $config['width'] = "350px"; } if (empty($config['verb'])) { $config['verb'] = "like"; } if (empty($config['scheme'])) { $config['scheme'] = "light"; } if (empty($config['url'])) { $config['url'] = $app['paths']['canonicalurl']; } // code from http://developers.facebook.com/docs/reference/plugins/like/ $html = <<<EOM <div class="fb-like" data-href="%url%" data-send="false" data-layout="%style%" data-width="%width%" data-show-faces="false" data-action="%verb%" data-colorscheme="%scheme%"></div> EOM; // data-href="http://example.org" $html = str_replace("%url%", $config['url'], $html); $html = str_replace("%style%", $config['style'], $html); $html = str_replace("%width%", $config['width'], $html); $html = str_replace("%verb%", $config['verb'], $html); $html = str_replace("%scheme%", $config['scheme'], $html); return $html; }
/** * Initialize NiceUrls. Called during bootstrap phase. * For subrequests in Silex, see * https://github.com/fabpot/Silex/blob/master/doc/cookbook/sub_requests.rst */ public function initialize() { $yamlparser = new \Symfony\Component\Yaml\Parser(); $this->config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); $this->addTwigFilter('niceurl', 'niceUrlFilter'); $this->processRouting(); }
function getConfig() { $config = array(); $yamlParser = new \Symfony\Component\Yaml\Parser(); $config['general'] = $yamlParser->parse(file_get_contents(JAZZ_CONFIG_DIR . "/config.yml") . "\n"); return $config; }
function twitterButton() { global $app; $yamlparser = new \Symfony\Component\Yaml\Parser(); $config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); if (empty($config['via'])) { $config['via'] = ""; } if (!empty($config['count']) && $config['count'] == false) { $config['count'] = 'data-count="none"'; } else { $config['count'] = ''; } if (empty($config['url'])) { $config['url'] = $app['paths']['canonicalurl']; } // code from: https://twitter.com/about/resources/buttons#tweet $html = <<<EOM <a href="https://twitter.com/share" class="twitter-share-button" data-via="%via%" %count% data-url="%url%" data-dnt="true">Tweet</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> EOM; $html = str_replace("%url%", $config['url'], $html); $html = str_replace("%via%", $config['via'], $html); $html = str_replace("%count%", $config['count'], $html); return $html; }
function disqus($title = "") { global $app; $yamlparser = new \Symfony\Component\Yaml\Parser(); $config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); if (empty($config['disqus_name'])) { $config['disqus_name'] = "No name set"; } $html = <<<EOM <div id="disqus_thread"></div> <script type="text/javascript"> var disqus_shortname = '%shortname%'; %title%var disqus_url = '%url%'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); </script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a> EOM; if ($title != "") { $title = "var disqus_title = '" . htmlspecialchars($title, ENT_QUOTES, "UTF-8") . "';\n"; } else { $title = ""; } // echo "<pre>\n" . \util::var_dump($app['paths'], true) . "</pre>\n"; $html = str_replace("%shortname%", $config['disqus_name'], $html); $html = str_replace("%url%", $app['paths']['canonicalurl'], $html); $html = str_replace("%title%", $title, $html); return $html; }
public function load($configFile) { $yaml = new \Symfony\Component\Yaml\Parser(); foreach ($yaml->parse(file_get_contents($configFile)) as $key => $value) { $this->oConfig->{$key} = $value; } }
/** * Get the config file. If it doesn't exist, attempt to fall back to config.yml.dist, * and rename it to config.yml. * * @return array */ public function getConfig() { $configfile = $this->getConfigFile(); $configdistfile = $this->basepath . '/config.yml.dist'; // If it's readable, we're cool if (is_readable($configfile)) { $yamlparser = new \Symfony\Component\Yaml\Parser(); $this->config = $yamlparser->parse(file_get_contents($configfile) . "\n"); return $this->config; } // Otherwise, check if there's a config.yml.dist if (is_readable($configdistfile)) { $yamlparser = new \Symfony\Component\Yaml\Parser(); $this->config = $yamlparser->parse(file_get_contents($configdistfile) . "\n"); // If config.yml.dist exists, attempt to copy it to config.yml. if (copy($configdistfile, $configfile)) { // Success! $this->app['log']->add("Copied 'extensions/" . $this->namespace . "/config.yml.dist' to 'extensions/" . $this->namespace . "/config.yml'.", 2); } else { // Failure!! $message = "Couldn't copy 'extensions/" . $this->namespace . "/config.yml.dist' to 'extensions/" . $this->namespace . "/config.yml': File is not writable. Create the file manually, or make the folder writable."; $this->app['log']->add($message, 3); $this->app['session']->getFlashBag()->set('error', $message); } return $this->config; } // Nope. No config. return false; }
/** * Load comics from YAML file * * @param string $file */ public function loadYaml($file) { $yaml = new \Symfony\Component\Yaml\Parser(); $value = $yaml->parse(file_get_contents($file)); foreach ($value as $id => $params) { $this->comics->append(new Entry($id, $params)); } }
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { $parser = new \Symfony\Component\Yaml\Parser(); $parametersFile = file_get_contents($this->getRootDir() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'parameters.yml'); $parameters = $parser->parse($parametersFile); $c->loadFromExtension('framework', ['secret' => 'none']); $c->addDefinitions(['git_automation.jira_api' => $this->createJiraApiService($parameters['parameters'])]); }
public static function getOptions($file, $profile = null, $localFile = null) { if (file_exists($file)) { $f = new \SplFileObject($file); switch ($f->getExtension()) { case "php": $standardOptions = (include $file); if (file_exists($localFile)) { $localOptions = (include $localFile); } break; case "yaml": case "yml": $parser = new \Symfony\Component\Yaml\Parser(); $standardOptions = $parser->parse(file_get_contents($file)); if (file_exists($localFile)) { $localOptions = $parser->parse(file_get_contents($localFile)); } break; case "json": $standardOptions = json_decode(file_get_contents($file), true); if (file_exists($localFile)) { $localOptions = json_decode(file_get_contents($localFile), true); } break; default: throw new \InvalidArgumentException("File type " . $f->getExtension() . " not supported"); } if (is_array($localOptions) && count($localOptions)) { $options = array_replace_recursive($standardOptions, $localOptions); } else { $options = $standardOptions; } if (!is_array($options)) { throw new \RuntimeException("Found no usable data in {$file}"); } else { if ($profile) { return self::resolveInheritance($options, $profile); } return $options; } } else { throw new \InvalidArgumentException("{$file} does not exist or could not be read"); } }
private function getInput() { $yaml = new \Symfony\Component\Yaml\Parser(); $local_defaults = $yaml->parse(file_get_contents(__DIR__ . '/../configs/default.yml')); $local_defaults['root'] = __DIR__ . '/../../'; $input = new GinnyInput($local_defaults); $input->bind(new GinnyDefinition()); return $input; }
/** * Load the configuration data into the object * from the defined YAML file * * @return array Set of configuration data */ public function load() { $yaml = new \Symfony\Component\Yaml\Parser(); $config = $yaml->parse(file_get_contents($this->path)); foreach ($config as $route => $setup) { $this->config[$route] = new \Psecio\Invoke\RouteContainer($route, $setup); } return $this->config; }
public function __construct(array $values = []) { parent::__construct($values); // $this['debug'] = TRUE; // Default values $values += ['templates' => 'templates', 'data' => 'data', 'content' => 'content', 'twig.options' => ['strict_variables' => FALSE]]; if ($values['debug']) { $this['debug'] = TRUE; $values['twig.options']['debug'] = TRUE; } $this->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => $values['templates'], 'twig.options' => $values['twig.options'])); if ($this['debug']) { $this['twig']->addExtension(new \Twig_Extension_Debug()); } $yaml = new \Symfony\Component\Yaml\Parser(); // Load all data files if (file_exists($values['data'])) { $finder = new \Symfony\Component\Finder\Finder(); $finder->files()->in($values['data'])->name('*.yml'); foreach ($finder as $file) { $data = $yaml->parse($file->getContents()); $this['twig']->addGlobal($file->getBasename('.yml'), $data); } } // Load all sample content $content = []; if (file_exists($values['content'])) { $finder = new \Symfony\Component\Finder\Finder(); $finder->files()->in($values['content'] . '/*')->name('*.md'); foreach ($finder as $file) { list(, $data, $body) = explode("---\n", $file->getContents()); $data = $yaml->parse($data); $data['content'] = \Michelf\Markdown::defaultTransform($body); $content[basename(dirname($file->getPathname()))][] = $data; $content[basename(dirname($file->getPathname()))][$file->getBasename('.md')] = $data; } } $this['twig']->addGlobal('content', $content); // Setup the front controller $this->get('/{page}', function ($page) { $this['twig']->addGlobal('current_page', '/' . ($page == 'index' ? '' : $page)); return $this->render($page . '.html'); })->value('page', 'index'); }
protected function getConfig() { // use native pecl extension if ($this->options['pecl']) { return yaml_parse_file($this->path); } // use Symfony component $parser = new \Symfony\Component\Yaml\Parser(); return $parser->parse(file_get_contents($this->path)); }
/** * @covers \Foote\Ginny\Command\GinnyCommand::execute */ public function testexecute() { $yaml = new \Symfony\Component\Yaml\Parser(); $local_defaults = $yaml->parse(file_get_contents(__DIR__ . '/../configs/default.yml')); $local_defaults['root'] = __DIR__ . '/../../'; $input = new GinnyInput($local_defaults); $cmd = new GinnyCommand(); //nothing happens $cmd->run($input, new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET)); }
/** * Get the menu for the current 'version' as an array. * * @param string $filename * * @return array */ public function getMenu($filename) { $sourceFile = sprintf('%s/%s', $this->basepath, $filename); if (!is_readable($sourceFile)) { return []; } $yaml = new \Symfony\Component\Yaml\Parser(); $this->menu = $yaml->parse(file_get_contents($sourceFile)); return $this->menu; }
/** * @return array * * @throws ParsingException */ public function parse() { try { $parser = new \Symfony\Component\Yaml\Parser(); $parsed = $parser->parse($this->getContent()); } catch (ParseException $e) { throw new ParsingException("Cannot parse this file: " . $e->getMessage(), 0, $e); } return $parsed; }
/** * Load the configuration from the given path * * @param string $configPath Path to YAML configuration file * @return array Configuration data set */ public function loadConfig($configPath) { $yaml = new \Symfony\Component\Yaml\Parser(); $config = $yaml->parse(file_get_contents($configPath)); if (is_array($config) && !empty($config)) { foreach ($config as $route => $setup) { $this->config[$route] = new RouteContainer($route, $setup); } } return $this->config; }
private function parseConfigYaml($basename, $default = array()) { static $yamlparser = false; if ($yamlparser === false) { $yamlparser = new \Symfony\Component\Yaml\Parser(); } $filename = BOLT_CONFIG_DIR . '/' . $basename; if (is_readable($filename)) { return $yamlparser->parse(file_get_contents($filename) . "\n"); } return $default; }
function twigHelloworld($name = "") { $yamlparser = new \Symfony\Component\Yaml\Parser(); $config = $yamlparser->parse(file_get_contents(__DIR__ . '/config.yml')); // if $name isn't set, use the one from the config.yml. Unless that's empty too, then use "world". if (empty($name)) { if (!empty($config['name'])) { $name = $config['name']; } else { $name = "World"; } } return "Hello, " . $name . "!"; }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument("file"); $baseDir = getcwd(); $parser = new \Symfony\Component\Yaml\Parser(); $data = $parser->parse(file_get_contents($baseDir . "/" . $file)); foreach ($data as $name => $config) { switch ($config["type"]) { case "Object": $gen = new ObjectGenerator($name, $config); $output->writeln($gen->generate()); } } }
/** * Sets config defined in YAML config file. * * @param string $configDir Location of config file. * * @throws ParseException if YAML file cannot be parsed. * @throws \Exception if Host or API key config values are not set */ public function __construct($configDir = self::CONFIG_DIR) { $yaml = new \Symfony\Component\Yaml\Parser(); try { $config = $yaml->parse(file_get_contents($configDir)); } catch (ParseException $e) { printf('Unable to parse the YAML string: %s', $e->getMessage()); } if (!isset($config[0]['host'][0]) || !isset($config[1]['apiKey'][0])) { throw new \Exception('You must set Host and API key values in the config file'); } $this->host = $config[0]['host'][0]; $this->apiKey = $config[1]['apiKey'][0]; }
public static function parse_yaml($file_path) { $yaml_parser = new \Symfony\Component\Yaml\Parser(); $data = array(); if (file_exists($file_path)) { try { $parsed = $yaml_parser->parse(file_get_contents($file_path)); if (is_array($parsed)) { $data = $parsed; } } catch (Symfony\Component\Yaml\Exception\ParseException $e) { throw new Exception("Parse error on '" . basename($file_path) . "': " . $e->getMessage()); } } return $data; }
public static function convert(GinnyInput $input) { $path = $input->getOption('schema_path'); $parser = new \Symfony\Component\Yaml\Parser(); if (is_dir($path)) { $data['name'] = $input->getOption('bundle'); $data['namespace'] = $input->getOption('namespace'); $data['models'] = []; $data['associations'] = []; $data['manyToManys'] = []; $schema_filename = $input->getOption('schema_filename'); if (empty($schema_filename)) { $filenames = []; $finder = new \Symfony\Component\Finder\Finder(); $finder->files()->in($input->getFullSchemaPath()); foreach ($finder as $file) { if ($file->getFilename() != 'ginny.yml') { $filenames[] = $file->getFilename(); } } } else { $filenames = explode(',', $schema_filename); } foreach ($filenames as $filename) { $file = $parser->parse(file_get_contents($path . $filename)); if (!empty($file['model'])) { $defaults = ['name' => '', 'description' => '']; $model = array_merge($defaults, $file['model']); $defaults = ['name' => '', 'type' => '', 'size' => '', 'default' => false, 'required' => false, 'unique' => false, 'primary' => false, 'autoIncrement' => false]; foreach ($model['fields'] as $n => $field) { $model['fields'][$n] = array_merge($defaults, $field); } $data['models'][] = $model; } if (!empty($file['associations'])) { $data['associations'] = array_merge($data['associations'], $file['associations']); } if (!empty($file['manyToManys'])) { $data['manyToManys'] = array_merge($data['manyToManys'], $file['manyToManys']); } } return ['bundles' => [$data]]; } echo 'booger!'; exit; }