/**
  * Parses the contents of a given YAML file.
  *
  * @param $filePath
  * @throws Exceptions\FileReaderException
  * @return array
  */
 public static function parse($filePath)
 {
     try {
         $data = self::load($filePath);
         if (!empty($data)) {
             //Try to process the yaml file with the PHP function, if installed
             if (function_exists("yaml_parse")) {
                 $dataArray = yaml_parse($data);
                 if (is_array($dataArray)) {
                     return $dataArray;
                 }
             } else {
                 try {
                     $yml = new \Symfony\Component\Yaml\Yaml();
                     return $yml->parse($data);
                 } catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
                     //Do nothing. Fire exception after the if-else statement.
                 }
             }
             throw new FileReaderException('The file does not contain valid well formatted YAML data.');
         } else {
             throw new FileReaderException('No data has been loaded. Use the load($filePath) method before using getData().');
         }
     } catch (FileReaderException $e) {
         throw new FileReaderException($e);
     }
 }
 /**
  * Process a structured array of info files lines to a flat array for merging.
  *
  * @param $lines
  *  An array of lines keyed by label.
  *  Place grouped labels (eg, dependencies) into an array of
  *  their own, keyed numerically.
  *  Eg:
  *    name => module name
  *    dependencies => array(foo, bar)
  *
  * @return
  *  An array of lines for the .info file.
  */
 function process_info_lines($lines)
 {
     $yaml_parser = new \Symfony\Component\Yaml\Yaml();
     $yaml = $yaml_parser->dump($lines, 2, 2);
     //drush_print_r($yaml);
     // Because the yaml is all built for us, this is just a singleton array.
     return array($yaml);
 }
Example #3
0
 /**
  *
  * @param Symfony\Component\HttpFoundation\Request $request
  */
 public function __construct(Request $request)
 {
     $queryDecorator = new QueryDecorator($this->_getQuery());
     $this->_query = $queryDecorator->decorate($request, $this->_getUrlParamsMapper());
     $this->_curl = new AnonymousCurl();
     $reader = new \Symfony\Component\Yaml\Yaml();
     $this->_config = $reader->parse(__DIR__ . '/../Resources/config/cache.yml');
 }
Example #4
0
 /**
  * Get the YAML body for the file.
  *
  * @param $yaml_data_array
  *  An array of data to convert to YAML.
  *
  * @return
  *  An array containing the YAML string.
  */
 protected function getYamlBody($yaml_data_array)
 {
     $yaml_parser = new \Symfony\Component\Yaml\Yaml();
     $yaml = $yaml_parser->dump($yaml_data_array, 6, 2);
     //drush_print_r($yaml);
     // Replace variables
     $variables = $this->getReplacements();
     $yaml = strtr($yaml, $variables);
     // Because the yaml is all built for us, this is just a singleton array.
     $body = array($yaml);
     return $body;
 }
Example #5
0
 public static function loadConfig($path)
 {
     $path = realpath($path);
     if (!isset(self::$Configs[$path])) {
         $yaml = new \Symfony\Component\Yaml\Yaml();
         if (file_exists($path)) {
             self::$Configs[$path] = $yaml->parse($path);
         } else {
             throw new \Symfony\Component\Filesystem\Exception\FileNotFoundException();
         }
     }
     return self::$Configs[$path];
 }
Example #6
0
 protected function exportModuleDependencies($io, $module, $dependencies)
 {
     $yaml = new \Symfony\Component\Yaml\Yaml();
     $info_file = file_get_contents($this->getSite()->getModuleInfoFile($module));
     $info_yaml = $yaml->parse($info_file);
     if (empty($info_yaml['dependencies'])) {
         $info_yaml['dependencies'] = $dependencies;
     } else {
         $info_yaml['dependencies'] = array_unique(array_merge($info_yaml['dependencies'], $dependencies));
     }
     if (file_put_contents($this->getSite()->getModuleInfoFile($module), $yaml->dump($info_yaml))) {
         $io->info('[+] ' . sprintf($this->trans('commands.config.export.view.messages.depencies-included'), $this->getSite()->getModuleInfoFile($module)));
         foreach ($dependencies as $dependency) {
             $io->info('   [-] ' . $dependency);
         }
     } else {
         $io->error($this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $this->getSite()->getModuleInfoFile($module));
         return [];
     }
 }
Example #7
0
 /**
  * @return bool|void
  */
 public static function make_manifest()
 {
     $files = self::get_file_manifest();
     $configs = array();
     foreach ($files as $path => $info) {
         if ($info['extension'] == 'yml' || $info['extension'] == 'yaml') {
             $configs = array_merge($configs, Symfony\Component\Yaml\Yaml::parse(file_get_contents($path)));
         }
     }
     file_put_contents(TEMP_PATH . '/config_manifest', serialize($configs));
     self::$config_manifest = $configs;
 }
Example #8
0
 protected function loadFile($filePath)
 {
     $yml = array();
     $dirname = dirname($filePath);
     $yaml = new \Symfony\Component\Yaml\Yaml();
     $res = $yaml->parse($filePath);
     foreach ($res as $key => $value) {
         if ($key == 'include') {
             foreach ($value as $file) {
                 $file = preg_replace_callback('`\\${env\\.([^}]+)}`i', function ($matches) {
                     return getenv($matches[1]);
                 }, $file);
                 $subYml = $this->loadFile($dirname . '/' . $file);
                 $yml = Arrays::mergeRecursiveUnique($yml, $subYml);
             }
         } else {
             $yml = Arrays::mergeRecursiveUnique($yml, array($key => $res[$key]));
         }
     }
     return $yml;
 }
 protected function overrideServices($env, $output)
 {
     $services_settings = $this->getServicesSettings($env);
     $directory = $this->getDrupalHelper()->getRoot() . '/' . \Drupal::service('site.path');
     $settings_services_file = $directory . '/services.yml';
     if (!file_exists($settings_services_file)) {
         // Copying default services
         $default_services_file = $this->getDrupalHelper()->getRoot() . '/sites/default/default.services.yml';
         if (!copy($default_services_file, $directory . '/services.yml')) {
             $output->writeln(' <error>' . $this->trans('commands.site.mode.messages.error-copying-file') . ': ' . $directory . '/services.yml' . '</error>');
             return [];
         }
     }
     $yaml = new \Symfony\Component\Yaml\Yaml();
     $content = file_get_contents($directory . '/services.yml');
     $services = $yaml->parse($content);
     $result = [];
     foreach ($services_settings as $service => $parameters) {
         foreach ($parameters as $parameter => $value) {
             $services['parameters'][$service][$parameter] = $value;
             // Set values for output
             $result[$parameter]['service'] = $service;
             $result[$parameter]['parameter'] = $parameter;
             if (is_bool($value)) {
                 $value = $value ? 'true' : 'false';
             }
             $result[$parameter]['value'] = $value;
         }
     }
     if (file_put_contents($directory . '/services.yml', $yaml->dump($services))) {
         $output->writeln('<info>' . sprintf($this->trans('commands.site.mode.messages.services-file-overwritten'), $directory . '/services.yml') . '</info>');
     } else {
         $output->writeln(' <error>' . $this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $directory . '/services.yml' . '</error>');
         return [];
     }
     sort($result);
     return $result;
 }
Example #10
0
 /**
  * Register the bundles (and by the way the modules).
  *
  * @return array|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
  * @throws RuntimeException
  * @throws Symfony\Component\Debug\Exception\FatalErrorException
  */
 public function registerBundles()
 {
     /*
      * Basic bundles, required to load the website
      */
     $bundles = array(new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Knp\Bundle\TimeBundle\KnpTimeBundle(), new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), new FOS\JsRoutingBundle\FOSJsRoutingBundle(), new FrequenceWeb\Bundle\CalendRBundle\FrequenceWebCalendRBundle(), new FM\BbcodeBundle\FMBbcodeBundle(), new Sonata\IntlBundle\SonataIntlBundle(), new Nelmio\ApiDocBundle\NelmioApiDocBundle(), new Minifier\MinifierBundle(), new Etu\Core\CoreBundle\EtuCoreBundle(), new Etu\Core\UserBundle\EtuUserBundle(), new Etu\Core\ApiBundle\EtuCoreApiBundle());
     if (in_array($this->getEnvironment(), array('dev', 'test'))) {
         $bundles[] = new Elao\WebProfilerExtraBundle\WebProfilerExtraBundle();
         $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
         $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
         $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
     }
     /*
      * Modules bundles, loaded dynamically from app/config/modules.yml
      */
     $modules = Symfony\Component\Yaml\Yaml::parse($this->getRootDir() . '/config/modules.yml');
     if (isset($modules['modules'])) {
         if (!is_array($modules['modules'])) {
             throw new FatalErrorException('Key "modules" in app/config/modules.yml must be an array');
         }
         foreach ($modules['modules'] as $module) {
             $bundleFile = 'src/' . str_replace('\\', '/', $module) . '.php';
             if (!class_exists($module, false)) {
                 if (file_exists($this->getRootDir() . '/../' . $bundleFile)) {
                     require $this->getRootDir() . '/../' . $bundleFile;
                 } else {
                     throw new \RuntimeException(sprintf('Module "%s" can not be loaded (file "%s" not found)', $module, $bundleFile));
                 }
             }
             if (class_exists($module, false)) {
                 $module = new ReflectionClass($module);
                 $module = $module->newInstance();
                 if ($module instanceof Module) {
                     $bundles[] = $module;
                     $this->registerModuleDefinition($module);
                 } else {
                     throw new FatalErrorException(sprintf('Module "%s" must be an instance of Etu\\Core\\CoreBundle\\Framework\\Definition\\Module.', get_class($module)));
                 }
             } else {
                 throw new \RuntimeException(sprintf('Module "%s" can not be loaded (class not found)', $module));
             }
         }
     }
     $this->checkModulesIntegrity();
     return $bundles;
 }
Example #11
0
 /**
  * Adds a new yaml file to the dataset.
  * @param string $yamlFile
  */
 public function addYamlFile($yamlFile)
 {
     $data = Symfony\Component\Yaml\Yaml::parse($yamlFile);
     foreach ($data as $tableName => $rows) {
         if (!isset($rows)) {
             $rows = array();
         }
         if (!is_array($rows)) {
             continue;
         }
         if (!array_key_exists($tableName, $this->tables)) {
             $columns = $this->getColumns($rows);
             $tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($tableName, $columns);
             $this->tables[$tableName] = new PHPUnit_Extensions_Database_DataSet_DefaultTable($tableMetaData);
         }
         foreach ($rows as $row) {
             $this->tables[$tableName]->addRow($row);
         }
     }
 }
Example #12
0
 /**
  * Writes the dataset to a yaml file
  *
  * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataset
  */
 public function write(PHPUnit_Extensions_Database_DataSet_IDataSet $dataset)
 {
     $phpArr = [];
     $emptyTables = [];
     foreach ($dataset as $table) {
         $tableName = $table->getTableMetaData()->getTableName();
         $rowCount = $table->getRowCount();
         if (!$rowCount) {
             $emptyTables[] = $tableName;
             continue;
         }
         $phpArr[$tableName] = [];
         for ($i = 0; $i < $rowCount; $i++) {
             $phpArr[$tableName][] = $table->getRow($i);
         }
     }
     $emptyTablesAsString = '';
     if (count($emptyTables)) {
         $emptyTablesAsString = implode(":\n", $emptyTables) . ":\n\n";
     }
     file_put_contents($this->filename, Symfony\Component\Yaml\Yaml::dump($phpArr, 3) . $emptyTablesAsString);
 }
Example #13
0
 /**
  * Load the component data from component.yml file
  * 
  * @param \Cx\Core\View\Model\Entity\Theme $theme
  */
 public function loadComponentData(\Cx\Core\View\Model\Entity\Theme &$theme)
 {
     $websiteFilePath = \Env::get('cx')->getWebsiteThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $codeBaseFilePath = \Env::get('cx')->getCodeBaseThemesPath() . '/' . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_COMPONENT_FILE;
     $filePath = file_exists($websiteFilePath) ? $websiteFilePath : (file_exists($codeBaseFilePath) ? $codeBaseFilePath : '');
     if ($filePath) {
         try {
             $objYaml = new \Symfony\Component\Yaml\Yaml();
             $objFile = new \Cx\Lib\FileSystem\File($filePath);
             $themeInformation = $objYaml->load($objFile->getData());
             $theme->setComponentData($themeInformation['DlcInfo']);
         } catch (\Exception $e) {
             \DBG::log($e->getMessage());
         }
     }
 }
Example #14
0
 /**
  * Behat config file specifing the main context class,
  * the required Behat extensions and Moodle test wwwroot.
  *
  * @param array $features The system feature files
  * @param array $contexts The system steps definitions
  * @param string $tags filter features with specified tags.
  * @param int $parallelruns number of parallel runs.
  * @param int $currentrun current run for which config file is needed.
  * @return string
  */
 public function get_config_file_contents($features = '', $contexts = '', $tags = '', $parallelruns = 0, $currentrun = 0)
 {
     global $CFG;
     // Set current run and parallel run.
     if (!empty($parallelruns) && !empty($currentrun)) {
         $this->set_parallel_run($parallelruns, $currentrun);
     }
     // If tags defined then use them. This is for BC.
     if (!empty($tags)) {
         $this->set_tag_for_feature_filter($tags);
     }
     // If features not passed then get it. Empty array means we don't need to include features.
     if (empty($features) && !is_array($features)) {
         $features = $this->get_components_features();
     } else {
         $this->features = $features;
     }
     // If stepdefinitions not passed then get the list.
     if (empty($contexts)) {
         $this->get_components_contexts();
     } else {
         $this->contexts = $contexts;
     }
     // We require here when we are sure behat dependencies are available.
     require_once $CFG->dirroot . '/vendor/autoload.php';
     $config = $this->build_config();
     $config = $this->merge_behat_config($config);
     $config = $this->merge_behat_profiles($config);
     return Symfony\Component\Yaml\Yaml::dump($config, 10, 2);
 }
Example #15
0
<?php

