Exemple #1
0
 /**
  * @param string[] $mainPaths
  * @param string[] $sourcePaths
  * @param bool     $generateSourceMaps
  * @return string
  */
 protected function _browserify(array $mainPaths, array $sourcePaths, $generateSourceMaps)
 {
     if (!count($mainPaths)) {
         return '';
     }
     $involvedFiles = [];
     foreach ($sourcePaths as $sourcePath) {
         $involvedFiles = array_merge($involvedFiles, CM_Util::rglob('*.js', $sourcePath));
     }
     foreach ($mainPaths as $mainPath) {
         $involvedFiles[] = $mainPath;
     }
     $cacheKeyContent = \Functional\reduce_left(array_unique($involvedFiles), function ($path, $index, $collection, $carry) {
         return md5($carry . (new CM_File($path))->read());
     }, '');
     $cacheKeyMainPaths = \Functional\reduce_left($mainPaths, function ($path, $index, $collection, $carry) {
         return md5($carry . $path);
     }, '');
     $cache = CM_Cache_Persistent::getInstance();
     $cacheKey = $cache->key(__METHOD__, $cacheKeyContent, $cacheKeyMainPaths, $generateSourceMaps);
     return $cache->get($cacheKey, function () use($mainPaths, $sourcePaths, $generateSourceMaps) {
         $args = $mainPaths;
         if ($generateSourceMaps) {
             $args[] = '--debug';
         }
         return CM_Util::exec('NODE_PATH="' . implode(':', $sourcePaths) . '" browserify', $args);
     });
 }
Exemple #2
0
 public function formatContext(CM_Log_Context $context)
 {
     $result = [];
     if ($computerInfo = $context->getComputerInfo()) {
         $result['computerInfo'] = ['fqdn' => $computerInfo->getFullyQualifiedDomainName(), 'phpVersion' => $computerInfo->getPhpVersion()];
     }
     $request = $context->getHttpRequest();
     if (null !== $request) {
         $serverArray = $request->getServer();
         $formattedRequest = ['uri' => $request->getUri(), 'method' => $request->getMethodName()];
         $query = $request->findQuery();
         unset($query['viewInfoList']);
         $formattedRequest['query'] = CM_Util::jsonEncode($query, true);
         if (array_key_exists('http_referer', $serverArray)) {
             $formattedRequest['referer'] = (string) $serverArray['http_referer'];
         }
         if (array_key_exists('http_user_agent', $serverArray)) {
             $formattedRequest['useragent'] = (string) $serverArray['http_user_agent'];
         }
         if ($ip = $request->getIp()) {
             $formattedRequest['ip'] = (string) $ip;
         }
         if ($request->hasHeader('host')) {
             $formattedRequest['hostname'] = $request->getHost();
         }
         $result['httpRequest'] = $formattedRequest;
     }
     $result = array_merge($result, $this->formatAppContext($context));
     if ($exception = $context->getException()) {
         $serializableException = new CM_ExceptionHandling_SerializableException($exception);
         $stack = $serializableException->getTrace();
         if (!empty($stack)) {
             $stackAsString = trim(Functional\reduce_left(array_reverse($stack), function ($value, $index, $collection, $reduction) {
                 return $reduction . '#' . $index . ' ' . $value['file'] . '(' . $value['line'] . '): ' . $value['code'] . PHP_EOL;
             }, ''));
         } else {
             $stackAsString = $serializableException->getTraceAsString();
         }
         $result['exception'] = ['type' => $serializableException->getClass(), 'message' => $serializableException->getMessage(), 'stack' => $stackAsString, 'metaInfo' => $serializableException->getMeta()];
     }
     return $result;
 }
function smarty_function_resourceJs(array $params, Smarty_Internal_Template $template)
{
    /** @var $render CM_Frontend_Render */
    $render = $template->smarty->getTemplateVars('render');
    $type = (string) $params['type'];
    $file = (string) $params['file'];
    $debug = CM_Bootloader::getInstance()->isDebug();
    if (!in_array($type, array('vendor', 'library'))) {
        throw new CM_Exception_Invalid('Invalid type provided', null, ['type' => $type]);
    }
    $scripts = [];
    if ($debug && 'vendor' == $type) {
        $scripts[] = $render->getUrlResource($type . '-js', 'dist-' . $file);
        $scripts[] = $render->getUrlResource($type . '-js', 'source-' . $file);
    } else {
        $scripts[] = $render->getUrlResource($type . '-js', $file);
    }
    return \Functional\reduce_left($scripts, function ($url, $index, $collection, $reduction) {
        return $reduction . PHP_EOL . '<script type="text/javascript" src="' . $url . '" crossorigin="anonymous"></script>';
    }, '');
}
Exemple #4
0
 /**
  * @return DateTimeZone|null
  */
 public function getTimeZone()
 {
     $pointCurrent = $this->getGeoPoint();
     if (null === $pointCurrent) {
         return null;
     }
     $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) {
         return null === IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName));
     });
     $distanceList = Functional\map($timezoneNameList, function ($timezoneName) use($pointCurrent) {
         $timezoneLocation = (new DateTimeZone($timezoneName))->getLocation();
         $pointTimeZone = new CM_Geo_Point($timezoneLocation['latitude'], $timezoneLocation['longitude']);
         return ['timezoneName' => $timezoneName, 'distance' => $pointCurrent->calculateDistanceTo($pointTimeZone)];
     });
     $closestDistance = Functional\reduce_left($distanceList, function (array $current, $index, $collection, array $minimal) {
         return $current['distance'] < $minimal['distance'] ? $current : $minimal;
     }, $distanceList[0]);
     return new DateTimeZone($closestDistance['timezoneName']);
 }