Ver Fonte

first commit

Maximiliano Schvindt há 8 anos atrás
commit
619ec27f86

+ 17 - 0
Controller/DefaultController.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace WebserviceBundle\Controller;
+
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+
+class DefaultController extends Controller
+{
+    /**
+     * @Route("/")
+     */
+    public function indexAction()
+    {
+        return $this->render('WebserviceBundle:Default:index.html.twig');
+    }
+}

+ 4 - 0
Resources/config/services.yml

@@ -0,0 +1,4 @@
+services:
+   webservice:
+       class: WebserviceBundle\Services\Webservice
+       arguments: ["@service_container"]

+ 1 - 0
Resources/views/Default/index.html.twig

@@ -0,0 +1 @@
+Hello World!

+ 75 - 0
Services/Webservice.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace WebserviceBundle\Services;
+
+class Webservice
+{
+
+    protected $serviceContainer;
+
+    
+    public function __construct($serviceContainer)
+    {
+        $this->serviceContainer = $serviceContainer;
+    }
+
+    /**
+     * @param string $webservice
+     * @param array $params
+     * @return array
+     */
+    public function getChoices($webservice, $params = array())
+    {
+        $choices = array();
+        if ($this->serviceContainer->hasParameter($webservice)) {
+            $url = $this->serviceContainer->getParameter($webservice);
+            $objectsJson = json_decode(file_get_contents($url), true);
+            foreach ($objectsJson as $object) {
+                $choices["{$object['name']} - {$object['external_id']}"] = $object['id'];
+            }
+        }
+
+        return $choices;
+    }
+
+    /**
+     * @param string $webservice
+     * @param array $filters
+     * @param array $order_by
+     * @param integer $limit
+     * @param integer $offset
+     * @return array
+     */
+    public function getData($webservice, $filters = array(), $order_by = array(), $limit = null, $offset = null)
+    {
+        if ($this->serviceContainer->hasParameter($webservice)) {
+            $url = $this->serviceContainer->getParameter($webservice) . "?";
+            
+            if($filters) {
+
+                $url .= http_build_query(array('filters' => $filters));
+            }
+            
+            if($order_by) {
+                $url .= http_build_query(array('order_by' => $order_by));
+            }
+            
+            if($limit) {
+                $url .= "&limit={$limit}";
+            }
+            
+            if($offset) {
+                $url .= "&offset={$offset}";
+            }
+
+            $data = json_decode(file_get_contents($url), true);
+
+            //$data['url'] = $url;
+
+            return $data;
+        }
+
+        return array();
+    }
+
+}

+ 9 - 0
WebserviceBundle.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace WebserviceBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class WebserviceBundle extends Bundle
+{
+}

+ 9 - 0
composer.json

@@ -0,0 +1,9 @@
+{
+    "name": "webservice",
+    "description": "The Flowdat3 Webservice Rest",
+    "autoload": {
+        "psr-4": { "WebserviceBundle\\": "" }
+    },
+	"version": "1.0",
+  	"minimum-stability": "stable"
+}