예제 #1
1
 /**
  * @param      $string
  * @param null $path
  * @return string
  */
 public function parse($string, $path = null)
 {
     $headers = [];
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3);
     if (count($parts) == 3) {
         $string = $parts[0] . "\n" . $parts[2];
         $headers = $this->yaml->parse($parts[1]);
     }
     $file = new SplFileInfo($path, '', '');
     $date = Carbon::createFromTimestamp($file->getMTime());
     $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia');
     $headers['date_modified'] = $date->toDateTimeString();
     if (isset($headers['date'])) {
         try {
             $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString();
         } catch (\InvalidArgumentException $e) {
             $headers['date'] = $headers['date_modified'];
             //dd($e->getMessage());
         }
     } else {
         $headers['date'] = $headers['date_modified'];
     }
     $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers));
     $viewPath = PageHelper::filePathToViewPath($path);
     $cacheKey = "{$viewPath}.headers";
     $this->cache->put($cacheKey, $headers);
     return $string;
 }
 /**
  * Allow an extension to prepend the extension configurations.
  *
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  */
 public function prepend(ContainerBuilder $container)
 {
     $configFile = __DIR__ . '/../Resources/config/templates.yml';
     $config = Yaml::parse(file_get_contents($configFile));
     $container->prependExtensionConfig('ezpublish', $config);
     $container->addResource(new FileResource($configFile));
 }
 public function testAdd()
 {
     global $testHelpers, $mockPosts;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_post', ['times' => '1', 'return' => (object) $mockPosts['testpost1']]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => [(object) $mockPosts['testpost1']]]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $cli = $app['cli'];
     $p = new Commands\Posts();
     $p->add(array(10), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['posts']['post']));
 }
 public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $m = new Commands\Menus();
     $cli = $app['cli'];
     $cli->launch_self_return = (object) ['return_code' => 0, 'stdout' => json_encode([(object) ['term_id' => 1, 'name' => 'Main menu', 'slug' => 'main', 'locations' => ['primary', 'footer'], 'count' => 2]])];
     $m->add(array('main'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(1), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(999), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['menus']));
 }
예제 #5
0
 public function import()
 {
     $app = Bootstrap::getApplication();
     $settings = $app['settings'];
     $yaml = new Yaml();
     $helpers = $app['helpers'];
     $baseUrl = get_option('siteurl');
     if (!isset($settings['content']['menus'])) {
         return;
     }
     foreach ($settings['content']['menus'] as $menu) {
         $dir = WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}";
         $menuMeta = $yaml->parse(file_get_contents(WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}_manifest"));
         $newMenu = new \stdClass();
         $newMenu->slug = $menu;
         $newMenu->locations = $menuMeta['locations'];
         $newMenu->items = array();
         foreach ($helpers->getFiles($dir) as $file) {
             $menuItem = new \stdClass();
             $menuItem->done = false;
             $menuItem->id = 0;
             $menuItem->parentId = 0;
             $menuItem->slug = $file;
             //$menuItem->menu = unserialize(file_get_contents($dir.'/'.$file));
             $menuItem->menu = $yaml->parse(file_get_contents("{$dir}/{$file}"));
             $newMenu->items[] = $menuItem;
         }
         usort($newMenu->items, function ($a, $b) {
             return (int) $a->menu['menu_order'] - (int) $b->menu['menu_order'];
         });
         $this->menus[] = $newMenu;
     }
     $helpers->fieldSearchReplace($this->menus, Bootstrap::NEUTRALURL, $baseUrl);
     $this->process();
 }
예제 #6
0
 public function import()
 {
     $app = Bootstrap::getApplication();
     $helpers = $app['helpers'];
     $baseUrl = get_option('siteurl');
     $yaml = new Yaml();
     $dir = WPBOOT_BASEPATH . '/bootstrap/sidebars';
     foreach ($helpers->getFiles($dir) as $sidebar) {
         if (!is_dir(WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}")) {
             continue;
         }
         $subdir = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}";
         $manifest = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}_manifest";
         $newSidebar = new \stdClass();
         $newSidebar->slug = $sidebar;
         $newSidebar->items = array();
         $newSidebar->meta = $yaml->parse(file_get_contents($manifest));
         foreach ($newSidebar->meta as $key => $widgetRef) {
             $widget = new \stdClass();
             $parts = explode('-', $widgetRef);
             $ord = end($parts);
             $type = substr($widgetRef, 0, -1 * strlen('-' . $ord));
             $widget->type = $type;
             $widget->ord = $ord;
             $widget->meta = $yaml->parse(file_get_contents($subdir . '/' . $widgetRef));
             $newSidebar->items[] = $widget;
         }
         $this->sidebars[] = $newSidebar;
     }
     $helpers->fieldSearchReplace($this->sidebars, Bootstrap::NEUTRALURL, $baseUrl);
     $this->process();
 }
 public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_term_by', ['times' => '2', 'return' => (object) $mockTerms['catTerm1']]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $t = new Commands\Taxonomies();
     $t->add(array('category', 21), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'catTerm1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', '*'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('*', $settings['content']['taxonomies']['category'][0]);
     \WP_Mock::wpFunction('get_term_by', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'yadayada'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['taxonomies']['category']));
 }
예제 #8
0
 public function __construct(GruverConfig $config)
 {
     $this->config = $config;
     $this->options = array();
     $yaml = new Yaml();
     $this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-animals.yml'));
     $this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-colors.yml'));
 }
예제 #9
0
 /**
  * @param MenuEvent $event
  * @return Item
  * @throws InvalidYamlStructureException
  */
 public function createMainMenu(MenuEvent $event)
 {
     $config = $this->yaml->parse(file_get_contents($this->configFilePath), true, true);
     if (!isset($config['menu'])) {
         throw new InvalidYamlStructureException(sprintf('File "%s" should contain top level "menu:" key', $this->configFilePath));
     }
     $menu = $event->getMenu();
     $menu->setOptions(array('attr' => array('id' => 'top-menu', 'class' => 'nav navbar-nav')));
     $this->populateMenu($menu, $config['menu']);
     return $menu;
 }
예제 #10
0
 /**
  * Reads a settings file.
  *
  * @param  string $file A file to read.
  * @return array  The settings read.
  */
 public function read($file)
 {
     $file = '/settings/' . $file;
     /**
      * @todo validate that $file is a string
      */
     $result = [];
     if ($this->source_filesystem->has($file . '.yml')) {
         $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml'));
     }
     return $result;
 }
예제 #11
0
 /**
  * @param $fileName
  * @return mixed
  */
 protected function parseFile($fileName)
 {
     $definitions = $this->parser->parse(file_get_contents($fileName));
     if (count($definitions) == 0) {
         // Erreur
     }
     if (count($definitions) > 1) {
         // Erreur
     }
     $mappings = $this->mappingsExtract($definitions);
     $mappings = $this->mappingsNormalizeSyntax($mappings);
     return $mappings;
 }
 public function testYamlCacheHit()
 {
     $cacheMock = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->setMethods(array('contains', 'fetch'))->getMockForAbstractClass();
     $cacheMock->expects($this->once())->method('contains')->will($this->returnValue(true));
     $cacheMock->expects($this->once())->method('fetch')->will($this->returnValue(Yaml::parse($this->validYamlData)));
     new YamlConfig($this->validYamlData, $cacheMock);
 }
예제 #13
0
 /**
  * Validate the configuration file
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->iohandler_factory->set_environment('cli');
     /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
     $iohandler = $this->iohandler_factory->get();
     $style = new SymfonyStyle($input, $output);
     $iohandler->set_style($style, $output);
     $config_file = $input->getArgument('config-file');
     if (!is_file($config_file)) {
         $iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
         return 1;
     }
     try {
         $config = Yaml::parse(file_get_contents($config_file), true, false);
     } catch (ParseException $e) {
         $iohandler->add_error_message('INVALID_YAML_FILE');
         return 1;
     }
     $processor = new Processor();
     $configuration = new updater_configuration();
     try {
         $processor->processConfiguration($configuration, $config);
     } catch (Exception $e) {
         $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
         return 1;
     }
     $iohandler->add_success_message('CONFIGURATION_VALID');
     return 0;
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public static function fromString($string, Translations $translations, array $options = [])
 {
     $messages = YamlParser::parse($string);
     if (is_array($messages)) {
         self::fromArray($messages, $translations);
     }
 }
 public function testParseAndDump()
 {
     $data = array('lorem' => 'ipsum', 'dolor' => 'sit');
     $yml = Yaml::dump($data);
     $parsed = Yaml::parse($yml);
     $this->assertEquals($data, $parsed);
 }
예제 #16
0
 /**
  * @param string $configFile A path to a yaml config file
  * @return array The config matrix
  *
  * @throws ResourceNotFoundException
  */
 public function load($configFile)
 {
     if (!is_file($configFile)) {
         throw new ResourceNotFoundException(sprintf('The config file "%s" was not found.', $configFile));
     }
     return Yaml::parse(file_get_contents($configFile));
 }
예제 #17
0
 protected function getSubDirectoriesInfos($rootDir, $infoFilename)
 {
     if ($rootDir[0] == '~') {
         if (DIRECTORY_SEPARATOR == '\\') {
             $rootDir = $_SERVER['USERPROFILE'] . substr($rootDir, 1);
         } else {
             $rootDir = $_SERVER['HOME'] . substr($rootDir, 1);
         }
     }
     $infos = array();
     $it = new \FilesystemIterator($rootDir);
     foreach ($it as $subDir) {
         if ($it->isDot() || !$it->isDir()) {
             continue;
         }
         $defaultInfo = array('name' => $subDir->getFilename(), 'description' => '', 'dir' => $subDir->getPathname(), 'source' => $subDir->getPathname());
         $infoPath = $subDir->getPathname() . DIRECTORY_SEPARATOR . $infoFilename;
         if (is_file($infoPath)) {
             $infos[] = array_merge($defaultInfo, Yaml::parse($infoPath));
         } else {
             $infos[] = $defaultInfo;
         }
     }
     return $infos;
 }
예제 #18
0
파일: Config.php 프로젝트: anroots/pgca
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.StaticAccess)
  */
 public function load()
 {
     $locator = new FileLocator($this->paths);
     $configFile = $locator->locate('pgca.yml');
     $fileContents = Yaml::parse(file_get_contents($configFile), true);
     $this->config = new Data($fileContents);
 }
예제 #19
0
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $config = Yaml::parse($path);
     $collection = new TrailCollection();
     $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->normalizeTrailConfig($config);
         if (isset($config['resource'])) {
             $root = isset($config['root']) ? $config['root'] : null;
             $type = isset($config['type']) ? $config['type'] : null;
             $this->setCurrentDir(dirname($path));
             $collection->addCollection($this->import($config['resource'], $type, false, $file), $root);
         } else {
             $this->parseTrail($collection, $name, $config, $path);
         }
     }
     return $collection;
 }
예제 #20
0
파일: YAML.php 프로젝트: kherge/wisdom
 /** {@inheritDoc} */
 public function load($resource, $type = null)
 {
     if (false === ($data = file_get_contents($resource))) {
         throw new RuntimeException(sprintf('Unable to read file: %s', $resource));
     }
     return Base::parse($this->doReplace($data));
 }
예제 #21
0
 public function testRouteSetupInstallerInstall()
 {
     $emMock = $this->createEntityManagerMock();
     $this->app['repo.sessions'] = $this->createEntityRepositoryMock();
     $this->app['EM'] = $emMock;
     $this->app['phraseanet.configuration-tester']->expects($this->once())->method('isBlank')->will($this->returnValue(true));
     $this->app['phraseanet.installer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Setup\\Installer')->disableOriginalConstructor()->getMock();
     $user = $this->createUserMock();
     $this->app['phraseanet.installer']->expects($this->once())->method('install')->will($this->returnValue($user));
     $authenticator = $this->getMockBuilder('Alchemy\\Phrasea\\Authentication\\Authenticator')->disableOriginalConstructor()->getMock();
     $session = $this->getMock('Entities\\Session');
     $authenticator->expects($this->once())->method('openAccount')->with($this->equalTo($user))->will($this->returnValue($session));
     $this->app['authentication'] = $authenticator;
     $client = $this->createClient();
     $settings = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../resources/hudson/InstallDBs.yml'));
     $settings = $settings['database'];
     $host = isset($settings['host']) ? $settings['host'] : 'localhost';
     $port = isset($settings['port']) ? $settings['port'] : '3306';
     $user = isset($settings['user']) ? $settings['user'] : '******';
     $password = isset($settings['password']) ? $settings['password'] : '';
     $abName = isset($settings['ab_name']) ? $settings['ab_name'] : null;
     $dbName = isset($settings['db_name']) ? $settings['db_name'] : null;
     $params = array('email' => '*****@*****.**', 'password' => 'prètty%%password', 'binary_xpdf' => '/path/to/xpdf', 'binary_mplayer' => '/path/to/mplayer', 'binary_MP4Box' => '/path/to/MP4Box', 'binary_ffmpeg' => '/path/to/ffmpeg', 'binary_unoconv' => '/path/to/unoconv', 'binary_swfrender' => '/path/to/swfrender', 'binary_pdf2swf' => '/path/to/pdf2swf', 'binary_swfextract' => '/path/to/swfextract', 'binary_exiftool' => '/path/to/exiftool', 'binary_composite' => '/path/to/composite', 'binary_convert' => '/path/to/convert', 'binary_php' => '/path/to/php', 'datapath_noweb' => sys_get_temp_dir() . '/datainstall/noweb', 'hostname' => $host, 'port' => $port, 'user' => $user, 'db_password' => $password, 'ab_name' => $abName, 'db_name' => $dbName, 'db_template' => 'en', 'create_task' => array(), 'binary_phraseanet_indexer' => '/path/to/phraseanet_indexer');
     $client->request('POST', '/setup/installer/install/', $params);
     $response = $client->getResponse();
     $this->assertEquals(302, $response->getStatusCode());
     $this->assertTrue(false === strpos($response->headers->get('location'), '/setup/installer/'), $response);
 }
예제 #22
0
 public static function main($argc, $argv)
 {
     if ($argc < 2) {
         echo 'Usage: php test.php number_of_files_to_copy' . PHP_EOL;
         exit;
     }
     $numFilesToCopy = (int) $argv[1];
     if ($numFilesToCopy < 1) {
         $numFilesToCopy = 1;
     }
     $fileName = 'test.yml';
     $filePath = __DIR__ . '/' . $fileName;
     $yamlArr = Yaml::parse(file_get_contents($filePath));
     $newFilenamePrefix = $yamlArr['new_filename_prefix'];
     try {
         $filesystem = new Filesystem();
         for ($i = 1; $i <= $numFilesToCopy; $i++) {
             $newFilepath = __DIR__ . "/{$newFilenamePrefix}_{$i}.yml";
             $filesystem->copy($filePath, $newFilepath);
         }
     } catch (FileNotFoundException $e) {
         echo "File '{$filePath}' could not be found!" . PHP_EOL;
     } catch (IOException $e) {
         echo "Could not copy file '{$filePath}' to '{$newFilepath}'!" . PHP_EOL;
     } finally {
         // Just for fun
         unset($filesystem);
     }
     $funny = (int) ((0.7 + 0.1) * 10);
     echo $funny . PHP_EOL;
     $notFunny = BigDecimal::of(0.7)->plus(BigDecimal::of(0.1))->multipliedBy(10)->toInteger();
     echo $notFunny . PHP_EOL;
     $notFunny = BigRational::of('7/10')->plus(BigRational::of('1/10'))->multipliedBy(10)->toInteger();
     echo $notFunny . PHP_EOL;
 }