// Register class loader
require_once __DIR__ . '/lib/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->registerNamespace('Symfony', __DIR__ . '/lib/symfony/src');
$loader->register();
// Read build file
$build = Symfony\Component\Yaml\Yaml::parse(__DIR__ . '/build.yml');
// Build components
mkdir(__DIR__ . "/../build/components", 0777, true);
foreach ($build['components'] as $componentName) {
    // Compute component source path
    $componentSourcePath = __DIR__ . "/../src/{$componentName}.js";
    // Build raw
    file_put_contents(__DIR__ . "/../build/components/{$componentName}.js", render(__DIR__ . '/copyright.php', array('content' => file_get_contents($componentSourcePath))));
    // Build minified
    file_put_contents(__DIR__ . "/../build/components/{$componentName}-min.js", render(__DIR__ . '/copyright.php', array('content' => compress(file_get_contents($componentSourcePath)))));
}
// Build rollups
mkdir(__DIR__ . '/../build/rollups', 0777, true);
foreach ($build['rollups'] as $rollupName => $components) {
    // Compute component source paths
    $componentSourcePaths = array_map(function ($componentName) {
        return __DIR__ . "/../src/{$componentName}.js";
    }, $components);
    // Get component source contents
    $componentSourceContents = implode('', array_map('file_get_contents', $componentSourcePaths));
    // Build rollup
    file_put_contents(__DIR__ . "/../build/rollups/{$rollupName}.js", render(__DIR__ . '/copyright.php', array('content' => compress($componentSourceContents))));
}
 public static function dump($array, $inline = 2, $indent = 2)
 {
     $yaml = new \Symfony\Component\Yaml\Yaml();
     return $yaml->dump($array, $inline, $indent);
 }
Example #17
0
<?php

if (!isset($_SERVER['HTTP_HOST'])) {
    exit('This script cannot be run from the CLI. Run it from a browser.');
}
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '10.0.2.2', '::1'])) {
    header('HTTP/1.0 403 Forbidden');
    exit('This script is only accessible from localhost.');
}
require_once __DIR__ . '/BackBeeRequirements.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';
\Symfony\Component\Debug\Debug::enable();
$step = isset($_POST['step']) ? intval($_POST['step']) : 1;
$yaml = new \Symfony\Component\Yaml\Yaml();
switch ($step) {
    case 2:
        /**
         * bootstrap.yml creation
         * -> debug true|false
         * -> container cache directory /path/to/container/cache
         * -> container auto-generate true|false
         */
        if (!isset($_POST['debug']) && !isset($_POST['container_dump_directory'])) {
            $bootstrap_requirements = new BootstrapRequirements();
            $requirements = $bootstrap_requirements->getRequirements();
            break;
        } else {
            $containerDirectory = realpath(__DIR__ . '/..') . '/cache/container';
            if (!is_dir($containerDirectory)) {
                mkdir($containerDirectory, 755);
            }
 /**
  * Behat config file specifing the main context class,
  * the required Behat extensions and Moodle test wwwroot.
  *
  * @param array $features The system feature files
  * @param array $stepsdefinitions The system steps definitions
  * @return string
  */
 protected static function get_config_file_contents($features, $stepsdefinitions)
 {
     global $CFG;
     // We require here when we are sure behat dependencies are available.
     require_once $CFG->dirroot . '/vendor/autoload.php';
     $selenium2wdhost = array('wd_host' => 'http://localhost:4444/wd/hub');
     $parallelruns = self::get_parallel_test_runs();
     // If parallel run, then only divide features.
     if (!empty($CFG->behatrunprocess) && !empty($parallelruns)) {
         // Attempt to split into weighted buckets using timing information, if available.
         if ($alloc = self::profile_guided_allocate($features, max(1, $parallelruns), $CFG->behatrunprocess)) {
             $features = $alloc;
         } else {
             // Divide the list of feature files amongst the parallel runners.
             srand(crc32(floor(time() / 3600 / 24) . var_export($features, true)));
             shuffle($features);
             // Pull out the features for just this worker.
             if (count($features)) {
                 $features = array_chunk($features, ceil(count($features) / max(1, $parallelruns)));
                 // Check if there is any feature file for this process.
                 if (!empty($features[$CFG->behatrunprocess - 1])) {
                     $features = $features[$CFG->behatrunprocess - 1];
                 } else {
                     $features = null;
                 }
             }
         }
         // Set proper selenium2 wd_host if defined.
         if (!empty($CFG->behat_parallel_run[$CFG->behatrunprocess - 1]['wd_host'])) {
             $selenium2wdhost = array('wd_host' => $CFG->behat_parallel_run[$CFG->behatrunprocess - 1]['wd_host']);
         }
     }
     // It is possible that it has no value as we don't require a full behat setup to list the step definitions.
     if (empty($CFG->behat_wwwroot)) {
         $CFG->behat_wwwroot = 'http://itwillnotbeused.com';
     }
     $basedir = $CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat';
     $config = array('default' => array('paths' => array('features' => $basedir . DIRECTORY_SEPARATOR . 'features', 'bootstrap' => $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'bootstrap'), 'context' => array('class' => 'behat_init_context'), 'extensions' => array('Behat\\MinkExtension\\Extension' => array('base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => $selenium2wdhost), 'Moodle\\BehatExtension\\Extension' => array('formatters' => array('moodle_progress' => 'Moodle\\BehatExtension\\Formatter\\MoodleProgressFormatter', 'moodle_list' => 'Moodle\\BehatExtension\\Formatter\\MoodleListFormatter', 'moodle_step_count' => 'Moodle\\BehatExtension\\Formatter\\MoodleStepCountFormatter'), 'features' => $features, 'steps_definitions' => $stepsdefinitions)), 'formatter' => array('name' => 'moodle_progress')));
     // In case user defined overrides respect them over our default ones.
     if (!empty($CFG->behat_config)) {
         $config = self::merge_config($config, $CFG->behat_config);
     }
     // Check for Moodle custom ones.
     if (!empty($CFG->behat_profiles) && is_array($CFG->behat_profiles)) {
         foreach ($CFG->behat_profiles as $profile => $values) {
             $config = self::merge_config($config, self::get_behat_profile($profile, $values));
         }
     }
     return Symfony\Component\Yaml\Yaml::dump($config, 10, 2);
 }
Example #19
0
 /**
  * Exports one or more variables to the selected format
  * Available formats: php (for testing purposes), yaml, xml and json
  * @param vars format and variables to dump
  */
 public function export()
 {
     $args = func_get_args();
     $format = strtolower($args[0]);
     $vars = array_slice($args, 1);
     $this->nodes = $this->_readVars($vars);
     $response = null;
     $exportArray = array();
     $i = 1;
     foreach ($this->nodes as $v) {
         $exportArray['var' . $i] = $v->export();
         $i++;
     }
     switch ($format) {
         case self::EXPORT_FORMAT_PHP:
             $response = $exportArray;
             break;
         case self::EXPORT_FORMAT_YAML:
             $yaml = new \Symfony\Component\Yaml\Yaml();
             $response = $yaml->dump($exportArray);
             break;
         case self::EXPORT_FORMAT_XML:
             $serializer = new \Symfony\Component\Serializer\Encoder\XmlEncoder();
             $response = $serializer->encode($exportArray, 'xml');
             break;
         case self::EXPORT_FORMAT_JSON:
             $response = json_encode($exportArray);
             break;
         default:
             throw new InvalidFormatException();
     }
     return $response;
 }
 /**
  * Behat config file specifing the main context class,
  * the required Behat extensions and Moodle test wwwroot.
  *
  * @param array $features The system feature files
  * @param array $stepsdefinitions The system steps definitions
  * @return string
  */
 protected static function get_config_file_contents($features, $stepsdefinitions)
 {
     global $CFG;
     // We require here when we are sure behat dependencies are available.
     require_once $CFG->dirroot . '/vendor/autoload.php';
     // It is possible that it has no value as we don't require a full behat setup to list the step definitions.
     if (empty($CFG->behat_wwwroot)) {
         $CFG->behat_wwwroot = 'http://itwillnotbeused.com';
     }
     $basedir = $CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat';
     $config = array('default' => array('paths' => array('features' => $basedir . DIRECTORY_SEPARATOR . 'features', 'bootstrap' => $basedir . DIRECTORY_SEPARATOR . 'features' . DIRECTORY_SEPARATOR . 'bootstrap'), 'context' => array('class' => 'behat_init_context'), 'extensions' => array('Behat\\MinkExtension\\Extension' => array('base_url' => $CFG->behat_wwwroot, 'goutte' => null, 'selenium2' => null), 'Moodle\\BehatExtension\\Extension' => array('formatters' => array('moodle_progress' => 'Moodle\\BehatExtension\\Formatter\\MoodleProgressFormatter', 'moodle_list' => 'Moodle\\BehatExtension\\Formatter\\MoodleListFormatter'), 'features' => $features, 'steps_definitions' => $stepsdefinitions)), 'formatter' => array('name' => 'moodle_progress')));
     // In case user defined overrides respect them over our default ones.
     if (!empty($CFG->behat_config)) {
         $config = self::merge_config($config, $CFG->behat_config);
     }
     return Symfony\Component\Yaml\Yaml::dump($config, 10, 2);
 }
Example #21
0
 public function __construct()
 {
     $reader = new \Symfony\Component\Yaml\Yaml();
     $this->_config = $reader->parse(__DIR__ . '/../Resources/config/cache.yml');
 }
Example #22
0
<?php

$yaml = APP_PATH . '/config.yml';
if (file_exists($yaml) && is_file($yaml) && is_readable($yaml)) {
    $env = getenv('ENVIRONMENT') ?: 'development';
    $configCache = VAR_PATH . "/cache/config/{$env}.json";
    if (file_exists($configCache) && is_file($configCache) && is_readable($configCache) && filemtime($configCache) > filemtime($yaml)) {
        $config = json_decode(file_get_contents($configCache), true);
    } else {
        $config = Symfony\Component\Yaml\Yaml::parse(file_get_contents($yaml));
        if (isset($config[$env])) {
            $config = $config[$env];
            // Slim
            $config['Slim']['mode'] = $env;
            // Logger
            if (isset($config['Slim']['log.level'])) {
                $level = 'Slim\\Log::' . $config['Slim']['log.level'];
                if (defined($level)) {
                    $config['Slim']['log.level'] = constant($level);
                } else {
                    throw new \Exception('Slim log level is incorrect.');
                }
            }
            // View renderer
            $config['Slim']['templates.path'] = APP_PATH . '/templates';
            if (true === $config['Twig']['cache']) {
                $config['Twig']['cache'] = VAR_PATH . '/cache/twig';
            }
            // save config cache file
            file_put_contents($configCache, json_encode($config));
        } else {
Example #23
0
<?php

$appDir = dirname(__DIR__);
include_once $appDir . "/vendor/autoload.php";
use Silktide\Syringe\ReferenceResolver;
use Silktide\Syringe\ContainerBuilder;
use Silktide\Syringe\Loader\JsonLoader;
use Silktide\Syringe\Loader\YamlLoader;
// Config data should be brought in using environment variables
// Updating environment variables is a PITA when doing some quick dev, so if we have an
// env.yml file, dump it into $_SERVER, where syringe will pick it up as if it was an actual environment variable
$environmentFile = __DIR__ . "/../env.yml";
if (file_exists($environmentFile)) {
    $yaml = new \Symfony\Component\Yaml\Yaml();
    $array = $yaml->parse(file_get_contents($environmentFile));
    foreach ($array as $key => $value) {
        $_SERVER[$key] = $value;
    }
}
$resolver = new ReferenceResolver();
$loaders = [new JsonLoader(), new YamlLoader()];
$configPaths = [$appDir . "/app/config", $appDir];
$builder = new ContainerBuilder($resolver, $configPaths);
foreach ($loaders as $loader) {
    $builder->addLoader($loader);
}
$builder->setApplicationRootDirectory($appDir);
$builder->addConfigFiles(["dolondro_hotstuff" => $appDir . "/vendor/dolondro/hotstuff/app/config/services.yml"]);
$builder->addConfigFile("services.yml");
Example #24
0
<?php

/**
 * 
 * 0 "${APP_PATH}/patch_yaml/patch_yaml.php" 
 * 1 "${APP_PATH}/array.yml" 
 * 2 "$MYSQL_DB_NAME" 
 * 3 "$MYSQL_USER_NAME" 
 * 4 "$MYSQL_USER_PASSWORD"`
 * 
 */
try {
    $autoload = (require_once __DIR__ . '/../vendor/autoload.php');
    $array = Symfony\Component\Yaml\Yaml::parse(file_get_contents($argv[1]));
    $db = $array["db"];
    $db["dbname"] = $argv[2];
    $db["user"] = $argv[3];
    $db["pass"] = $argv[4];
    $array["db"] = $db;
    file_put_contents($argv[1], Symfony\Component\Yaml\Yaml::dump($array, 4, 4, true));
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
    exit(1);
}
echo "OK";
exit(0);
Example #25
0
 /**
  * Parses YAML into a PHP array.
  *
  * @param string $value YAML string
  *
  * @return array
  */
 public static function yamlDecode($value)
 {
     return Symfony\Component\Yaml\Yaml::parse($value);
 }
Example #26
0
 protected function loadInline($inline)
 {
     $yaml = new \Symfony\Component\Yaml\Yaml();
     $res = $yaml->parse($inline);
     return $res;
 }
Example #27
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Pinboard\Logger\DbalLogger;
use Pinboard\Stopwatch\Stopwatch;
$app = new Silex\Application();
$app['params'] = Symfony\Component\Yaml\Yaml::parse(file_get_contents(__DIR__ . '/../config/parameters.yml'));
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
    if (!isset($app['params']['base_url']) || empty($app['params']['base_url'])) {
        $baseUrl = '/';
    } else {
        $baseUrl = $app['params']['base_url'];
    }
    if (substr($baseUrl, -1) != '/') {
        $baseUrl .= '/';
    }
    $twig->addGlobal('base_url', $baseUrl);
    return $twig;
}));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$dbOptions = array('driver' => 'pdo_mysql', 'dbname' => $app['params']['db']['name'], 'host' => $app['params']['db']['host'], 'user' => $app['params']['db']['user'], 'password' => $app['params']['db']['pass']);
if (isset($app['params']['db']['port'])) {
    $dbOptions['port'] = $app['params']['db']['port'];
}
if (isset($app['params']['db']['unix_socket'])) {
    $dbOptions['unix_socket'] = $app['params']['db']['unix_socket'];
}
Example #28
0
#!/usr/bin/php
<?php 
require_once __DIR__ . '/../vendor/autoload.php';
Dotenv::load(__DIR__ . '/../');
/**
 * @TODO build this from the yaml file on the fly
 */
$yml = new Symfony\Component\Yaml\Yaml();
$tests = $yml->parse(__DIR__ . '/../behat.yml');
$run = [];
$env = getenv('APP_ENV');
foreach ($tests as $key => $test) {
    if (strpos($key, $env) !== false) {
        $run[] = $key;
    }
}
$failing_test = [];
foreach ($run as $test) {
    $command = "bin/behat --stop-on-failure --no-paths --tags='@api,~@wip' --profile={$test}";
    $run = new \Symfony\Component\Process\Process($command);
    $run->setTimeout(600);
    $run->run(function ($type, $buffer) use($failing_test, $test) {
        if (Symfony\Component\Process\Process::ERR === $type) {
            $failing_test[] = $test;
            //throw new \Exception(sprintf("Test Failed %s", $buffer));
        } else {
            echo $buffer;
        }
    });
    if ($run->getExitCode() != 0) {
        $failing_test[] = $test;
Example #29
0
 /**
  * Prepares site settings and services before installation.
  */
 protected function prepareSettings()
 {
     // Prepare installer settings that are not install_drupal() parameters.
     // Copy and prepare an actual settings.php, so as to resemble a regular
     // installation.
     // Not using File API; a potential error must trigger a PHP warning.
     $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
     copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
     // All file system paths are created by System module during installation.
     // @see system_requirements()
     // @see TestBase::prepareEnvironment()
     $settings['settings']['file_public_path'] = (object) ['value' => $this->publicFilesDirectory, 'required' => TRUE];
     $settings['settings']['file_private_path'] = (object) ['value' => $this->privateFilesDirectory, 'required' => TRUE];
     // Save the original site directory path, so that extensions in the
     // site-specific directory can still be discovered in the test site
     // environment.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
     $settings['settings']['test_parent_site'] = (object) ['value' => $this->originalSite, 'required' => TRUE];
     // Add the parent profile's search path to the child site's search paths.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
     $settings['conf']['simpletest.settings']['parent_profile'] = (object) ['value' => $this->originalProfile, 'required' => TRUE];
     $settings['settings']['apcu_ensure_unique_prefix'] = (object) ['value' => FALSE, 'required' => TRUE];
     $this->writeSettings($settings);
     // Allow for test-specific overrides.
     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
     if (file_exists($settings_testing_file)) {
         // Copy the testing-specific settings.php overrides in place.
         copy($settings_testing_file, $directory . '/settings.testing.php');
         // Add the name of the testing class to settings.php and include the
         // testing specific overrides
         file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
     }
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (!file_exists($settings_services_file)) {
         // Otherwise, use the default services as a starting point for overrides.
         $settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml';
     }
     // Copy the testing-specific service overrides in place.
     copy($settings_services_file, $directory . '/services.yml');
     if ($this->strictConfigSchema) {
         // Add a listener to validate configuration schema on save.
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $content = file_get_contents($directory . '/services.yml');
         $services = $yaml->parse($content);
         $services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed', $this->getConfigSchemaExclusions()], 'tags' => [['name' => 'event_subscriber']]];
         file_put_contents($directory . '/services.yml', $yaml->dump($services));
     }
     // Since Drupal is bootstrapped already, install_begin_request() will not
     // bootstrap again. Hence, we have to reload the newly written custom
     // settings.php manually.
     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader);
 }
Example #30
0
 /**
  * Sets up a Drupal site for running functional and integration tests.
  *
  * Installs Drupal with the installation profile specified in
  * \Drupal\simpletest\WebTestBase::$profile into the prefixed database.
  *
  * Afterwards, installs any additional modules specified in the static
  * \Drupal\simpletest\WebTestBase::$modules property of each class in the
  * class hierarchy.
  *
  * After installation all caches are flushed and several configuration values
  * are reset to the values of the parent site executing the test, since the
  * default values may be incompatible with the environment in which tests are
  * being executed.
  */
 protected function setUp()
 {
     // When running tests through the Simpletest UI (vs. on the command line),
     // Simpletest's batch conflicts with the installer's batch. Batch API does
     // not support the concept of nested batches (in which the nested is not
     // progressive), so we need to temporarily pretend there was no batch.
     // Backup the currently running Simpletest batch.
     $this->originalBatch = batch_get();
     // Define information about the user 1 account.
     $this->rootUser = new UserSession(array('uid' => 1, 'name' => 'admin', 'mail' => '*****@*****.**', 'pass_raw' => $this->randomMachineName()));
     // The child site derives its session name from the database prefix when
     // running web tests.
     $this->generateSessionName($this->databasePrefix);
     // Reset the static batch to remove Simpletest's batch operations.
     $batch =& batch_get();
     $batch = array();
     // Get parameters for install_drupal() before removing global variables.
     $parameters = $this->installParameters();
     // Prepare installer settings that are not install_drupal() parameters.
     // Copy and prepare an actual settings.php, so as to resemble a regular
     // installation.
     // Not using File API; a potential error must trigger a PHP warning.
     $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
     copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
     copy(DRUPAL_ROOT . '/sites/default/default.services.yml', $directory . '/services.yml');
     // All file system paths are created by System module during installation.
     // @see system_requirements()
     // @see TestBase::prepareEnvironment()
     $settings['settings']['file_public_path'] = (object) array('value' => $this->publicFilesDirectory, 'required' => TRUE);
     $settings['settings']['file_private_path'] = (object) array('value' => $this->privateFilesDirectory, 'required' => TRUE);
     // Save the original site directory path, so that extensions in the
     // site-specific directory can still be discovered in the test site
     // environment.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
     $settings['settings']['test_parent_site'] = (object) array('value' => $this->originalSite, 'required' => TRUE);
     // Add the parent profile's search path to the child site's search paths.
     // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
     $settings['conf']['simpletest.settings']['parent_profile'] = (object) array('value' => $this->originalProfile, 'required' => TRUE);
     $settings['settings']['apcu_ensure_unique_prefix'] = (object) array('value' => FALSE, 'required' => TRUE);
     $this->writeSettings($settings);
     // Allow for test-specific overrides.
     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
     if (file_exists($settings_testing_file)) {
         // Copy the testing-specific settings.php overrides in place.
         copy($settings_testing_file, $directory . '/settings.testing.php');
         // Add the name of the testing class to settings.php and include the
         // testing specific overrides
         file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
     }
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
         // Copy the testing-specific service overrides in place.
         copy($settings_services_file, $directory . '/services.yml');
     }
     if ($this->strictConfigSchema) {
         // Add a listener to validate configuration schema on save.
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $services = $yaml->parse($directory . '/services.yml');
         $services['services']['simpletest.config_schema_checker'] = ['class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker', 'arguments' => ['@config.typed'], 'tags' => [['name' => 'event_subscriber']]];
         file_put_contents($directory . '/services.yml', $yaml->dump($services));
     }
     // Since Drupal is bootstrapped already, install_begin_request() will not
     // bootstrap again. Hence, we have to reload the newly written custom
     // settings.php manually.
     $class_loader = (require DRUPAL_ROOT . '/autoload.php');
     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
     // Execute the non-interactive installer.
     require_once DRUPAL_ROOT . '/core/includes/install.core.inc';
     install_drupal($class_loader, $parameters);
     // Import new settings.php written by the installer.
     Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $class_loader);
     foreach ($GLOBALS['config_directories'] as $type => $path) {
         $this->configDirectories[$type] = $path;
     }
     // After writing settings.php, the installer removes write permissions
     // from the site directory. To allow drupal_generate_test_ua() to write
     // a file containing the private key for drupal_valid_test_ua(), the site
     // directory has to be writable.
     // TestBase::restoreEnvironment() will delete the entire site directory.
     // Not using File API; a potential error must trigger a PHP warning.
     chmod($directory, 0777);
     $request = \Drupal::request();
     $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', TRUE);
     $this->kernel->prepareLegacyRequest($request);
     // Force the container to be built from scratch instead of loaded from the
     // disk. This forces us to not accidentally load the parent site.
     $container = $this->kernel->rebuildContainer();
     $config = $container->get('config.factory');
     // Manually create and configure private and temporary files directories.
     // While these could be preset/enforced in settings.php like the public
     // files directory above, some tests expect them to be configurable in the
     // UI. If declared in settings.php, they would no longer be configurable.
     file_prepare_directory($this->privateFilesDirectory, FILE_CREATE_DIRECTORY);
     file_prepare_directory($this->tempFilesDirectory, FILE_CREATE_DIRECTORY);
     $config->getEditable('system.file')->set('path.temporary', $this->tempFilesDirectory)->save();
     // Manually configure the test mail collector implementation to prevent
     // tests from sending out emails and collect them in state instead.
     // While this should be enforced via settings.php prior to installation,
     // some tests expect to be able to test mail system implementations.
     $config->getEditable('system.mail')->set('interface.default', 'test_mail_collector')->save();
     // By default, verbosely display all errors and disable all production
     // environment optimizations for all tests to avoid needless overhead and
     // ensure a sane default experience for test authors.
     // @see https://www.drupal.org/node/2259167
     $config->getEditable('system.logging')->set('error_level', 'verbose')->save();
     $config->getEditable('system.performance')->set('css.preprocess', FALSE)->set('js.preprocess', FALSE)->save();
     // Collect modules to install.
     $class = get_class($this);
     $modules = array();
     while ($class) {
         if (property_exists($class, 'modules')) {
             $modules = array_merge($modules, $class::$modules);
         }
         $class = get_parent_class($class);
     }
     if ($modules) {
         $modules = array_unique($modules);
         try {
             $success = $container->get('module_installer')->install($modules, TRUE);
             $this->assertTrue($success, SafeMarkup::format('Enabled modules: %modules', array('%modules' => implode(', ', $modules))));
         } catch (\Drupal\Core\Extension\MissingDependencyException $e) {
             // The exception message has all the details.
             $this->fail($e->getMessage());
         }
         $this->rebuildContainer();
     }
     // Restore the original Simpletest batch.
     $batch =& batch_get();
     $batch = $this->originalBatch;
     // Reset/rebuild all data structures after enabling the modules, primarily
     // to synchronize all data structures and caches between the test runner and
     // the child site.
     // @see \Drupal\Core\DrupalKernel::bootCode()
     // @todo Test-specific setUp() methods may set up further fixtures; find a
     //   way to execute this after setUp() is done, or to eliminate it entirely.
     $this->resetAll();
     $this->kernel->prepareLegacyRequest($request);
     // Explicitly call register() again on the container registered in \Drupal.
     // @todo This should already be called through
     //   DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that
     //   appears to be calling a different container.
     $this->container->get('stream_wrapper_manager')->register();
 }