@@ -112,8 +112,9 @@ abstract class AmazonCore{
112112 *
113113 * This constructor is called when initializing all objects in this library.
114114 * The parameters are passed by the child objects' constructors.
115- * @param string $s <p>Name for the store you want to use as seen in the config file.
116- * If this is not set to a valid name, none of these objects will work.</p>
115+ * @param string $s [optional] <p>Name for the store you want to use as seen in the config file.
116+ * If there is only one store defined in the config file, this parameter is not necessary.
117+ * If there is more than one store and this is not set to a valid name, none of these objects will work.</p>
117118 * @param boolean $mock [optional] <p>This is a flag for enabling Mock Mode.
118119 * When this is set to <b>TRUE</b>, the object will fetch responses from
119120 * files you specify instead of sending the requests to Amazon.
@@ -124,7 +125,7 @@ abstract class AmazonCore{
124125 * from the list to use as a response. See <i>setMock</i> for more information.</p>
125126 * @param string $config [optional] <p>An alternate config file to set. Used for testing.</p>
126127 */
127- protected function __construct ($ s , $ mock= false , $ m = null , $ config = null ){
128+ protected function __construct ($ s = null , $ mock = false , $ m = null , $ config = null ){
128129 if (is_null ($ config )){
129130 $ config = __DIR__ .'/../../amazon-config.php ' ;
130131 }
@@ -360,8 +361,9 @@ public function setConfig($path){
360361 include ($ path );
361362 $ this ->config = $ path ;
362363 $ this ->setLogPath ($ logpath );
363- if (isset ($ AMAZON_SERVICE_URL ))
364- $ this ->urlbase = $ AMAZON_SERVICE_URL ;
364+ if (isset ($ AMAZON_SERVICE_URL )) {
365+ $ this ->urlbase = $ AMAZON_SERVICE_URL ;
366+ }
365367 } else {
366368 throw new Exception ("Config file does not exist or cannot be read! ( $ path) " );
367369 }
@@ -392,16 +394,25 @@ public function setLogPath($path){
392394 * for making requests with Amazon. If the store cannot be found in the
393395 * config file, or if any of the key values are missing,
394396 * the incident will be logged.
395- * @param string $s <p>The store name to look for.</p>
397+ * @param string $s [optional] <p>The store name to look for.
398+ * This parameter is not required if there is only one store defined in the config file.</p>
396399 * @throws Exception If the file can't be found.
397400 */
398- public function setStore ($ s ){
401+ public function setStore ($ s= null ){
399402 if (file_exists ($ this ->config )){
400403 include ($ this ->config );
401404 } else {
402405 throw new Exception ("Config file does not exist! " );
403406 }
404407
408+ if (empty ($ store ) || !is_array ($ store )) {
409+ throw new Exception ("No stores defined! " );
410+ }
411+
412+ if (!isset ($ s ) && count ($ store )===1 ) {
413+ $ s =key ($ store );
414+ }
415+
405416 if (array_key_exists ($ s , $ store )){
406417 $ this ->storeName = $ s ;
407418 if (array_key_exists ('merchantId ' , $ store [$ s ])){
@@ -417,6 +428,9 @@ public function setStore($s){
417428 if (!array_key_exists ('secretKey ' , $ store [$ s ])){
418429 $ this ->log ("Secret Key is missing! " ,'Warning ' );
419430 }
431+ if (!empty ($ store [$ s ]['serviceUrl ' ])) {
432+ $ this ->urlbase = $ store [$ s ]['serviceUrl ' ];
433+ }
420434
421435 } else {
422436 $ this ->log ("Store $ s does not exist! " ,'Warning ' );
@@ -499,7 +513,7 @@ protected function log($msg, $level = 'Info'){
499513 file_put_contents ($ this ->logpath , "This is the Amazon log, for Amazon classes to use. \n" );
500514 }
501515 if (file_exists ($ this ->logpath ) && is_writable ($ this ->logpath )){
502- $ str = "[ $ level][ " . date ("Y/m/d h :i:s " , mktime () ) . " $ name@ $ ip $ fileName: $ line $ function] " . $ msg ;
516+ $ str = "[ $ level][ " . date ("Y/m/d H :i:s " ) . " $ name@ $ ip $ fileName: $ line $ function] " . $ msg ;
503517 $ fd = fopen ($ this ->logpath , "a+ " );
504518 fwrite ($ fd ,$ str . "\r\n" );
505519 fclose ($ fd );
0 commit comments