12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace WebserviceBundle\Services;
- class Webservice
- {
- /**
- * @var ServiceContainer
- */
- protected $serviceContainer;
-
- /**
- * @param ServiceContainer $serviceContainer
- */
- public function __construct($serviceContainer)
- {
- $this->serviceContainer = $serviceContainer;
- }
- /**
- * @param string $webservice
- * @param array $params
- * @return array
- */
- public function getChoices($webservice, $params = array())
- {
- $choices = array();
- $objectsJson = $this->getArray($webservice, $params);
- foreach ($objectsJson as $object) {
- $choices[$object['name']] = $object['id'];
- }
- return $choices;
- }
-
- /**
- * @param string $webservice
- * @param array $params
- * @return array
- */
- public function getArray($webservice, $params = array())
- {
- $objectsJson = array();
- if ($this->serviceContainer->hasParameter($webservice)) {
- $url = $this->serviceContainer->getParameter($webservice);
- $url .= '?filters[qb-criteria]';
- foreach ($params as $param => $value) {
- $url .= "&filters[{$param}]=$value";
- }
- $objectsJson = json_decode(file_get_contents($url), true);
- }
-
- return $objectsJson;
- }
- }
|