Permalink
Browse files

initial commit

  • Loading branch information...
Jirgn Mssnr
Jirgn Mssnr committed Jan 25, 2013
0 parents commit 63afd286ebc31b861948ffc6b52dab62218b7013
@@ -0,0 +1,92 @@
+# itCrossAppRouting Plugin
+
+## Requirements
+* sfDependencyInjectionPlugin
+
+## Installation
+
+## copy and activate
+Copy the plugin to your projects plugins folder.
+You have to activate the Plugin in your global ProjectConfiguration.
+ class ProjectConfiguration extends sfProjectConfiguration {
+ ...
+ public function setup() {
+ ...
+ $this->enablePlugins(array(
+ ...
+ 'itCrossAppRoutingPlugin',
+ ...
+ //notice that the sfDependencyInjectionPlugin has to be enabled AFTER the itCrossAppRoutingPlguin
+ 'sfDependencyInjectionPlugin',
+ );
+ }
+ }
+
+### register helper
+The helper itCrossAppRoutingHelper can also be globally enabeld.
+This will be done by defining it as standard_helper in settings.yml @see http://www.symfony-project.org/reference/1_4/en/04-Settings#chapter_04_sub_standard_helpers
+
+### set app_routing.yml
+The Plugin entroduces a new configurationfile 'app_routing.yml'.
+This is an Environment specific yml Config like the most symfony config files.
+
+The following settings are supported
+Example:
+ ../config/app_routing.yml
+ all:
+ # key is the application name
+ # optionally you can use the :sf_culture placeholder to inject the cluture in path prefix
+ online_guard:
+ domain: http://ifb.berlinale.de
+ route_prefix: :domain/:sf_culture/path/to/online_guard
+ online_boa:
+ domain: http://ifb.berlinale.de
+ route_prefix: :domain/:sf_culture/path/to/online_boa
+
+## Usage
+The Routing can be called due to the configured service 'app_routing'
+
+### Example Actions / Components
+ ../actions.class.php
+ public function executeMyAction() {
+ $this->getService('app_routing')
+ ->generateApplicationUrl(
+ 'application_name',
+ 'route_name',
+ array('param'=>'123test',
+ $absolute)
+ );
+ ...
+ }
+
+### Example anywhere in the symfony context (eg. filter, ..)
+
+ public function getAnApplicationLink(){
+ $appRouting = sfContext::getInstance()->getConfiguration()->getService('app_routing');
+ return $appRouting->generateApplicationUrl(
+ 'application_name',
+ 'route_name',
+ array('param'=>'123test', $absolute);
+ }
+
+### Example template
+ ../myActionSuccess.php
+ //include helper if not already defined in standard_helpers
+ use_helper('itCrossAppRouting');
+
+ echo it_cross_app_url_for('app_name', 'route_name', array('param'=>'test123'));
+
+### Usage via string notation
+
+for using in routing.yml there is an altenative syntax to descripe app routings
+the convention is like
+
+ $alternativeNotation = '@@appname?app_param=value@routename?routeparam=othervalue'
+
+so you can call
+
+ $appRouting->generateApplicationUrlByString($alternativeNotation);
+
+
+
+
@@ -0,0 +1,65 @@
+all: &default
+ domain: http://www.cornelsen.de
+ duden_domain: http://www.duden-schulverlage.de
+ duden_sbk_base:
+ # domain: can/be/specified/here
+ route_prefix: :duden_domain/:alias/
+ sbk_base:
+# domain: can/be/specified/here
+ route_prefix: :domain/:alias/
+ lehrkraefte:
+# domain: can/be/specified/here
+ route_prefix: :domain/lehrkraefte
+ home:
+# domain: can/be/specified/here
+ route_prefix: :domain/home
+
+
+dev_test: &dev_test
+ <<: *default
+ domain: http://test.cornelsen.de
+ duden_domain: http://test.cornelsen.de
+
+test:
+ <<: *dev_test
+
+dev_test2: &dev_test2
+ <<: *default
+ domain: http://test2.cornelsen.de
+ duden_domain: http://test2.cornelsen.de
+
+test2:
+ <<: *dev_test2
+
+dev_referenz: &dev_referenz
+ <<: *default
+ domain: http://referenz.cornelsen.de
+ duden_domain: http://referenz.cornelsen.de
+
+referenz:
+ <<: *dev_referenz
+
+dev_entwicklung: &dev_entwicklung
+ <<: *default
+ domain: http://entwicklung.cornelsen.de
+ duden_domain: http://entwicklung.cornelsen.de
+
+entwicklung:
+ <<: *dev_entwicklung
+
+dev_entwicklung2: &dev_entwicklung2
+ <<: *default
+ domain: http://entwicklung2.cornelsen.de
+ duden_domain: http://entwicklung2.cornelsen.de
+
+entwicklung2:
+ <<: *dev_entwicklung2
+
+
+dev_local: &dev_local
+ <<: *default
+ domain: http://cornelsen.vbox
+ duden_domain: http://cornelsen.vbox
+
+prod_local:
+ <<: *dev_local
@@ -0,0 +1,5 @@
+config/app_routing.yml:
+ class: itCrossAppConfigHandler
+ file: %SF_PLUGINS_DIR%/itCrossAppRoutingPlugin/lib/config/itCrossAppConfigHandler.class.php
+ param:
+ prefix: sf_app_routing
@@ -0,0 +1,30 @@
+<?php
+class itCrossAppRoutingPluginConfiguration extends sfPluginConfiguration {
+
+ public function initialize() {
+ $this->initAppRoutingConfig();
+ $this->dispatcher->connect('service_container.load_configuration', array($this, 'listenToServiceContainerLoadConfiguration'));
+ }
+
+ public function listenToServiceContainerLoadConfiguration(sfEvent $event) {
+ $container = $event->getSubject();
+ $loader = new sfServiceContainerLoaderFileYaml($container);
+ $loader->load(dirname(__FILE__).'/services.yml');
+ }
+
+ /**
+ * inits application route config app_routing.yml
+ */
+ protected function initAppRoutingConfig() {
+
+ $config = 'config/app_routing.yml';
+ if($this->configuration instanceof sfApplicationConfiguration) {
+ $cacheConfig = new sfConfigCache($this->configuration);
+ $cacheConfig->import($config, true);
+ }
+ else {
+ $configFiles = $this->configuration->getConfigPaths($config);
+ sfConfig::set(itCrossAppConfigHandler::DEFAULT_PREFIX, itCrossAppConfigHandler::getConfiguration($configFiles));
+ }
+ }
+}
@@ -0,0 +1,7 @@
+parameters:
+ testparam: foo
+
+services:
+ app_routing:
+ class: itCrossAppRoutingService
+ shared: true
@@ -0,0 +1,30 @@
+<?php
+
+class itCrossAppConfigHandler extends sfYamlConfigHandler {
+
+ const DEFAULT_PREFIX = 'sf_app_routing';
+
+ public function execute($configFiles)
+ {
+
+ $prefix = strtolower($this->getParameterHolder()->get('prefix', self::DEFAULT_PREFIX));
+ $config = self::getConfiguration($configFiles);
+
+ // compile data
+ $retval = sprintf("<?php\n".
+ "// auto-generated by %s\n".
+ "// date: %s\nsfConfig::set('{$prefix}', \n%s\n);\n?>",
+ __CLASS__, date('Y/m/d H:i:s'), var_export($config,true));
+
+ return $retval;
+ }
+
+ /**
+ * @see sfConfigHandler
+ */
+ static public function getConfiguration(array $configFiles)
+ {
+ return self::replaceConstants(self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles)));
+ }
+
+}
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ *
+ * generates a url for given app route
+ * @param string $app_name
+ * @param string $route_name
+ * @param array $params
+ * @return string absolute url to application route
+ */
+function it_cross_app_url_for($app_name, $route_name, $params = array(), $absolute = false, $prefixParams = array())
+{
+ return sfContext::getInstance()
+ ->getConfiguration()
+ ->getService('app_routing')
+ ->generateApplicationUrl(
+ $app_name,
+ $route_name,
+ $params,
+ $absolute,
+ $prefixParams
+ );
+}
+
+/**
+ *
+ * generates url based on mofified uri string
+ * @param string $uridef in form @@appname?prefixparam1=value&prefixparam2=...@routename?routeparam1=value&routeparam2=value
+ * @return string
+ */
+function it_cross_app_url_for2($uridef, $absolute = false)
+{
+ if (preg_match('(^\w?://)', $uridef)) {
+ return $uridef;
+ }
+
+ return sfContext::getInstance()
+ ->getConfiguration()
+ ->getService('app_routing')
+ ->generateApplicationUrlByString($uridef, $absolute);
+}
Oops, something went wrong.

0 comments on commit 63afd28

Please sign in to comment.