예제 #23
0
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $amiAddress = $value['examples']['client']['ami_address'];
     $logger = new Log\Logger();
     $logWriter = new Log\Writer\Stream("php://output");
     $logger->addWriter($logWriter);
     //$filter = new Log\Filter\SuppressFilter(true);
     $filter = new Log\Filter\Priority(Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     // Connect to the ARI server
     $client = new Phparia($logger);
     $client->connect($ariAddress, $amiAddress);
     $this->client = $client;
     // Listen for the stasis start
     $client->onStasisStart(function (StasisStart $event) {
         // Put the new channel in a bridge
         $channel = $event->getChannel();
         $bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'bridgename');
         $this->client->bridges()->addChannel($bridge->getId(), $channel->getId());
         // Listen for DTMF and hangup when '#' is pressed
         $channel->onChannelDtmfReceived(function (ChannelDtmfReceived $event) use($channel) {
             $this->log("Got digit: {$event->getDigit()}");
             if ($event->getDigit() === '#') {
                 $channel->hangup();
             }
         });
         $this->client->getWsClient()->on('Hangup', function ($event) {
             $this->log('User hung up');
         });
     });
     $this->client->run();
 }
예제 #24
0
 /**
  * @Route ("/apiway", name="apiway")
  */
 public function apiAction()
 {
     $em = $this->getDoctrine()->getManager();
     //clear table first
     $sql = "DELETE FROM video";
     $stmt = $this->getDoctrine()->getManager()->getConnection()->prepare($sql);
     $stmt->execute();
     #get artists list from yaml file as Symfony good form
     $artists = Yaml::parse(file_get_contents("artists.yml"));
     #used of Google Client is unnecessary because not used OAuth2, just only query with key
     $developer_key = $this->container->getParameter("google_api_key");
     $client = new Google_Client();
     $client->setDeveloperKey($developer_key);
     $youtube = new Google_Service_YouTube($client);
     foreach ($artists as $artist) {
         $search_response = $youtube->search->listSearch("id", ['q' => $artist, 'maxResults' => 5, 'type' => 'video']);
         #merge video IDs for getting statistic data by artists video
         $videoResults = [];
         foreach ($search_response['items'] as $searchResult) {
             array_push($videoResults, $searchResult['id']['videoId']);
         }
         $videoIds = join(',', $videoResults);
         $videosResponse = $youtube->videos->listVideos('snippet, statistics', array('id' => $videoIds));
         foreach ($videosResponse['items'] as $videoResult) {
             $video = new Video();
             $video->setAuthor($artist);
             $video->setLink($videoResult['id']);
             $video->setName($videoResult['snippet']['title']);
             $video->setViews($videoResult['statistics']['viewCount']);
             $em->persist($video);
         }
         $em->flush();
     }
     return $this->redirect($this->generateUrl("homepage"));
 }
예제 #25
0
 private function updateAppRoutes()
 {
     $appRoutingFile = $this->kernelRoot . '/config/routing.yml';
     if (!realpath($appRoutingFile)) {
     }
     $routing = Yaml::parse(file_get_contents($appRoutingFile));
 }
예제 #26
0
 /**
  * Convert a yaml string to an array.
  *
  * {@inheritDoc}
  */
 public static function decode($string)
 {
     if (!$string) {
         return [];
     }
     return SymfonyYaml::parse($string);
 }
