Browse Source

Added package files

Jan Oris 11 years ago
parent
commit
1c66cf5e88

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+/vendor
+composer.phar
+composer.lock
+.DS_Store

+ 12 - 0
.travis.yml

@@ -0,0 +1,12 @@
+language: php
+
+php: 
+  - 5.3
+  - 5.4
+  - 5.5
+
+before_script:
+  - curl -s http://getcomposer.org/installer | php
+  - php composer.phar install --dev
+
+script: phpunit

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
 Curl
 ====
 
-Custom PHP Curl library
+Custom PHP Curl library - developed by Ixudra

+ 27 - 0
composer.json

@@ -0,0 +1,27 @@
+{
+    "name": "ixudra/curl",
+    "description": "Custom PHP Curl library - developer by Ixudra",
+    "version": "0.1.0",
+    "keywords": ["Ixudra", "Laravel", "Curl"],
+    "homepage": "http://ixudra.be",
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "Jan Oris",
+            "email": "[email protected]"
+        }
+    ],
+    "require": {
+        "php": ">=5.3.0",
+        "illuminate/support": "4.1.*"
+    },
+    "autoload": {
+        "classmap": [
+            "src/migrations"
+        ],
+        "psr-0": {
+            "Ixudra\\Curl\\": "src/"
+        }
+    },
+    "minimum-stability": "stable"
+}

+ 18 - 0
phpunit.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit backupGlobals="false"
+         backupStaticAttributes="false"
+         bootstrap="vendor/autoload.php"
+         colors="true"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         processIsolation="false"
+         stopOnFailure="false"
+         syntaxCheck="false"
+>
+    <testsuites>
+        <testsuite name="Package Test Suite">
+            <directory suffix=".php">./tests/</directory>
+        </testsuite>
+    </testsuites>
+</phpunit>

+ 0 - 0
public/.gitkeep


+ 66 - 0
src/Ixudra/Curl/Curl.php

@@ -0,0 +1,66 @@
+<?php namespace Ixudra\Curl;
+
+
+class Curl {
+
+    protected $_curlObject = null;
+
+    protected $_options = array(
+        'RETURN_TRANSFER'       => true,
+        'FAIL_ON_ERROR'         => true,
+        'FOLLOW_LOCATION'       => false,
+        'CONNECT_TIMEOUT'       => '',
+        'TIMEOUT'               => 30,
+        'USER_AGENT'            => '',
+        'URL'                   => '',
+        'POST'                  => false,
+        'POST_FIELDS'           => array(),
+        'HTTP_HEADER'           => array()
+    );
+
+
+    public function send()
+    {
+        $this->_curlObject = curl_init();
+        $options = $this->_forgeOptions();
+        curl_setopt_array( $this->_curlObject, $options );
+
+        $response = curl_exec($this->_curlObject);
+        curl_close( $this->_curlObject );
+
+        return $response;
+    }
+
+    public function setUrl($url)
+    {
+        $this->_options['URL'] = $url;
+    }
+
+    public function setMethod($method)
+    {
+        $this->_options['POST'] = $method;
+    }
+
+    public function setPostParameters(array $parameters)
+    {
+        $this->_options['POST'] = true;
+        $this->_options['POST_FIELDS'] = $parameters;
+    }
+
+    protected function _forgeOptions()
+    {
+        $results = array();
+        foreach( $this->_options as $key => $value ) {
+            $array_key = constant( 'CURLOPT_' . str_replace('_', '', $key) );
+
+            if( $key == 'POST_FIELDS' && is_array($value) ) {
+                $results[$array_key] = http_build_query($value, NULL, '&');
+            } else {
+                $results[$array_key] = $value;
+            }
+        }
+
+        return $results;
+    }
+
+}

+ 28 - 0
src/Ixudra/Curl/CurlService.php

@@ -0,0 +1,28 @@
+<?php namespace Ixudra\Curl;
+
+
+class CurlService {
+
+    public function get($url)
+    {
+        $curl = new Curl();
+        $curl->setUrl( $url );
+
+        $response = $curl->send();
+
+        return $response;
+    }
+
+    public function post($url, $parameters)
+    {
+        $curl = new Curl();
+        $curl->setUrl( $url );
+        $curl->setMethod( true );
+        $curl->setPostParameters( $parameters );
+
+        $response = $curl->send();
+
+        return $response;
+    }
+
+}

+ 43 - 0
src/Ixudra/Curl/CurlServiceProvider.php

@@ -0,0 +1,43 @@
+<?php namespace Ixudra\Curl;
+
+
+use Illuminate\Support\ServiceProvider;
+
+class CurlServiceProvider extends ServiceProvider {
+
+    /**
+     * @var bool
+     */
+    protected $defer = false;
+
+
+    /**
+     * @return void
+     */
+    public function boot()
+    {
+        $this->package('ixudra/curl');
+    }
+
+    /**
+     * @return void
+     */
+    public function register()
+    {
+        $this->app['Curl'] = $this->app->share(
+            function($app)
+            {
+                return new CurlService();
+            }
+        );
+    }
+
+    /**
+     * @return array
+     */
+    public function provides()
+    {
+        return array('Curl');
+    }
+
+}

+ 16 - 0
src/Ixudra/Curl/Facades/Curl.php

@@ -0,0 +1,16 @@
+<?php namespace Ixudra\Curl\Facades;
+
+
+use Illuminate\Support\Facades\Facade;
+
+class Curl extends Facade {
+
+    /**
+     * @return string
+     */
+    protected static function getFacadeAccessor()
+    {
+        return 'Curl';
+    }
+
+}

+ 0 - 0
src/config/.gitkeep


+ 0 - 0
src/controllers/.gitkeep


+ 0 - 0
src/lang/.gitkeep


+ 0 - 0
src/migrations/.gitkeep


+ 0 - 0
src/views/.gitkeep


+ 0 - 0
tests/.gitkeep