Created
February 5, 2015 22:38
-
-
Save wouterj/52a4ddcf4b9eb5c23dd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Kunstmaan\LiveReloadBundle\DependencyInjection; | |
| use Symfony\Component\Config\Definition\Builder\TreeBuilder; | |
| use Symfony\Component\Config\Definition\ConfigurationInterface; | |
| /** | |
| * This is the class that validates and merges configuration from your app/config files | |
| * | |
| * To learn more see {@link | |
| * http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class} | |
| */ | |
| class Configuration implements ConfigurationInterface | |
| { | |
| /** | |
| * {@inheritDoc} | |
| */ | |
| public function getConfigTreeBuilder() | |
| { | |
| $treeBuilder = new TreeBuilder(); | |
| $rootNode = $treeBuilder->root('kunstmaan_live_reload'); | |
| $rootNode | |
| ->normalize() | |
| ->ifTrue(function ($v) { return isset($v['host']) && isset($v['port']); }) | |
| ->then(function ($v) { | |
| $url = 'http://' . $v['host'] . ':' . $v['port'] . '/livereload.js'; | |
| $v['server_url'] = $url; | |
| $v['script_url'] = $url; | |
| return $v; | |
| }) | |
| ->end() | |
| ->children() | |
| ->booleanNode('enabled') | |
| ->defaultTrue() | |
| ->end() | |
| ->scalarNode('host') | |
| ->end() | |
| ->scalarNode('port') | |
| ->end() | |
| ->scalarNode('server_url') | |
| ->defaultValue('http://localhost:35729/livereload.js') | |
| ->end() | |
| ->scalarNode('script_url') | |
| ->defaultValue('http://localhost:35729/livereload.js') | |
| ->end() | |
| ->booleanNode('check_server_presence') | |
| ->defaultTrue() | |
| ->end() | |
| ->end() | |
| ->validate() | |
| ->ifTrue(function($v) { | |
| return array_key_exists('host', $v) || array_key_exists('port', $v) | |
| && (array_key_exists('server_url', $v) || array_key_exists('script_url', $v)); | |
| }) | |
| ->thenInvalid('"host" and "port" cannot be used together with "script_url" or "server_url"') | |
| ->end() | |
| ; | |
| return $treeBuilder; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment