Renaming Namespaces and Organizing Classes

- Updated OpenId classes to be in API namespace
- Updated PP Naming Convention to PayPal Naming Convention
- FormatConverter Class got its own namespace
- Handlers are grouped in Handler namespace
- Samples and Tests Updated Accordingly
This commit is contained in:
japatel
2014-12-17 17:15:01 -06:00
parent 4cb951f8b2
commit 9c0827643b
246 changed files with 1067 additions and 1057 deletions

View File

@@ -3,12 +3,12 @@
namespace PayPal\Common;
/**
* Class PPArrayUtil
* Class ArrayUtil
* Util Class for Arrays
*
* @package PayPal\Common
*/
class PPArrayUtil
class ArrayUtil
{
/**
@@ -25,4 +25,4 @@ class PPArrayUtil
}
return true;
}
}
}

View File

@@ -1,74 +0,0 @@
<?php
namespace PayPal\Common;
class FormatConverter {
/**
* Format the data based on the input formatter value
*
* @param $value
* @param $formatter
* @return string
*/
public static function format($value, $formatter)
{
return sprintf($formatter, $value);
}
/**
* Format the input data to two decimal places
*
* @deprecated Use formatToNumber instead
* @param $value
* @return string
*/
public static function formatToTwoDecimalPlaces($value)
{
return self::formatToNumber($value);
}
/**
* Format the input data with decimal places
*
* Defaults to 2 decimal places
*
* @param $value
* @param int $decimals
* @return null|string
*/
public static function formatToNumber($value, $decimals = 2)
{
if (trim($value) != null) {
return number_format($value, $decimals, '.', '');
}
return null;
}
/**
* Helper method to format price values with associated currency information.
*
* It covers the cases where certain currencies does not accept decimal values. We will be adding
* any specific currency level rules as required here.
*
* @param $value
* @param null $currency
* @return null|string
*/
public static function formatToPrice($value, $currency = null)
{
$decimals = 2;
$currencyDecimals = array('JPY' => 0, 'TWD' => 0);
if ($currency && array_key_exists($currency, $currencyDecimals)) {
if (strpos($value, ".") !== false && (floor($value) != $value)) {
//throw exception if it has decimal values for JPY and TWD which does not ends with .00
throw new \InvalidArgumentException("value cannot have decimals for $currency currency");
}
$decimals = $currencyDecimals[$currency];
} else if (strpos($value, ".") === false) {
// Check if value has decimal values. If not no need to assign 2 decimals with .00 at the end
$decimals = 0;
}
return self::formatToNumber($value, $decimals);
}
}

View File

@@ -9,7 +9,7 @@ use PayPal\Validation\ModelAccessorValidator;
* Stores all member data in a Hashmap that enables easy
* JSON encoding/decoding
*/
class PPModel
class PayPalModel
{
private $_propMap = array();
@@ -52,7 +52,7 @@ class PPModel
//Convert to Array if Json Data Sent
$data = json_decode($data, true);
}
if (!PPArrayUtil::isAssocArray($data)) {
if (!ArrayUtil::isAssocArray($data)) {
$list = array();
//This means, root element is array
foreach ($data as $k => $v) {
@@ -136,7 +136,7 @@ class PPModel
{
$ret = array();
foreach ($param as $k => $v) {
if ($v instanceof PPModel) {
if ($v instanceof PayPalModel) {
$ret[$k] = $v->toArray();
} else if (is_array($v)) {
$ret[$k] = $this->_convertToArray($v);
@@ -158,8 +158,8 @@ class PPModel
if (!empty($arr)) {
foreach ($arr as $k => $v) {
if (is_array($v)) {
$clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k);
if (PPArrayUtil::isAssocArray($v)) {
$clazz = ReflectionUtil::getPropertyClass(get_class($this), $k);
if (ArrayUtil::isAssocArray($v)) {
/** @var self $o */
$o = new $clazz();
$o->fromArray($v);

View File

@@ -1,19 +1,19 @@
<?php
namespace PayPal\Common;
use PayPal\Handler\IPPHandler;
use PayPal\Handler\IPayPalHandler;
use PayPal\Rest\ApiContext;
use PayPal\Rest\IResource;
use PayPal\Transport\PPRestCall;
use PayPal\Transport\PayPalRestCall;
/**
* Class ResourceModel
* An Executable PPModel Class
* Class PayPalResourceModel
* An Executable PayPalModel Class
*
* @package PayPal\Common
*/
class ResourceModel extends PPModel implements IResource
class PayPalResourceModel extends PayPalModel implements IResource
{
/**
@@ -43,15 +43,15 @@ class ResourceModel extends PPModel implements IResource
* @param string $payLoad
* @param array $headers
* @param ApiContext $apiContext
* @param PPRestCall $restCall
* @param PayPalRestCall $restCall
* @param array $handlers
* @return string json response of the object
*/
protected static function executeCall($url, $method, $payLoad, $headers = array(), $apiContext = null, $restCall = null, $handlers = array('PayPal\Rest\RestHandler'))
protected static function executeCall($url, $method, $payLoad, $headers = array(), $apiContext = null, $restCall = null, $handlers = array('PayPal\Handler\RestHandler'))
{
//Initialize the context and rest call object if not provided explicitly
$apiContext = $apiContext ? $apiContext : new ApiContext(self::$credential);
$restCall = $restCall ? $restCall : new PPRestCall($apiContext);
$restCall = $restCall ? $restCall : new PayPalRestCall($apiContext);
//Make the execution call
$json = $restCall->execute($handlers, $url, $method, $payLoad, $headers);

View File

@@ -3,12 +3,12 @@
namespace PayPal\Common;
/**
* Class PPUserAgent
* PPUserAgent generates User Agent for curl requests
* Class PayPalUserAgent
* PayPalUserAgent generates User Agent for curl requests
*
* @package PayPal\Common
*/
class PPUserAgent
class PayPalUserAgent
{
/**
@@ -56,4 +56,4 @@ class PPUserAgent
return PHP_INT_SIZE;
}
}
}
}

View File

@@ -3,11 +3,11 @@
namespace PayPal\Common;
/**
* Class PPReflectionUtil
* Class ReflectionUtil
*
* @package PayPal\Common
*/
class PPReflectionUtil
class ReflectionUtil
{
/**
@@ -34,9 +34,9 @@ class PPReflectionUtil
*/
public static function getPropertyClass($class, $propertyName)
{
if ($class == get_class(new PPModel())) {
// Make it generic if PPModel is used for generating this
return get_class(new PPModel());
if ($class == get_class(new PayPalModel())) {
// Make it generic if PayPalModel is used for generating this
return get_class(new PayPalModel());
}
if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {