Overview

Packages

  • IllApps
    • Shipsync
  • PHP

Classes

  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Abstract
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Form
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Items
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_Packages_View_Package
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_Shipment_View
  • IllApps_Shipsync_Block_Adminhtml_Sales_Order_View
  • IllApps_Shipsync_Block_Adminhtml_Shipsync
  • IllApps_Shipsync_Block_Adminhtml_Shipsync_Option
  • IllApps_Shipsync_Helper_Data
  • IllApps_Shipsync_IndexController
  • IllApps_Shipsync_Model_Mysql4_Setup
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package
  • IllApps_Shipsync_Model_Mysql4_Shipment_Package_Collection
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package
  • IllApps_Shipsync_Model_Sales_Order_Shipment_Package_Item
  • IllApps_Shipsync_Model_Sales_Quote_Address
  • IllApps_Shipsync_Model_Shipment_Abstract
  • IllApps_Shipsync_Model_Shipment_Package
  • IllApps_Shipsync_Model_Shipment_Request
  • IllApps_Shipsync_Model_Shipment_Response
  • IllApps_Shipsync_Model_Shipment_Result
  • IllApps_Shipsync_Model_Shipping_Carrier_Abstract
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Address
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Package
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Ship
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_B13afilingoption
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Freemethod
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Image
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Orientation
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Label_Stock
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Method
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Packaging
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Rate
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Ratediscount
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Residencedelivery
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Signature
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Endorsement
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Smartpost_Indicia
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Source_Unitofmeasure
  • IllApps_Shipsync_Model_Shipping_Carrier_Fedex_Track
  • IllApps_Shipsync_Model_Shipping_Package
  • IllApps_Shipsync_Model_Shipping_Package_Item
  • IllApps_Shipsync_Model_Shipping_Package_Origins
  • IllApps_Shipsync_Model_Shipping_Package_Sort
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * ShipSync
  5:  *
  6:  * @category   IllApps
  7:  * @package    IllApps_Shipsync
  8:  * @copyright  Copyright (c) 2014 EcoMATICS, Inc. DBA IllApps (http://www.illapps.com)
  9:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 10:  */
 11: 
 12: /**
 13:  * IllApps_Shipsync_Helper_Data
 14:  */
 15: class IllApps_Shipsync_Helper_Data extends Mage_Core_Helper_Abstract
 16: {
 17: 
 18:     /**
 19:      * @var string
 20:      */
 21:     const VERSION = '3.0.1';
 22: 
 23:     /**
 24:      * @var string
 25:      */
 26:     const HEADER_NAME = 'X-ChromePhp-Data';
 27: 
 28:     /**
 29:      * @var string
 30:      */
 31:     const BACKTRACE_LEVEL = 'backtrace_level';
 32: 
 33:     /**
 34:      * @var string
 35:      */
 36:     const LOG = 'log';
 37: 
 38:     /**
 39:      * @var string
 40:      */
 41:     const WARN = 'warn';
 42: 
 43:     /**
 44:      * @var string
 45:      */
 46:     const ERROR = 'error';
 47: 
 48:     /**
 49:      * @var string
 50:      */
 51:     const GROUP = 'group';
 52: 
 53:     /**
 54:      * @var string
 55:      */
 56:     const INFO = 'info';
 57: 
 58:     /**
 59:      * @var string
 60:      */
 61:     const GROUP_END = 'groupEnd';
 62: 
 63:     /**
 64:      * @var string
 65:      */
 66:     const GROUP_COLLAPSED = 'groupCollapsed';
 67: 
 68:     /**
 69:      * @var string
 70:      */
 71:     protected $_php_version;
 72: 
 73:     /**
 74:      * @var int
 75:      */
 76:     protected $_timestamp;
 77: 
 78:     /**
 79:      * @var array
 80:      */
 81:     protected $_json = array(
 82:         'version' => self::VERSION,
 83:         'columns' => array('label', 'log', 'backtrace', 'type'),
 84:         'rows' => array()
 85:     );
 86: 
 87:     /**
 88:      * @var array
 89:      */
 90:     protected $_backtraces = array();
 91: 
 92:     /**
 93:      * @var bool
 94:      */
 95:     protected $_error_triggered = false;
 96: 
 97:     /**
 98:      * @var array
 99:      */
100:     protected $_settings = array(
101:         self::BACKTRACE_LEVEL => 1
102:     );
103: 
104:     /**
105:      * @var ChromePhp
106:      */
107:     protected static $_instance;
108: 
109:     /**
110:      * Prevent recursion when working with objects referring to each other
111:      *
112:      * @var array
113:      */
114:     protected $_processed = array();
115: 
116:     /**
117:      * constructor
118:      */
119:     public function __construct()
120:     {
121:         $this->_php_version = phpversion();
122:         $this->_timestamp = $this->_php_version >= 5.1 ? $_SERVER['REQUEST_TIME'] : time();
123:         $this->_json['request_uri'] = $_SERVER['REQUEST_URI'];
124:     }
125: 
126:     /**
127:      * gets instance of this class
128:      *
129:      * @return ChromePhp
130:      */
131:     public static function getInstance()
132:     {
133:         if (self::$_instance === null) {
134:             self::$_instance = new self();
135:         }
136:         return self::$_instance;
137:     }
138: 
139:     /**
140:      * logs a variable to the console
141:      *
142:      * @param string label
143:      * @param mixed value
144:      * @param string severity ChromePhp::LOG || ChromePhp::WARN || ChromePhp::ERROR
145:      * @return void
146:      */
147:     public static function log()
148:     {
149:         $args = func_get_args();
150:         $severity = count($args) == 3 ? array_pop($args) : '';
151: 
152:         // save precious bytes
153:         if ($severity == self::LOG) {
154:             $severity = '';
155:         }
156: 
157:         return self::_log($args + array('type' => $severity));
158:     }
159: 
160:     /**
161:      * logs a warning to the console
162:      *
163:      * @param string label
164:      * @param mixed value
165:      * @return void
166:      */
167:     public static function warn()
168:     {
169:         return self::_log(func_get_args() + array('type' => self::WARN));
170:     }
171: 
172:     /**
173:      * logs an error to the console
174:      *
175:      * @param string label
176:      * @param mixed value
177:      * @return void
178:      */
179:     public static function error()
180:     {
181:         return self::_log(func_get_args() + array('type' => self::ERROR));
182:     }
183: 
184:     /**
185:      * sends a group log
186:      *
187:      * @param string value
188:      */
189:     public static function group()
190:     {
191:         return self::_log(func_get_args() + array('type' => self::GROUP));
192:     }
193: 
194:     /**
195:      * sends an info log
196:      *
197:      * @param string value
198:      */
199:     public static function info()
200:     {
201:         return self::_log(func_get_args() + array('type' => self::INFO));
202:     }
203: 
204:     /**
205:      * sends a collapsed group log
206:      *
207:      * @param string value
208:      */
209:     public static function groupCollapsed()
210:     {
211:         return self::_log(func_get_args() + array('type' => self::GROUP_COLLAPSED));
212:     }
213: 
214:     /**
215:      * ends a group log
216:      *
217:      * @param string value
218:      */
219:     public static function groupEnd()
220:     {
221:         return self::_log(func_get_args() + array('type' => self::GROUP_END));
222:     }
223: 
224:     /**
225:      * internal logging call
226:      *
227:      * @param string $type
228:      * @return void
229:      */
230:     protected static function _log(array $args)
231:     {
232:         $type = $args['type'];
233:         unset($args['type']);
234: 
235:         // nothing passed in, don't do anything
236:         if (count($args) == 0 && $type != self::GROUP_END) {
237:             return;
238:         }
239: 
240:         // default to single
241:         $label = null;
242:         $value = isset($args[0]) ? $args[0] : '';
243: 
244:         $logger = self::getInstance();
245: 
246:         // if there are two values passed in then the first one is the label
247:         if (count($args) == 2) {
248:             $label = $args[0];
249:             $value = $args[1];
250:         }
251: 
252:         $logger->_processed = array();
253:         $value = $logger->_convert($value);
254: 
255:         $backtrace = debug_backtrace(false);
256:         $level = $logger->getSetting(self::BACKTRACE_LEVEL);
257: 
258:         $backtrace_message = 'unknown';
259:         if (isset($backtrace[$level]['file']) && isset($backtrace[$level]['line'])) {
260:             $backtrace_message = $backtrace[$level]['file'] . ' : ' . $backtrace[$level]['line'];
261:         }
262: 
263:         $logger->_addRow($label, $value, $backtrace_message, $type);
264:     }
265: 
266:     /**
267:      * converts an object to a better format for logging
268:      *
269:      * @param Object
270:      * @return array
271:      */
272:     protected function _convert($object)
273:     {
274:         // if this isn't an object then just return it
275:         if (!is_object($object)) {
276:             return $object;
277:         }
278: 
279:         //Mark this object as processed so we don't convert it twice and it
280:         //Also avoid recursion when objects refer to each other
281:         $this->_processed[] = $object;
282: 
283:         $object_as_array = array();
284: 
285:         // first add the class name
286:         $object_as_array['___class_name'] = get_class($object);
287: 
288:         // loop through object vars
289:         $object_vars = get_object_vars($object);
290:         foreach ($object_vars as $key => $value) {
291: 
292:             // same instance as parent object
293:             if ($value === $object || in_array($value, $this->_processed, true)) {
294:                 $value = 'recursion - parent object [' . get_class($value) . ']';
295:             }
296:             $object_as_array[$key] = $this->_convert($value);
297:         }
298: 
299:         $reflection = new ReflectionClass($object);
300: 
301:         // loop through the properties and add those
302:         foreach ($reflection->getProperties() as $property) {
303: 
304:             // if one of these properties was already added above then ignore it
305:             if (array_key_exists($property->getName(), $object_vars)) {
306:                 continue;
307:             }
308:             $type = $this->_getPropertyKey($property);
309: 
310:             if ($this->_php_version >= 5.3) {
311:                 $property->setAccessible(true);
312:             }
313: 
314:             try {
315:                 $value = $property->getValue($object);
316:             } catch (ReflectionException $e) {
317:                 $value = 'only PHP 5.3 can access private/protected properties';
318:             }
319: 
320:             // same instance as parent object
321:             if ($value === $object || in_array($value, $this->_processed, true)) {
322:                 $value = 'recursion - parent object [' . get_class($value) . ']';
323:             }
324: 
325:             $object_as_array[$type] = $this->_convert($value);
326:         }
327:         return $object_as_array;
328:     }
329: 
330:     /**
331:      * takes a reflection property and returns a nicely formatted key of the property name
332:      *
333:      * @param ReflectionProperty
334:      * @return string
335:      */
336:     protected function _getPropertyKey(ReflectionProperty $property)
337:     {
338:         $static = $property->isStatic() ? ' static' : '';
339:         if ($property->isPublic()) {
340:             return 'public' . $static . ' ' . $property->getName();
341:         }
342: 
343:         if ($property->isProtected()) {
344:             return 'protected' . $static . ' ' . $property->getName();
345:         }
346: 
347:         if ($property->isPrivate()) {
348:             return 'private' . $static . ' ' . $property->getName();
349:         }
350:     }
351: 
352:     /**
353:      * adds a value to the data array
354:      *
355:      * @var mixed
356:      * @return void
357:      */
358:     protected function _addRow($label, $log, $backtrace, $type)
359:     {
360:         // if this is logged on the same line for example in a loop, set it to null to save space
361:         if (in_array($backtrace, $this->_backtraces)) {
362:             $backtrace = null;
363:         }
364: 
365:         if ($backtrace !== null) {
366:             $this->_backtraces[] = $backtrace;
367:         }
368: 
369:         $row = array($label, $log, $backtrace, $type);
370: 
371:         $this->_json['rows'][] = $row;
372:         $this->_writeHeader($this->_json);
373:     }
374: 
375:     protected function _writeHeader($data)
376:     {
377:         header(self::HEADER_NAME . ': ' . $this->_encode($data));
378:     }
379: 
380:     /**
381:      * encodes the data to be sent along with the request
382:      *
383:      * @param array $data
384:      * @return string
385:      */
386:     protected function _encode($data)
387:     {
388:         return base64_encode(utf8_encode(json_encode($data)));
389:     }
390: 
391:     /**
392:      * adds a setting
393:      *
394:      * @param string key
395:      * @param mixed value
396:      * @return void
397:      */
398:     public function addSetting($key, $value)
399:     {
400:         $this->_settings[$key] = $value;
401:     }
402: 
403:     /**
404:      * add ability to set multiple settings in one call
405:      *
406:      * @param array $settings
407:      * @return void
408:      */
409:     public function addSettings(array $settings)
410:     {
411:         foreach ($settings as $key => $value) {
412:             $this->addSetting($key, $value);
413:         }
414:     }
415: 
416:     /**
417:      * gets a setting
418:      *
419:      * @param string key
420:      * @return mixed
421:      */
422:     public function getSetting($key)
423:     {
424:         if (!isset($this->_settings[$key])) {
425:             return null;
426:         }
427:         return $this->_settings[$key];
428:     }
429:     
430:     public static function mageLog($var, $name)
431:     {
432:         if (Mage::getStoreConfig('carriers/fedex/mage_log')) {
433:             Mage::log($var, null, 'shipsync_' . $name . '.log');
434:         }
435:     }
436: }
437: 
shipsync-community API documentation generated by ApiGen 2.8.0