예제 #27
0
 public function __construct()
 {
     $configFile = __DIR__ . '/../config.yml';
     $value = Yaml::parse(file_get_contents($configFile));
     $ariAddress = $value['examples']['client']['ari_address'];
     $dialString = $value['examples']['dial_example']['dial_string'];
     $logger = new \Zend\Log\Logger();
     $logWriter = new \Zend\Log\Writer\Stream("php://output");
     $logger->addWriter($logWriter);
     //$filter = new \Zend\Log\Filter\SuppressFilter(true);
     $filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
     $logWriter->addFilter($filter);
     // Connect to the ARI server
     $this->client = new Phparia($logger);
     $this->client->connect($ariAddress);
     $this->client->getAriClient()->onConnect(function () use($dialString) {
         try {
             $this->client->channels()->createChannel($dialString, null, null, null, null, $this->client->getStasisApplicationName(), 'dialed', '8185551212', 30, null, null, array('MYVARIABLE' => 'value'));
         } catch (\phparia\Exception\ServerException $e) {
             $this->log($e->getMessage());
         }
     });
     // Listen for the stasis start
     $this->client->onStasisStart(function (StasisStart $event) use($dialString) {
         if (count($event->getArgs()) > 0 && $event->getArgs()[0] === 'dialed') {
             $this->log('Detected outgoing call with variable MYVARIABLE=' . $event->getChannel()->getVariable('MYVARIABLE')->getValue());
             // Put the new channel in a bridge
             $channel = $event->getChannel();
             $this->bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'dial_example_bridge');
             $this->bridge->addChannel($channel->getId());
         }
     });
     $this->client->run();
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 protected function transformDataToArray($file)
 {
     if (strpos($file, "\n") === false && is_file($file)) {
         if (false === is_readable($file)) {
             throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $file));
         }
         if (null !== $this->container && $this->container->has('faker.generator')) {
             $generator = $this->container->get('faker.generator');
             $faker = function ($type) use($generator) {
                 $args = func_get_args();
                 array_shift($args);
                 echo Yaml::dump(call_user_func_array(array($generator, $type), $args)) . "\n";
             };
         } else {
             $faker = function ($text) {
                 echo $text . "\n";
             };
         }
         ob_start();
         $retval = (include $file);
         $content = ob_get_clean();
         // if an array is returned by the config file assume it's in plain php form else in YAML
         $file = is_array($retval) ? $retval : $content;
         // if an array is returned by the config file assume it's in plain php form else in YAML
         if (is_array($file)) {
             return $file;
         }
     }
     return Yaml::parse($file);
 }
 /**
  * @param string $serviceId
  * @param string $modelClass
  * @param string $adminClass
  * @param string $controllerName
  * @param string $managerType
  *
  * @throws \RuntimeException
  */
 public function addResource($serviceId, $modelClass, $adminClass, $controllerName, $managerType)
 {
     $code = "services:\n";
     if (is_file($this->file)) {
         $code = rtrim(file_get_contents($this->file));
         $data = (array) Yaml::parse($code);
         if ($code !== '') {
             $code .= "\n";
         }
         if (array_key_exists('services', $data)) {
             if (array_key_exists($serviceId, (array) $data['services'])) {
                 throw new \RuntimeException(sprintf('The service "%s" is already defined in the file "%s".', $serviceId, realpath($this->file)));
             }
             if ($data['services'] !== null) {
                 $code .= "\n";
             }
         } else {
             $code .= $code === '' ? '' : "\n" . "services:\n";
         }
     }
     $code .= sprintf($this->template, $serviceId, $adminClass, $modelClass, $controllerName, $managerType, current(array_slice(explode('\\', $modelClass), -1)));
     @mkdir(dirname($this->file), 0777, true);
     if (@file_put_contents($this->file, $code) === false) {
         throw new \RuntimeException(sprintf('Unable to append service "%s" to the file "%s". You will have to do it manually.', $serviceId, $this->file));
     }
 }
예제 #30
-1
 /**
  * {@inheritdoc}
  */
 public function parse($value, QueryBuilder $qb)
 {
     if (!is_array($value)) {
         $value = Yaml::parse($value);
     }
     $processor = new Processor();
     $value = $processor->processConfiguration(new QueryConfiguration(), $value);
     if (!isset($value['from'])) {
         throw new \RuntimeException('Missing mandatory "from" section');
     }
     foreach ((array) $value['from'] as $from) {
         $qb->from($from['table'], $from['alias']);
     }
     if (isset($value['select'])) {
         foreach ($value['select'] as $select) {
             $qb->add('select', new Expr\Select($select), true);
         }
     }
     if (isset($value['distinct'])) {
         $qb->distinct((bool) $value['distinct']);
     }
     if (isset($value['groupBy'])) {
         $qb->groupBy($value['groupBy']);
     }
     if (isset($value['having'])) {
         $qb->having($value['having']);
     }
     $this->addJoin($qb, $value);
     $this->addWhere($qb, $value);
     $this->addOrder($qb, $value);
     return $qb;
 }