// __PHP object has relevant properties from PHP object // PHP object is later removed from JS context, so it cannot be used in expressions directly __PHP.__getWrapperProp = PHP.__getWrapperProp; __PHP.__contextWrapper = PHP.__contextWrapper; __PHP.__contextProperties = PHP.__contextProperties; __PHP.__getContextPropertyService = PHP.__getContextPropertyService; __PHP.__items = PHP.__items; __PHP.__buildItemCallback = PHP.__buildItemCallback; __PHP.__throwErrors = PHP.__throwErrors; __PHP.__isDevelopment = PHP.__isDevelopment; __PHP.__transformJSError = PHP.__transformJSError; __PHP.__isPreview = PHP.__isPreview; __PHP.__updateReport = PHP.__updateReport; __PHP.__runBuild = PHP.__runBuild; for (const prop in __PHP.__properties) { Object.defineProperty(global, prop, { get() { return __PHP.__getWrapperProp(prop); } }); } for (const prop in __PHP.__methods) { global[prop] = (...arguments) => { return __PHP.__contextWrapper[prop](...arguments); } } for (const prop in __PHP.__contextProperties) { if (prop === 'utils') { __PHP.__utils = __PHP.__contextProperties[prop] !== null ? __PHP.__contextProperties[prop] : (__PHP.__contextProperties[prop] = __PHP.__getContextPropertyService(prop)); // Object.defineProperty(__PHP, '__utils', { get() { return __PHP.__contextProperties[prop] !== null ? __PHP.__contextProperties[prop] : (__PHP.__contextProperties[prop] = __PHP.__getContextPropertyService(prop)); } }); } else { Object.defineProperty(global, prop, { get() { return __PHP.__contextProperties[prop] !== null ? __PHP.__contextProperties[prop] : (__PHP.__contextProperties[prop] = __PHP.__getContextPropertyService(prop)); } }); } } // make __PHP.__utils context methods and properties accessible through utils for (const [propIndex, propObject] of Object.entries(__PHP.__utils.getRawFieldsAndMethods())) { if (propObject.method) { // mediate php utils context methods utils[propObject.name] = function(...arguments) { return __PHP.__utils[propObject.name](...arguments); }; // utils[propObject.name] = __PHP.__utils[propObject.name]; // throws Illegal invocation } else { // mediate php utils context properties in a lazy fashion Object.defineProperty(utils, propObject.name, { get() { return __PHP.__utils.offsetGet(propObject.name); } }); } } __reportCounters = {}; let __report = {"count": 0, "validCount": 0, "validInStoreCount": 0, "errors": {}}; const __updateReport = function () { __report["reportCounters"] = __reportCounters; if (__PHP.__isPreview) { __report["consoleLogs"] = console.__getLogs(); } __PHP.__updateReport(__report); }; const __buildItem = function (__item) { const __hasIdProperty = !__item.done && typeof id !== 'undefined'; const __hasSearchProperty = !__item.done && typeof __search !== 'undefined'; const __hasInStoreProperty = !__item.done && typeof in_store !== 'undefined'; const __hasStockProperty = !__item.done && typeof stock !== 'undefined'; try { if (__PHP.__buildItemCallback !== null) { __PHP.__buildItemCallback(function(){ print(__buildXML() + '\n'); }, __item); } else { print(__buildXML() + '\n'); } __report.validCount++; if (__hasInStoreProperty && in_store > 0) { __report.validInStoreCount++; } else if (__hasStockProperty && stock > 0) { __report.validInStoreCount++; } } catch (error) { if (__PHP.__throwErrors) { if (__PHP.__isDevelopment) { throw error; } else { print(__PHP.__transformJSError(error, error.message, error.stack)); exit(); } } if (Object.keys(__report.errors).length < 10) { __report.errors[__hasIdProperty ? id : (__hasSearchProperty && typeof __search !== 'undefined' && __search.length ? __search : '#'+__report.count)] = __PHP.__transformJSError(error, error.message, error.stack); } print('\n'); } __report.count++; }; const __buildBatch = function (batchSize) { let __current = __PHP.__items.next(); let index = 0; while (!__current.done) { __buildItem(__current) if (batchSize !== null && ++index >= batchSize) { break; } __current = __PHP.__items.next(); } return __current.done; }; if (__PHP.__runBuild) { __buildBatch(null); __updateReport(); }