Skip to content

Commit 96cad8c

Browse files
committed
Alpha release - trying to get the composer structure right.
1 parent 1d75fdd commit 96cad8c

File tree

11 files changed

+606
-0
lines changed

11 files changed

+606
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.phar

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "mycloudth/rest-api-sdk-php",
3+
"description": "MyCloud's PHP SDK for REST APIs",
4+
"keywords": ["mycloud", "fulfillment", "rest", "sdk"],
5+
"type": "library",
6+
"license": "MyCloud Fulfillment Group API License v1",
7+
"homepage": "http://mycloudth.github.io/MyCloud-SDK-PHP/",
8+
"authors": [
9+
{
10+
"name": "Tim Endres",
11+
"email": "tim@bkbasic.com"
12+
}
13+
],
14+
"require": {
15+
"php": ">=5.6.0",
16+
"ext-curl": "*",
17+
"ext-json": "*",
18+
"psr/log": "1.0.0"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"MyCloud\\": "mycloudth/rest-api-sdk-php/lib/MyCloud"
23+
}
24+
}
25+
}

composer.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$vendorPath = dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'vendor';
4+
$composerAutoload = $vendorPath . DIRECTORY_SEPARATOR . 'autoload.php';
5+
6+
$reason = '';
7+
$loadable = TRUE;
8+
if ( ! file_exists($vendorPath) ) {
9+
$loadable = FALSE;
10+
$reason = "The 'vendor' folder is missing. (expected at '" . $vendorPath . "')";
11+
}
12+
if ( ! file_exists($composerAutoload) ) {
13+
$loadable = FALSE;
14+
$reason = "The 'autoload.php' file is missing. (expected at '" . $composerAutoload . "')";
15+
}
16+
17+
if ( $loadable ) {
18+
require $composerAutoload;
19+
} else {
20+
print "Could not bootstrap the example program:" . PHP_EOL;
21+
print " " . $reason . PHP_EOL;
22+
print "Check that you installed with composer, or copied the distribution correctly." . PHP_EOL;
23+
exit(1);
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
require 'bootstrap.php';
4+
5+
use \MyCloud\Api\Model\Order;
6+
7+
$order = new Order();
8+
print var_export( $order, true ) . PHP_EOL;
9+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?php
2+
3+
namespace MyCloud\Api\Core;
4+
5+
/**
6+
* Class MyCloudConfigManager
7+
*
8+
* Manages the configuration of the API.
9+
*
10+
* @package MyCloud\Api\Core
11+
*/
12+
class MyCloudConfigManager
13+
{
14+
15+
/**
16+
* Configuration Options
17+
*
18+
* @var array
19+
*/
20+
private $configs = array( );
21+
22+
/**
23+
* Singleton Object
24+
*
25+
* @var $this
26+
*/
27+
private static $instance;
28+
29+
/**
30+
* Private Constructor
31+
*/
32+
private function __construct()
33+
{
34+
if ( defined('MCAPI_CONFIG_PATH') ) {
35+
$configFile = constant('MCAPI_CONFIG_PATH') . '/sdk_config.ini';
36+
} else {
37+
$configFile = implode(
38+
DIRECTORY_SEPARATOR,
39+
array( dirname(__FILE__), "..", "config", "sdk_config.ini" )
40+
);
41+
}
42+
43+
if ( file_exists($configFile) ) {
44+
$this->addConfigFromIni( $configFile );
45+
}
46+
}
47+
48+
/**
49+
* Returns the singleton object
50+
*
51+
* @return $this
52+
*/
53+
public static function getInstance()
54+
{
55+
if ( ! isset(self::$instance) ) {
56+
self::$instance = new self();
57+
}
58+
return self::$instance;
59+
}
60+
61+
/**
62+
* Add Configuration from configuration.ini files
63+
*
64+
* @param string $fileName
65+
* @return $this
66+
*/
67+
public function addConfigFromIni( $fileName )
68+
{
69+
if ( $configs = parse_ini_file($fileName) ) {
70+
$this->addConfigs( $configs );
71+
}
72+
return $this;
73+
}
74+
75+
/**
76+
* If a configuration exists in both arrays,
77+
* then the element from the first array will be used and
78+
* the matching key's element from the second array will be ignored.
79+
*
80+
* @param array $configs
81+
* @return $this
82+
*/
83+
public function addConfigs( $configs = array() )
84+
{
85+
$this->configs = $configs + $this->configs;
86+
return $this;
87+
}
88+
89+
/**
90+
* Simple getter for configuration params
91+
* Returns array of values for matched key,
92+
* or an empty array.
93+
*
94+
* @param string $key
95+
* @return array
96+
*/
97+
public function get( $key )
98+
{
99+
if ( array_key_exists($searchKey, $this->configs) ) {
100+
return $this->configs[$searchKey];
101+
} else {
102+
return array();
103+
}
104+
}
105+
106+
/**
107+
* returns the config file hashmap
108+
*/
109+
public function getConfigHashmap()
110+
{
111+
return $this->configs;
112+
}
113+
114+
/**
115+
* Disabling __clone call
116+
*/
117+
public function __clone()
118+
{
119+
trigger_error( 'Clone is not allowed.', E_USER_ERROR );
120+
}
121+
}

0 commit comments

Comments
 (0)