3namespace Bitrix\MobileApp\Janative\Entity;
5use Bitrix\Main\Application;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\EventManager;
8use Bitrix\Main\IO\Directory;
9use Bitrix\Main\IO\File;
10use Bitrix\Main\IO\FileNotFoundException;
11use Bitrix\Main\IO\Path;
12use Bitrix\Main\Loader;
13use Bitrix\Main\LoaderException;
14use Bitrix\Main\ModuleManager;
15use Bitrix\Main\SystemException;
16use Bitrix\MobileApp\Janative\Manager;
17use Bitrix\MobileApp\Janative\Utils;
18use Bitrix\MobileApp\Mobile;
28 private $version =
null;
30 private ?
Config $bundleConfig =
null;
52 if (mb_substr($this->
path, -1) !=
'/')
58 $this->baseFileName =
'component';
59 $path = $directory->getPath() .
'/' . $this->baseFileName .
'.js';
61 $this->name = $directory->getName();
64 if (!$directory->isExists() || !$file->isExists())
66 throw new Exception(
"Component '{$this->name}' doesn't exists ($path) ");
95 public function execute(
bool $resultOnly =
false)
97 header(
'Content-Type: text/javascript;charset=UTF-8');
98 header(
'BX-Component-Version: ' . $this->
getVersion());
99 header(
'BX-Component: true');
112 $componentFile =
new File($this->
path .
'/component.php');
113 if ($componentFile->isExists())
115 return include($componentFile->getPath());
131 private function getBundleConfig():
Config
133 if ($this->bundleConfig ===
null)
135 $this->bundleConfig =
new Config(
"{$this->path}/dist/deps.bundle.php");
138 return $this->bundleConfig;
143 return $this->getBundleConfig()->exists();
146 private function getBundleDynamicData():
array
148 return $this->getBundleConfig()->dynamicData;
155 $extensionContent =
"";
156 $availableComponents =
"";
158 foreach ($this->getBundleDynamicData() as $ext)
161 $extensionContent .= $extension->getResultExpression();
164 $componentFilePath =
"{$this->path}/dist/{$this->baseFileName}.bundle.js";
168 $componentFilePath =
"{$this->path}/{$this->baseFileName}.js";
174 $events =
$eventManager->findEventHandlers(
"mobileapp",
"onBeforeComponentContentGet");
176 $additionalContent =
"";
179 foreach ($events as
$event)
182 if (is_string($jsCode))
184 $additionalContent .= $jsCode;
200 $file =
new File($componentFilePath);
201 if ($file->isExists())
203 $componentCode = $file->getContents();
219 if ($isExtranetModuleInstalled)
221 $extranetSiteId = CExtranet::getExtranetSiteId();
222 if (!$extranetSiteId)
224 $isExtranetModuleInstalled =
false;
227 $isExtranetUser = $isExtranetModuleInstalled && !CExtranet::IsIntranetUser();
239 ($extranetSiteFields =
$res->fetch())
240 && ($extranetSiteFields[
'ACTIVE'] !=
'N')
243 $siteDir = $extranetSiteFields[
'DIR'];
247 $installedModules = array_reduce(
249 static function ($modulesCollection, $module) {
250 $modulesCollection[$module[
'ID']] =
true;
252 return $modulesCollection;
257 $isAdmin =
$USER->isAdmin();
260 $isAdmin = \CBitrix24::IsPortalAdmin(
$userId);
264 'isAdmin' => $isAdmin,
265 'languageId' => LANGUAGE_ID,
266 'siteDir' => $siteDir,
268 'extranet' => $isExtranetUser,
269 'isCollaber' => $this->isUserCollaber(),
270 'installedModules' => $installedModules,
273 $export = $file->getContents();
274 $inlineContent = <<<JS
280 this.component = $object;
286 return $inlineContent;
289 private function isUserCollaber(): bool
299 $container = class_exists(\
Bitrix\Extranet\
Service\ServiceContainer::class)
300 ? \Bitrix\Extranet\Service\ServiceContainer::getInstance()
303 return $container?->getCollaberService()?->isCollaberById(
$userId) ??
false;
310 if ($relativeComponents !==
null)
312 $relativeComponentsScope = [];
313 foreach ($relativeComponents as $scope)
315 if (isset($componentScope[$scope]))
317 $relativeComponentsScope[$scope] = $componentScope[$scope];
321 $componentScope = $relativeComponentsScope;
324 return array_map(
function ($component) {
325 return $component->getInfo();
342 foreach ($deps as $ext)
345 $value[] = $extension->getModificationMarker();
357 $bundleVersion =
new File(
"{$this->path}/dist/version.bundle.php");
358 if ($bundleVersion->isExists())
360 $versionDesc = include($bundleVersion->getPath());
361 $this->
version = $versionDesc[
'version'];
366 $versionFile =
new File(
"{$this->path}/version.php");
367 if ($versionFile->isExists())
369 $versionDesc = include($versionFile->getPath());
370 $this->
version = $versionDesc[
'version'];
371 $this->
version .=
'.' . self::VERSION;
378 return $this->version;
383 $name = ($this->
namespace !== "bitrix
" ? $this->namespace . ":" : "") . $this->name;
384 $name = urlencode($name);
391 $langPhrases = parent::getLangMessages();
393 foreach ($extensions as $extension)
398 $extensionPhrases =
$instance->getLangMessages();
399 $langPhrases = array_merge($langPhrases, $extensionPhrases);
414 return (
new Config(
"{$this->path}/dist/deps.bundle.php"))->extensions;
417 return parent::getDependencies();
422 $componentDependencies = parent::getComponentDependencies();
423 if (is_array($componentDependencies))
432 $componentDependencies = array_merge($componentDependencies, $list);
436 return array_unique($componentDependencies);
450 array_walk($rootDeps,
function ($ext) use (&$deps) {
452 $deps = array_merge($deps, $list);
455 return array_unique($deps);
460 $content =
"\n//extension '{$this->name}'\n";
462 foreach ($deps as $ext)
467 $content .=
"\n" . $extension->getContent($excludeResult);
471 echo
"Janative: error while initialization of '{$ext}' extension\n\n";
475 $loadedExtensions =
"this.loadedExtensions = " .
Utils::jsonEncode(array_values($deps),
true) .
";\n";
477 return $loadedExtensions .
$content;
485 private function isHotreloadEnabled(): bool
487 return (defined(
'JN_HOTRELOAD_ENABLED') && defined(
'JN_HOTRELOAD_HOST'));
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static includeModule($moduleName)
static getInstalledModules()
getLangDefinitionExpression()
setVersion(string $version="1")
onBeforeModificationMarkerSave(array &$value)
getExtensionsContent($excludeResult=false)
static array $dependencies
execute(bool $resultOnly=false)
getComponentDependencies()
static array $modificationDates
__construct($path=null, $namespace="bitrix")
static createInstanceByName($name, string $namespace='bitrix')
static getInstance($identifier)
static getAvailableComponents()
static getComponentByName($name)
static extractEntityDescription($entityIdentifier, string $defaultNamespace="bitrix")
static jsonEncode($string, $options=JSON_HEX_TAG|JSON_HEX_AMP|JSON_PRETTY_PRINT|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_UNESCAPED_UNICODE)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
const SITE_DIR(!defined('LANG'))
if(!defined('SITE_ID')) $lang
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
ExecuteModuleEventEx($arEvent, $arParams=[])