Last active
August 29, 2015 14:00
-
-
Save alex-moreno/11112325 to your computer and use it in GitHub Desktop.
using symfony dependency injection in Drupal 7 (parameters)
This file contains 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
# CruiseHunter Config Yaml. | |
parameters: | |
agency: NULL | |
services: | |
cruise_hunter_fetcher: | |
class: CruiseHunter\CruiseHunterFetcher | |
arguments: | |
# Agency from which we will fetch the information | |
- "@agency" |
This file contains 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 | |
/** | |
* Register a name class in Drupal | |
* Implements hook_namespace_register(). | |
*/ | |
function cruisehunter_namespace_register() { | |
// Structure array('<namespace>' => '<path>'); | |
return array( | |
'CruiseHunter' => __DIR__ . '/lib', | |
); | |
} |
This file contains 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 | |
/** | |
* Created by PhpStorm. | |
* User: Alex Moreno | |
* Date: 16/03/2014 | |
* Time: 16:19 | |
*/ | |
namespace CruiseHunter; | |
/** | |
* Class CruiseHunterFetcher | |
* | |
* @package CruiseHunter | |
*/ | |
class CruiseHunterFetcher { | |
// List of Cruises in that object. | |
protected $listOfCruises; | |
/** | |
* Execute robot to fetch the list of cruises from a given url. | |
* | |
* @param $url | |
* URL from which start the crawl. | |
* | |
* @return array | |
* Array with the list of cruises. | |
*/ | |
public function fetchListofCruises($url) { | |
$this->listOfCruises = array(); | |
} | |
/** | |
* Return the list of cruises. | |
* | |
* @return array | |
* list of cruises in that object. | |
*/ | |
public function getListCruises() { | |
return $this->listOfCruises; | |
} | |
/** | |
* Function to find cruise dates in an array or urls. | |
* | |
* @urls | |
*/ | |
public function find_prices($urls) { | |
} | |
/** | |
* Normalize string | |
* | |
* @param $string_to_normalize | |
* Normalized string $string_normalized | |
* | |
* @return mixed | |
*/ | |
public function normalize($string_to_normalize){ | |
return str_replace("€","",$string_to_normalize); | |
} | |
} |
This file contains 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 | |
/** | |
* Example function to fetch cruises from site agencies. | |
* | |
*/ | |
function fetch_cruises() { | |
try { | |
global $_drupal_symfony_di_container; | |
if (isset($_drupal_symfony_di_container)) { | |
$service_manager = $_drupal_symfony_di_container->get('cruise_hunter_fetcher'); | |
$cruises = $service_manager->fetchListofCruises(); | |
} | |
} | |
catch(Exception $exp) { | |
watchdog_exception('cruise_hunter', $exp); | |
} | |
return $cruises; | |
} |
This file contains 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 | |
/** | |
* Implements hook_symfony_yaml_config(). | |
*/ | |
function cruisehunter_symfony_yaml_config() { | |
// Return the path of the Yaml config files. | |
// Structure array('<filename>' => '<file_path>'); | |
return array( | |
'config.yaml' => drupal_get_path('module', 'cruisehunter') . '/config/yaml', | |
); | |
} |
This file contains 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 | |
/** | |
* Implements hook_symfony_yaml_config_params(). | |
*/ | |
function cruisehunter_symfony_yaml_config_params($container_builder) { | |
// Param array to compile. | |
$param_array = array(); | |
if ($container_builder instanceof ContainerBuilder) { | |
// Generic Web Service Settings. | |
$proxy_host = variable_get(WEBSERVICE_PROXY_HOST, NULL); | |
$proxy_host = variable_get(WEBSERVICE_PROXY_PORT, NULL); | |
// Add the proxy host and the port. | |
if (isset($proxy_host) && isset($proxy_port)) { | |
// Set proxy for wsdl client. | |
$wsdl_pfw_options['WEBSERVICE_PROXY_HOST'] = $proxy_host; | |
$wsdl_pfw_options['WEBSERVICE_PROXY_PORT'] = $proxy_port; | |
} | |
} | |
return $param_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment