code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public static function get($pkgIsInstalled = 1) { $pkgIsInstalled = $pkgIsInstalled ? 1 : 0; $pkgList = CacheLocal::getEntry('pkgList', $pkgIsInstalled); if ($pkgList) { return $pkgList; } $em = app(EntityManagerInterface::class); $r = $em->getRepository(PackageEntity::class); $packages = $r->findBy(['pkgIsInstalled' => $pkgIsInstalled], ['pkgID' => 'asc']); $list = new static(); foreach($packages as $pkg) { $list->add($pkg); } CacheLocal::set('pkgList', $pkgIsInstalled, $list); return $list; }
@deprecated @param bool|int $pkgIsInstalled @return static
get
php
concretecms/concretecms
concrete/src/Package/PackageList.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageList.php
MIT
public function __construct(Localization $localization, Application $application, EntityManagerInterface $entityManager) { $this->localization = $localization; $this->application = $application; $this->entityManager = $entityManager; }
Initialize the instance. @param Localization $localization the Localization service instance @param Application $application the Application container instance @param EntityManagerInterface $entityManager the EntityManagerInterface instance
__construct
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getByHandle($pkgHandle) { $r = $this->entityManager->getRepository('\Concrete\Core\Entity\Package'); return $r->findOneBy(['pkgHandle' => $pkgHandle]); }
Get a package entity given its handle. @param string $pkgHandle @return \Concrete\Core\Entity\Package|null
getByHandle
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getByID($pkgID) { $r = $this->entityManager->getRepository('\Concrete\Core\Entity\Package'); return $r->findOneBy(['pkgID' => $pkgID]); }
Get a package entity given its ID. @param int $pkgID @return \Concrete\Core\Entity\Package|null
getByID
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getInstalledList() { $r = $this->entityManager->getRepository('\Concrete\Core\Entity\Package'); return $r->findBy(['pkgIsInstalled' => true], ['pkgDateInstalled' => 'asc']); }
Get the package entities of installed packages. @return \Concrete\Core\Entity\Package[]
getInstalledList
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getAvailablePackages($onlyNotInstalled = true) { $dh = $this->application->make('helper/file'); $packages = $dh->getDirectoryContents(DIR_PACKAGES); if ($onlyNotInstalled) { $handles = $this->getInstalledHandles(); $packages = array_diff($packages, $handles); } if (count($packages) > 0) { $packagesTemp = []; // get package objects from the file system foreach ($packages as $p) { if (file_exists(DIR_PACKAGES . '/' . $p . '/' . FILENAME_CONTROLLER)) { $pkg = $this->getClass($p); if (!empty($pkg)) { $packagesTemp[] = $pkg; } } } $packages = $packagesTemp; } return $packages; }
Get the package controllers of the available packages. @param bool $onlyNotInstalled true to get the controllers of not installed packages, false to get all the package controllers @return \Concrete\Core\Package\Package[]
getAvailablePackages
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getLocalUpgradeablePackages() { $packages = $this->getAvailablePackages(false); $upgradeables = []; foreach ($packages as $p) { $entity = $this->getByHandle($p->getPackageHandle()); if ($entity) { if (version_compare($p->getPackageVersion(), $entity->getPackageVersion(), '>')) { $p->pkgCurrentVersion = $entity->getPackageVersion(); $upgradeables[] = $p; } } } return $upgradeables; }
Get the controllers of packages that have newer versions in the local packages directory than those which are in the Packages table. This means they're ready to be upgraded. @return \Concrete\Core\Package\Package[]
getLocalUpgradeablePackages
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getInstalledHandles() { $query = 'select p.pkgHandle from \\Concrete\\Core\\Entity\\Package p'; $r = $this->entityManager->createQuery($query); $result = $r->getArrayResult(); $handles = []; foreach ($result as $r) { $handles[] = $r['pkgHandle']; } return $handles; }
Get the handles of all the installed packages. @return string[]
getInstalledHandles
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getRemotelyUpgradeablePackages() { $packages = $this->getInstalledList(); $upgradeables = []; foreach ($packages as $p) { if (version_compare($p->getPackageVersion(), $p->getPackageVersionUpdateAvailable(), '<')) { $upgradeables[] = $p; } } return $upgradeables; }
Get the controllers of the packages that have an upgraded version available in the marketplace. @return \Concrete\Core\Package\Package[]
getRemotelyUpgradeablePackages
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function bootPackageEntityManager(Package $p, $clearCache = false) { $configUpdater = new EntityManagerConfigUpdater($this->entityManager); $providerFactory = new PackageProviderFactory($this->application, $p); $provider = $providerFactory->getEntityManagerProvider(); $configUpdater->addProvider($provider); if ($clearCache) { $cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl(); if ($cache) { $cache->flushAll(); } } }
Initialize the entity manager for a package. @param \Concrete\Core\Package\Package $p The controller of package @param bool $clearCache Should the entity metadata cache be emptied?
bootPackageEntityManager
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function uninstall(Package $p) { $p->uninstall(); $config = $this->entityManager->getConfiguration(); $cache = $config->getMetadataCacheImpl(); if ($cache) { $cache->flushAll(); } $inspector = $this->application->make(Inspector::class); $command = new UpdateRemoteDataCommand([$inspector->getPackagesField()]); $this->application->executeCommand($command); }
Uninstall a package. @param \Concrete\Core\Package\Package $p the controller of the package to be uninstalled
uninstall
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function install(Package $p, $data) { $this->localization->pushActiveContext(Localization::CONTEXT_SYSTEM); if (method_exists($p, 'validate_install')) { $response = $p->validate_install($data); } if (isset($response) && $response instanceof ErrorList && $response->has()) { return $response; } $this->bootPackageEntityManager($p, true); $p->install($data); $inspector = $this->application->make(Inspector::class); $command = new UpdateRemoteDataCommand([$inspector->getPackagesField()]); $this->application->executeCommand($command); $u = $this->application->make(User::class); $swapper = $p->getContentSwapper(); if ($u->isSuperUser() && $swapper->allowsFullContentSwap($p) && isset($data['pkgDoFullContentSwap']) && $data['pkgDoFullContentSwap']) { $swapper->swapContent($p, $data); if (method_exists($p, 'on_after_swap_content')) { $p->on_after_swap_content($data); } } $this->localization->popActiveContext(); $this->getByHandle($p->getPackageHandle()); return $p; }
Install a package. @param \Concrete\Core\Package\Package $p the controller of the package to be installed @param array $data data to be passed to the Package::validate_install(), Package::install(), ContentSwapper::swapContent(), ContentSwapper::on_after_swap_content() methods @return \Concrete\Core\Error\ErrorList\ErrorList|\Concrete\Core\Package\Package return an ErrorList instance in case of errors, the package controller otherwise
install
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function getClass($pkgHandle) { $cache = $this->application->make('cache/request'); $item = $cache->getItem('package/class/' . $pkgHandle); if ($item->isMiss()) { $item->lock(); $classAutoloader = ClassAutoloader::getInstance(); $classAutoloader->registerPackageHandle($pkgHandle); // loads and instantiates the object $class = '\\Concrete\\Package\\' . camelcase($pkgHandle) . '\\Controller'; $packageController = null; try { $packageController = $this->application->make($class); if (!$packageController instanceof Package) { $packageController = null; $errorDetails = t('The package controller does not extend the PHP class %s', Package::class); } } catch (Throwable $x) { $errorDetails = $x->getMessage(); } if ($packageController === null) { $classAutoloader->unregisterPackage($pkgHandle); $packageController = $this->application->make(BrokenPackage::class, ['pkgHandle' => $pkgHandle, 'errorDetails' => $errorDetails]); } else { $classAutoloader->registerPackageController($packageController); } $cache->save($item->set($packageController)); } else { $packageController = $item->get(); } return clone $packageController; }
Get the controller of a package given its handle. @param string $pkgHandle Handle of package @return \Concrete\Core\Package\Package
getClass
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function setupLocalization(LocalizablePackageInterface $package, $locale = null, $translator = 'current') { if ($translator === 'current') { $translator = $this->localization->getActiveTranslateObject(); } if (is_object($translator)) { $locale = (string) $locale; if ($locale === '') { $locale = $this->localization->getLocale(); } $languageFile = $package->getTranslationFile($locale); if (is_file($languageFile)) { $translator->addTranslationFile('gettext', $languageFile); } } }
@deprecated @param LocalizablePackageInterface $package @param string|null $locale @param \Laminas\I18n\Translator\Translator|'current' $translator
setupLocalization
php
concretecms/concretecms
concrete/src/Package/PackageService.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageService.php
MIT
public function register() { $this->app ->when(Offline\Inspector::class) ->needs('$parsers') ->give(function (Application $app) { return [ $app->make(Offline\Parser\Legacy::class), $app->make(Offline\Parser\FiveSeven::class), ]; }) ; }
{@inheritdoc} @see \Concrete\Core\Foundation\Service\Provider::register()
register
php
concretecms/concretecms
concrete/src/Package/PackageServiceProvider.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/PackageServiceProvider.php
MIT
public static function getClass($pkgHandle) { if (is_dir(DIR_STARTING_POINT_PACKAGES . '/' . $pkgHandle)) { $class = '\\Application\\StartingPointPackage\\' . camelcase($pkgHandle) . '\\Controller'; } else { $class = '\\Concrete\\StartingPointPackage\\' . camelcase($pkgHandle) . '\\Controller'; } if (class_exists($class, true)) { $cl = Core::build($class); } else { $cl = null; } return $cl; }
@param string $pkgHandle @return static|null
getClass
php
concretecms/concretecms
concrete/src/Package/StartingPointPackage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/StartingPointPackage.php
MIT
public function executeInstallRoutine($routineName) { if (!@ini_get('safe_mode') && $this->app->make(FunctionInspector::class)->functionAvailable('set_time_limit')) { @set_time_limit(1000); } $timezone = $this->installerOptions->getServerTimeZone(true); date_default_timezone_set($timezone->getName()); $this->app->make('config')->set('app.server_timezone', $timezone->getName()); $localization = Localization::getInstance(); $localization->pushActiveContext(Localization::CONTEXT_SYSTEM); $error = null; try { $this->$routineName(); } catch (Exception $x) { $error = $x; } catch (Throwable $x) { $error = $x; } $localization->popActiveContext(); if ($error !== null) { throw $error; } }
@param string $routineName @throws Exception @throws Throwable
executeInstallRoutine
php
concretecms/concretecms
concrete/src/Package/StartingPointPackage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/StartingPointPackage.php
MIT
protected function install_blocktypes() { $ci = new ContentImporter(ContentImporter::IMPORT_MODE_INSTALL); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_basic.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_navigation.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_form.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_express.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_social.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_calendar.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_multimedia.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_core_desktop.xml'); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/blocktypes_other.xml'); }
@deprecated This method has been splitted in smaller chunks
install_blocktypes
php
concretecms/concretecms
concrete/src/Package/StartingPointPackage.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/StartingPointPackage.php
MIT
public function __construct(Application $application) { $this->application = $application; }
Initializes the instance. @param Application $application
__construct
php
concretecms/concretecms
concrete/src/Package/Dependency/DependencyChecker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/DependencyChecker.php
MIT
public function setInstalledPackages(array $installedPackages) { $dictionary = []; foreach ($installedPackages as $installedPackage) { $dictionary[$installedPackage->getPackageHandle()] = $installedPackage; } $this->installedPackages = $dictionary; return $this; }
Set the list of installed packages. @param Package[] $installedPackages @return $this
setInstalledPackages
php
concretecms/concretecms
concrete/src/Package/Dependency/DependencyChecker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/DependencyChecker.php
MIT
protected function getInstalledPackages() { if ($this->installedPackages === null) { $installedPackages = []; $packageService = $this->application->make(PackageService::class); foreach ($packageService->getInstalledHandles() as $packageHandle) { $installedPackages[$packageHandle] = $packageService->getClass($packageHandle); } $this->installedPackages = $installedPackages; } return $this->installedPackages; }
Get the list of installed packages. @return Package[] keys are package handles, values are Package instances
getInstalledPackages
php
concretecms/concretecms
concrete/src/Package/Dependency/DependencyChecker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/DependencyChecker.php
MIT
protected function getPackageRequirementsForPackage(Package $package, Package $otherPackage) { $dependencies = $package->getPackageDependencies(); $otherPackageHandle = $otherPackage->getPackageHandle(); return isset($dependencies[$otherPackageHandle]) ? $dependencies[$otherPackageHandle] : null; }
Get the requirements for a package in respect to another package. @param Package $package @param Package $otherPackage @return string[]|string|bool|null
getPackageRequirementsForPackage
php
concretecms/concretecms
concrete/src/Package/Dependency/DependencyChecker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/DependencyChecker.php
MIT
protected function checkPackageCompatibility(Package $package, Package $dependentPackage, $requirements) { $result = null; $version = $dependentPackage->getPackageVersion(); if ($requirements === false) { $result = new IncompatiblePackagesException($package, $dependentPackage); } elseif (is_string($requirements)) { if (version_compare($version, $requirements) < 0) { $result = new VersionMismatchException($package, $dependentPackage, $requirements); } } elseif (is_array($requirements)) { if (version_compare($version, $requirements[0]) < 0 || version_compare($version, $requirements[1]) > 0) { $result = new VersionMismatchException($package, $dependentPackage, $requirements); } } return $result; }
@param Package $package @param Package $dependentPackage @param string[]|string|bool|null $requirements @return \LogicException|null
checkPackageCompatibility
php
concretecms/concretecms
concrete/src/Package/Dependency/DependencyChecker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/DependencyChecker.php
MIT
public function __construct(Package $blockingPackage, Package $incompatiblePackage) { $this->blockingPackage = $blockingPackage; $this->incompatiblePackage = $incompatiblePackage; parent::__construct(t( 'The package "%1$s" can\'t be installed if the package "%2$s" is installed.', $incompatiblePackage->getPackageName(), $blockingPackage->getPackageName() )); }
Initialize the instance. @param \Concrete\Core\Package\Package $blockingPackage the package that doesn't want the other package @param \Concrete\Core\Package\Package $incompatiblePackage the incompatible package
__construct
php
concretecms/concretecms
concrete/src/Package/Dependency/IncompatiblePackagesException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/IncompatiblePackagesException.php
MIT
public function getBlockingPackage() { return $this->blockingPackage; }
Get the package that can't be uninstalled. @return \Concrete\Core\Package\Package
getBlockingPackage
php
concretecms/concretecms
concrete/src/Package/Dependency/IncompatiblePackagesException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/IncompatiblePackagesException.php
MIT
public function getIncompatiblePackage() { return $this->incompatiblePackage; }
Get the incompatible package. @return \Concrete\Core\Package\Package
getIncompatiblePackage
php
concretecms/concretecms
concrete/src/Package/Dependency/IncompatiblePackagesException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/IncompatiblePackagesException.php
MIT
public function __construct(Package $notInstallablePackage, $missingPackageHandle, $requirements) { $this->notInstallablePackage = $notInstallablePackage; $this->missingPackageHandle = $missingPackageHandle; $this->requirements = $requirements; if (is_string($requirements)) { $message = t( 'The package "%1$s" requires the package with handle "%2$s" (version %3$s or greater)', $notInstallablePackage->getPackageName(), $missingPackageHandle, $requirements ); } elseif (is_array($requirements)) { $message = t( 'The package "%1$s" requires the package with handle "%2$s" (version between %3$s and %4$s)', $notInstallablePackage->getPackageName(), $missingPackageHandle, $requirements[0], $requirements[1] ); } else { $message = t( 'The package "%1$s" requires the package with handle "%2$s"', $notInstallablePackage->getPackageName(), $missingPackageHandle ); } parent::__construct($message); }
Initialize the instance. @param \Concrete\Core\Package\Package $notInstallablePackage the package that can't be installed @param string $missingPackageHandle the handle of the package that's not installed @param string|string[]|bool $requirements the version requirements of the package
__construct
php
concretecms/concretecms
concrete/src/Package/Dependency/MissingRequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/MissingRequiredPackageException.php
MIT
public function getNotInstallablePackage() { return $this->notInstallablePackage; }
Get the package that can't be installed. @return \Concrete\Core\Package\Package
getNotInstallablePackage
php
concretecms/concretecms
concrete/src/Package/Dependency/MissingRequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/MissingRequiredPackageException.php
MIT
public function getMissingPackageHandle() { return $this->missingPackageHandle; }
Get the handle of the package that's not installed. @return string
getMissingPackageHandle
php
concretecms/concretecms
concrete/src/Package/Dependency/MissingRequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/MissingRequiredPackageException.php
MIT
public function getRequirements() { return $this->requirements; }
Get the version requirements of the not installed package. @var string|string[]|bool
getRequirements
php
concretecms/concretecms
concrete/src/Package/Dependency/MissingRequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/MissingRequiredPackageException.php
MIT
public function __construct(Package $uninstallablePackage, Package $blockingPackage) { $this->uninstallablePackage = $uninstallablePackage; $this->blockingPackage = $blockingPackage; parent::__construct(t( 'The package "%1$s" can\'t be uninstalled since the package "%2$s" requires it.', $uninstallablePackage->getPackageName(), $blockingPackage->getPackageName() )); }
Initialize the instance. @param \Concrete\Core\Package\Package $uninstallablePackage the package that can't be uninstalled @param \Concrete\Core\Package\Package $blockingPackage the package that requires the package that can't be uninstalled
__construct
php
concretecms/concretecms
concrete/src/Package/Dependency/RequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/RequiredPackageException.php
MIT
public function getUninstallablePackage() { return $this->uninstallablePackage; }
Get the package that can't be uninstalled. @return \Concrete\Core\Package\Package
getUninstallablePackage
php
concretecms/concretecms
concrete/src/Package/Dependency/RequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/RequiredPackageException.php
MIT
public function getBlockingPackage() { return $this->blockingPackage; }
Get the package that requires the package that can't be uninstalled. @return \Concrete\Core\Package\Package
getBlockingPackage
php
concretecms/concretecms
concrete/src/Package/Dependency/RequiredPackageException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/RequiredPackageException.php
MIT
public function __construct(Package $blockingPackage, Package $package, $requiredVersion) { $this->package = $package; $this->blockingPackage = $blockingPackage; $this->requiredVersion = $requiredVersion; if (is_array($requiredVersion)) { $message = t( 'The package "%1$s" requires that package "%2$s" has a version between %3$s and %4$s', $blockingPackage->getPackageName(), $package->getPackageName(), $requiredVersion[0], $requiredVersion[1] ); } else { $message = t( 'The package "%1$s" requires that package "%2$s" has a version %3$s or greater', $blockingPackage->getPackageName(), $package->getPackageName(), $requiredVersion ); } parent::__construct($message); }
Initialize the instance. @param \Concrete\Core\Package\Package $blockingPackage the package that causes the dependency problem @param \Concrete\Core\Package\Package $package the package that fails the requirement @param string|string[] $requiredVersion the required package version
__construct
php
concretecms/concretecms
concrete/src/Package/Dependency/VersionMismatchException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/VersionMismatchException.php
MIT
public function getBlockingPackage() { return $this->blockingPackage; }
Get the package that causes the dependency problem. @return \Concrete\Core\Package\Package
getBlockingPackage
php
concretecms/concretecms
concrete/src/Package/Dependency/VersionMismatchException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/VersionMismatchException.php
MIT
public function getPackage() { return $this->package; }
Get the package that fails the requirement. @return \Concrete\Core\Package\Package
getPackage
php
concretecms/concretecms
concrete/src/Package/Dependency/VersionMismatchException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/VersionMismatchException.php
MIT
public function getRequiredVersion() { return $this->requiredVersion; }
Get the required package version. @return string|string[]
getRequiredVersion
php
concretecms/concretecms
concrete/src/Package/Dependency/VersionMismatchException.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Dependency/VersionMismatchException.php
MIT
public function addEntityManager(EntityManagerInterface $em) { if (!in_array($em, $this->entityManagers, true)) { $this->entityManagers[] = $em; } return $this; }
Add an EntityManagerInterface instance to the list. @param EntityManagerInterface $em @return $this
addEntityManager
php
concretecms/concretecms
concrete/src/Package/Event/PackageEntities.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Event/PackageEntities.php
MIT
public function getEntityManagers() { return $this->entityManagers; }
Get the EntityManagerInterface instances. @return EntityManagerInterface[]
getEntityManagers
php
concretecms/concretecms
concrete/src/Package/Event/PackageEntities.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Event/PackageEntities.php
MIT
public function getItemCategoryDisplayName() { return t('IP Access Control Categories'); }
{@inheritdoc} @see \Concrete\Core\Package\ItemCategory\ItemInterface::getItemCategoryDisplayName()
getItemCategoryDisplayName
php
concretecms/concretecms
concrete/src/Package/ItemCategory/IpAccessControlCategory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/ItemCategory/IpAccessControlCategory.php
MIT
public function getItemName($ipAccessControlCategory) { return $ipAccessControlCategory->getDisplayName(); }
{@inheritdoc} @see \Concrete\Core\Package\ItemCategory\ItemInterface::getItemName() @param \Concrete\Core\Entity\Permission\IpAccessControlCategory $ipAccessControlCategory
getItemName
php
concretecms/concretecms
concrete/src/Package/ItemCategory/IpAccessControlCategory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/ItemCategory/IpAccessControlCategory.php
MIT
public function getPackageItems(Package $package) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $repo = $em->getRepository(IpAccessControlCategoryEntity::class); return $repo->findBy(['package' => $package]); }
@param \Concrete\Core\Entity\Package $package @return \Concrete\Core\Entity\Permission\IpAccessControlCategory[]
getPackageItems
php
concretecms/concretecms
concrete/src/Package/ItemCategory/IpAccessControlCategory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/ItemCategory/IpAccessControlCategory.php
MIT
public function removeItem($ipAccessControlCategory) { if ($ipAccessControlCategory instanceof Entity && $ipAccessControlCategory->getIpAccessControlCategoryID() !== null) { $app = Application::getFacadeApplication(); $em = $app->make(EntityManagerInterface::class); $em->remove($ipAccessControlCategory); $em->flush($ipAccessControlCategory); } }
{@inheritdoc} @see \Concrete\Core\Package\ItemCategory\AbstractCategory::removeItem() @param \Concrete\Core\Entity\Permission\IpAccessControlCategory|mixed $ipAccessControlCategory
removeItem
php
concretecms/concretecms
concrete/src/Package/ItemCategory/IpAccessControlCategory.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/ItemCategory/IpAccessControlCategory.php
MIT
public function getItemName($type) { return $type->getTreeTypeHandle(); }
@param $type \Concrete\Core\Tree\TreeType @return mixed
getItemName
php
concretecms/concretecms
concrete/src/Package/ItemCategory/TreeType.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/ItemCategory/TreeType.php
MIT
public static function create($code, $message, $exceptionData = null) { $result = new static($message, $code); $result->exceptionData = $exceptionData; return $result; }
Create a new instance of this class. @param int $code the error code (one of the ERRORCODE_... constants) @param string $message the error message @param mixed $exceptionData he contextual data associated to the exception
create
php
concretecms/concretecms
concrete/src/Package/Offline/Exception.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Exception.php
MIT
public function getExceptionData() { return $this->exceptionData; }
Get the contextual data associated to the exception. @return mixed
getExceptionData
php
concretecms/concretecms
concrete/src/Package/Offline/Exception.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Exception.php
MIT
public function __construct(Filesystem $fs, array $parsers) { $this->fs = $fs; foreach ($parsers as $parser) { $this->addParser($parser); } }
@param \Illuminate\Filesystem\Filesystem $fs @param \Concrete\Core\Package\Offline\Parser[] $parsers
__construct
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public function addParser(Parser $parser) { $this->parsers[] = $parser; return $this; }
Add a parser to the parsers list. @param \Concrete\Core\Package\Offline\Parser $parser @return $this
addParser
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public function getParsers() { return $this->parsers; }
Get the parsers list. \Concrete\Core\Package\Offline\Parser[]
getParsers
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public function inspectPackageDirectory($directory) { $path = @realpath($directory); if (!is_string($path)) { throw Exception::create(Exception::ERRORCODE_DIRECTORYNOTFOUND, t('Unable to find the directory %s', $directory), $directory); } $controller = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $directory), '/') . '/' . FILENAME_PACKAGE_CONTROLLER; return $this->inspectControllerFile($controller); }
Extract the package details from the directory containing the package controller.php file. @param string $directory the directory containing the package controller.php file @throws \Concrete\Core\Package\Offline\Exception in case of problems @return \Concrete\Core\Package\Offline\PackageInfo
inspectPackageDirectory
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public function inspectControllerFile($filename) { $path = @realpath($filename); if (!is_string($path)) { throw Exception::create(Exception::ERRORCODE_FILENOTFOUND, t('Unable to find the file %s', $filename), $filename); } $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); try { $contents = $this->fs->get($path); } catch (FileNotFoundException $x) { throw Exception::create(Exception::ERRORCODE_FILENOTFOUND, t('Unable to find the file %s', $filename), $filename); } if (!is_string($contents)) { throw Exception::create(Exception::ERRORCODE_FILENOTREADABLE, t('Unable to read the file %s', $filename), $filename); } return $this->inspectControllerContent($contents) ->setPackageDirectory(substr($path, 0, strrpos($path, '/'))); }
Extract the package details reading its controller.php file. @param string $filename the path to the package controller.php file @throws \Concrete\Core\Package\Offline\Exception in case of problems @return \Concrete\Core\Package\Offline\PackageInfo
inspectControllerFile
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public function inspectControllerContent($content) { if (!is_string($content)) { throw Exception::create(Exception::ERRORCODE_BADPARAM, t('The function %s requires a string', __METHOD__), __METHOD__); } $tokens = token_get_all($content); $parser = $this->determineParser($tokens); return $parser->extractInfo($tokens); }
Extract the package details analyzing the contents of its controller.php file. @param string|mixed $content the content of the package controller.php file @throws \Concrete\Core\Package\Offline\Exception in case of problems @return \Concrete\Core\Package\Offline\PackageInfo
inspectControllerContent
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
protected function determineParser(array $tokens) { $result = null; foreach ($this->getParsers() as $parser) { if ($parser->canParseTokens($tokens)) { if ($result !== null) { throw Exception::create(Exception::ERRORCODE_MULTIPLEPARSERSFOUND, t('Multiple parsers found')); } $result = $parser; } } if ($result === null) { throw Exception::create(Exception::ERRORCODE_NOPARSERSFOUND, t('No parsers found')); } return $result; }
Analyze the tokens to determine the analyzer to be used. @param array $tokens @throws \Concrete\Core\Package\Offline\Exception in case of problems @return \Concrete\Core\Package\Offline\Parser
determineParser
php
concretecms/concretecms
concrete/src/Package/Offline/Inspector.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Inspector.php
MIT
public static function create() { return new static(); }
Create a new instance of this class. @return static
create
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getPackageDirectory() { return $this->packageDirectory; }
Get the package directory (normalized, without trailing slashes). @return string
getPackageDirectory
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setPackageDirectory($value) { $this->packageDirectory = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', (string) $value), '/'); return $this; }
Set the package directory. @param string $value @return $this
setPackageDirectory
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getHandle() { return $this->handle; }
Get the package handle. @return string
getHandle
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setHandle($value) { $this->handle = (string) $value; return $this; }
Set the package handle. @param string $value @return $this
setHandle
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getVersion() { return $this->version; }
Get the package version. @return string
getVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setVersion($value) { $this->version = (string) $value; return $this; }
Set the package version. @param string $value @return $this
setVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getName() { return $this->name; }
Get the package name, in English. @return string
getName
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setName($value) { $this->name = (string) $value; return $this; }
Set the package name, in English. @param string $value @return $this
setName
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getDescription() { return $this->description; }
Get the package description, in English. @return string
getDescription
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setDescription($value) { $this->description = (string) $value; return $this; }
Set the package description, in English. @param string $value @return $this
setDescription
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getMinimumCoreVersion() { return $this->minimumCoreVersion; }
Get the minimum Concrete version. @return string
getMinimumCoreVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function getMayorMinimumCoreVersion() { $chunks = array_merge(explode('.', $this->getMinimumCoreVersion()), ['0', '0']); return (int) $chunks[0] === 5 ? "{$chunks[0]}.{$chunks[1]}" : $chunks[0]; }
Get the major minimum Concrete version. @return string @example '5.0' @example '5.6' @example '5.7' @example '8' @example '9'
getMayorMinimumCoreVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setMinimumCoreVersion($value) { $this->minimumCoreVersion = $value; return $this; }
Set the minimum Concrete version. @param string $value @return $this
setMinimumCoreVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function setMinimumPHPVersion(string $value): self { $this->minimumPHPVersion = $value; return $this; }
Set the minimum PHP version. @return $this
setMinimumPHPVersion
php
concretecms/concretecms
concrete/src/Package/Offline/PackageInfo.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/PackageInfo.php
MIT
public function __construct(StringValidator $stringValidator) { $this->stringValidator = $stringValidator; }
Initialize the instance. @param \Concrete\Core\Utility\Service\Validation\Strings $stringValidator the string validator service to be used to check the validity of handles
__construct
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
public function extractInfo(array $tokens) { list($className, $classStart, $classEnd) = $this->findControllerClass($tokens); return PackageInfo::create() ->setHandle($this->getPackageHandle($tokens, $className, $classStart, $classEnd)) ->setVersion($this->getPackageVersion($tokens, $className, $classStart, $classEnd)) ->setName($this->getPackageName($tokens, $className, $classStart, $classEnd)) ->setDescription($this->getPackageDescription($tokens, $className, $classStart, $classEnd)) ->setMinimumCoreVersion($this->getPackageMinimumCodeVersion($tokens, $className, $classStart, $classEnd)) ->setMinimumPHPVersion($this->getPackageMinimumPHPVersion($tokens, $className, $classStart, $classEnd)) ; }
Extract package details from the PHP tokens of the package controller.php file. @param array $tokens the PHP tokens of the package controlller.php file @throws \Concrete\Core\Package\Offline\Exception in case of problems @return \Concrete\Core\Package\Offline\PackageInfo
extractInfo
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function findControllerClass(array $tokens) { $result = null; $numTokens = count($tokens); for ($tokenIndex = 0; $tokenIndex < $numTokens;) { $classIndex = $this->findTypedToken($tokens, [T_CLASS], $tokenIndex, $numTokens); if ($classIndex === null) { break; } $classStart = $this->findTextToken($tokens, ['{'], $classIndex + 1, $numTokens); if ($classStart === null) { throw Exception::create(Exception::ERRORCODE_MISSING_OPENCURLY, t('Unable to find the opening of the controller class')); } $tokenIndex = $classStart; $nestingLevel = 1; for (; ;) { $tokenIndex = $this->findTextToken($tokens, ['{', '}'], $tokenIndex + 1, $numTokens); if ($tokenIndex === null) { throw Exception::create(Exception::ERRORCODE_MISSING_CLOSECURLY, t('Unable to find the closing of the controller class')); } if ($tokens[$tokenIndex] === '{') { ++$nestingLevel; } else { --$nestingLevel; if ($nestingLevel === 0) { $classEnd = $tokenIndex; ++$tokenIndex; break; } } } $classNameIndex = $this->findTypedToken($tokens, [T_STRING], $classIndex, $classStart); if ($classNameIndex === null) { throw Exception::create(Exception::ERRORCODE_MISSING_CLASSNAME, t('Unable to find the name of the controller class')); } $className = $tokens[$classNameIndex][1]; if (preg_match($this->getControllerClassNameRegularExpression(), $className)) { if ($result !== null) { throw Exception::create(Exception::ERRORCODE_MULTIPLE_CONTROLLECLASSES, t('Multiple controller classes found')); } $result = [$className, $classStart, $classEnd]; } } if ($result === null) { throw Exception::create(Exception::ERRORCODE_CONTROLLERCLASS_NOT_FOUND, t('Unable to find the controller class')); } return $result; }
Find the package controller class. @param array $tokens the PHP tokens of the package controlller.php file @throws \Concrete\Core\Package\Offline\Exception in case of problems @return array[] [$className, $classStart, $classEnd] returns the class name, the index of the first PHP token of the class body (its first '{'}, and the index of the last PHP token of the class body (its last '}'}
findControllerClass
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageHandle(array $tokens, $className, $classStart, $classEnd) { $fromClassName = $this->getPackageHandleFromClassName($tokens, $className, $classStart); $fromProperty = $this->getPropertyValue($tokens, '$pkgHandle', $classStart, $classEnd); if (!is_string($fromProperty)) { throw Exception::create(Exception::ERRORCODE_MISSING_PACKAGEHANDLE_PROPERTY, t('The package controller lacks the %s property', '$pkgHandle')); } if ($fromClassName !== $fromProperty) { throw Exception::create(Exception::ERRORCODE_MISMATCH_PACKAGEHANDLE, t('The package handle defined by the class name (%1$s) differs from the one defined by the %2$s property (%3$s)', $fromClassName, '$pkgHandle', $fromProperty)); } if (!$this->stringValidator->handle($fromClassName)) { throw Exception::create(Exception::ERRORCODE_INVALID_PACKAGEHANDLE, t('The package handle "%s" is not valid', $fromClassName)); } return $fromClassName; }
Get the package handle. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageHandle
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageVersion(array $tokens, $className, $classStart, $classEnd) { $fromProperty = (string) $this->getPropertyValue($tokens, '$pkgVersion', $classStart, $classEnd); if ($fromProperty === '') { throw Exception::create(Exception::ERRORCODE_MISSING_PACKAGEVERSION_PROPERTY, t('The package controller lacks the %s property', '$pkgVersion')); } if (!$this->isVersionValid($fromProperty)) { throw Exception::create(Exception::ERRORCODE_INVALID_PACKAGEVERSION, t('The package version "%s" is not valid', $fromProperty)); } return $fromProperty; }
Get the package version. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageVersion
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageName(array $tokens, $className, $classStart, $classEnd) { $fromMethod = (string) $this->getSimpleMethodReturnValue($tokens, 'getPackageName', $classStart, $classEnd); if ($fromMethod !== '') { return $fromMethod; } $fromProperty = (string) $this->getPropertyValue($tokens, '$pkgName', $classStart, $classEnd); if ($fromProperty !== '') { return $fromProperty; } throw Exception::create(Exception::ERRORCODE_MISSING_PACKAGENAME, t('The package controller lacks both the %1$s property and the %2$s method', '$pkgName', 'getPackageName')); }
Get the package name. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageName
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageDescription(array $tokens, $className, $classStart, $classEnd) { $fromMethod = (string) $this->getSimpleMethodReturnValue($tokens, 'getPackageDescription', $classStart, $classEnd); if ($fromMethod !== '') { return $fromMethod; } $fromProperty = (string) $this->getPropertyValue($tokens, '$pkgDescription', $classStart, $classEnd); if ($fromProperty !== '') { return $fromProperty; } return ''; }
Get the package description. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageDescription
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageMinimumCodeVersion(array $tokens, $className, $classStart, $classEnd) { $fromProperty = $this->getPropertyValue($tokens, '$appVersionRequired', $classStart, $classEnd); return (string) $fromProperty === '' ? $this->getDefaultPackageMinimumCodeVersion() : $fromProperty; }
Get the minimum supported core version. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageMinimumCodeVersion
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPackageMinimumPHPVersion(array $tokens, string $className, int $classStart, int $classEnd): string { $fromProperty = $this->getPropertyValue($tokens, '$phpVersionRequired', $classStart, $classEnd); return (string) $fromProperty; }
Get the minimum supported PHP version. @param array $tokens the PHP tokens of the package controlller.php file @param string $className the class name of the package controller @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
getPackageMinimumPHPVersion
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getPropertyValue(array $tokens, $propertyName, $classStart, $classEnd) { $nestingLevel = 0; for ($index = $classStart + 1; $index < $classEnd; ++$index) { $token = $tokens[$index]; if ($token === '{') { ++$nestingLevel; } elseif ($token === '}') { --$nestingLevel; } elseif ($nestingLevel === 0 && is_array($token) && $token[0] === T_VARIABLE && $token[1] === $propertyName) { $semicolonIndex = $this->findTextToken($tokens, [';'], $index + 1, $classEnd); if ($semicolonIndex === null) { throw Exception::create(Exception::ERRORCODE_MISSIMG_SEMICOLON, t('Missing semicolon after property %s', $propertyName)); } $equalsIndex = $this->findTextToken($tokens, ['='], $index + 1, $semicolonIndex); if ($equalsIndex === null) { return null; } $valueTokens = $this->stripNonCodeTokens($tokens, $equalsIndex + 1, $semicolonIndex); if (count($valueTokens) !== 1) { throw Exception::create(Exception::ERRORCODE_UNSUPPORTED_PROPERTYVALUE, t('Decoding complex tokens for property %s is not supported', $propertyName)); } if (!is_array($valueTokens[0])) { throw Exception::create(Exception::ERRORCODE_UNSUPPORTED_PROPERTYVALUE, t('Decoding string tokens for property %s is not supported', $propertyName)); } return $this->decodeValueToken($valueTokens, $propertyName); } } return null; }
Get the value of a class property. @param array $tokens the PHP tokens of the package controlller.php file @param string $propertyName @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return mixed
getPropertyValue
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getSimpleMethodReturnValue(array $tokens, $methodName, $classStart, $classEnd) { $range = $this->getSimpleMethodBodyTokenRange($tokens, $methodName, $classStart, $classEnd); if ($range === null) { return null; } $codeTokens = $this->stripNonCodeTokens($tokens, $range[0] + 1, $range[1]); if (empty($codeTokens)) { return null; } $token = array_shift($codeTokens); if (!is_array($token) || $token[0] !== T_RETURN) { throw Exception::create(Exception::ERRORCODE_METHOD_TOO_COMPLEX, t('The body of the %s controller method is too complex', $methodName)); } $token = array_pop($codeTokens); if ($token !== ';') { throw Exception::create(Exception::ERRORCODE_METHOD_TOO_COMPLEX, t('The body of the %s controller method is too complex', $methodName)); } $codeTokens = $this->stripTFunctionCall($codeTokens); $codeTokens = $this->stripEnclosingParenthesis($codeTokens); if (count($codeTokens) !== 1 || !is_array($codeTokens[0])) { throw Exception::create(Exception::ERRORCODE_METHOD_TOO_COMPLEX, t('The body of the %s controller method is too complex', $methodName)); } return $this->decodeValueToken($codeTokens, $methodName); }
Get the return value of a class method. Get the value returned from a very simple class method (that is, containing only a "return something;"). @param array $tokens the PHP tokens of the package controlller.php file @param string $methodName @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return mixed
getSimpleMethodReturnValue
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function getSimpleMethodBodyTokenRange(array $tokens, $methodName, $classStart, $classEnd) { $nestingLevel = 0; for ($index = $classStart + 1; $index < $classEnd; ++$index) { $token = $tokens[$index]; if ($token === '{') { ++$nestingLevel; } elseif ($token === '}') { --$nestingLevel; } elseif ($nestingLevel === 0 && is_array($token) && $token[0] === T_FUNCTION) { $nameIndex = $this->skipNonCodeTokens($tokens, $index + 1, $classEnd); if ($nameIndex !== null && is_array($tokens[$nameIndex]) && $tokens[$nameIndex][0] === T_STRING && strcasecmp($tokens[$nameIndex][1], $methodName) === 0) { $bodyStart = $this->findTextToken($tokens, ['{'], $nameIndex + 1, $classEnd); if ($bodyStart === null) { throw Exception::create(Exception::ERRORCODE_MISSING_METHOD_BODY, t('Missing body of the %s controller method', $methodName)); } $bodyEnd = $this->findTextToken($tokens, ['}'], $bodyStart + 1, $classEnd); if ($bodyEnd === null) { throw Exception::create(Exception::ERRORCODE_MISSING_METHOD_BODY, t('Missing body of the %s controller method', $methodName)); } if ($this->findTextToken($tokens, ['{'], $bodyStart + 1, $bodyEnd) !== null) { throw Exception::create(Exception::ERRORCODE_METHOD_TOO_COMPLEX, t('The body of the %s controller method is too complex', $methodName)); } return [$bodyStart, $bodyEnd]; } } } return null; }
Get token range of the body of a very simple class method (that is, containing only a "return something;"). @param array $tokens the PHP tokens of the package controlller.php file @param string $methodName @param int $classStart the index of the first PHP token of the class body (its first '{') @param int $classEnd the index of the last PHP token of the class body (its last '}'} @throws \Concrete\Core\Package\Offline\Exception in case of problems @return int[]|null returns null if it can't be detected (for example, for abstract methods), the token index of the opening '{' and the token index of the closing '}' otherwise
getSimpleMethodBodyTokenRange
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function isVersionValid($version) { if (!is_string($version) || $version === '') { return false; } return preg_match('/^\d+(\.\d+)*([\w\-]+(\d+(\.\d+)*)?)?$/', $version); }
Check if a version is valid. @param string|mixed $version @return bool
isVersionValid
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function findTypedToken(array $tokens, array $tokenIDs, $startIndexInclusive = 0, $endIndexExclusive = null) { if ($endIndexExclusive === null) { $endIndexExclusive = count($tokens); } for ($index = $startIndexInclusive; $index < $endIndexExclusive; ++$index) { $token = $tokens[$index]; if (is_array($token) && in_array($token[0], $tokenIDs, true)) { return $index; } } return null; }
Find the index of a token given its type. @param array $tokens the list of PHP tokens where the search should be performed @param int[] $tokenIDs the list of token identifiers to be searched @param int $startIndexInclusive the initial index where the search should start (inclusive) @param int|null $endIndexExclusive the final index where the search should end (exclusive); if null we'll search until the end of the token list @return int|null the index of the first token with an ID included in $tokenIDs otherwise; return NULL of none of the token ID have been found
findTypedToken
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function findTextToken(array $tokens, array $tokenContent, $startIndexInclusive = 0, $endIndexExclusive = null) { if ($endIndexExclusive === null) { $endIndexExclusive = count($tokens); } for ($index = $startIndexInclusive; $index < $endIndexExclusive; ++$index) { if (in_array($tokens[$index], $tokenContent, true)) { return $index; } } return null; }
Find the index of a text token given its contents. @param array $tokens the list of PHP tokens where the search should be performed @param string[] $tokenContent the list of token values to be searched @param int $startIndexInclusive the initial index where the search should start (inclusive) @param int|null $endIndexExclusive the final index where the search should end (exclusive); if null we'll search until the end of the token list @return int|null the index of the first string token found; return NULL of none of the strings have been found
findTextToken
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function stripNonCodeTokens(array $tokens, $startIndexInclusive = 0, $endIndexExclusive = null) { if ($endIndexExclusive === null) { $endIndexExclusive = count($tokens); } $result = []; for ($index = $startIndexInclusive; $index < $endIndexExclusive; ++$index) { $token = $tokens[$index]; if (!is_array($token) || !in_array($token[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { $result[] = $token; } } return $result; }
Strip whitespaces and comments from a list of tokens. @param array $tokens the list of PHP tokens to be processed @param int $startIndexInclusive the initial index where the search should start (inclusive) @param int|null $endIndexExclusive the final index where the search should end (exclusive); if null we'll search until the end of the token list @return array
stripNonCodeTokens
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function stripTFunctionCall(array $tokens) { if (!isset($tokens[0]) || !is_array($tokens[0]) || $tokens[0][0] !== T_STRING) { return $tokens; } if (strcasecmp($tokens[0][1], 't') !== 0) { return $tokens; } array_shift($tokens); return $tokens; }
Strip t() function calls at the beginning of a list of tokens tokens (if any). @param array $tokens the list of PHP tokens to be processed @return array
stripTFunctionCall
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function stripEnclosingParenthesis(array $tokens) { $numTokens = count($tokens); for (; ;) { if ($numTokens < 2 || $tokens[0] !== '(' || $tokens[$numTokens - 1] !== ')') { return $tokens; } array_pop($tokens); array_shift($tokens); $numTokens -= 2; } }
Strip enclosing parenthesis ("(...)") (if any) in a list of tokens. @param array $tokens the list of PHP tokens to be processed @return array
stripEnclosingParenthesis
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function skipNonCodeTokens(array $tokens, $startIndexInclusive = 0, $endIndexExclusive = null) { if ($endIndexExclusive === null) { $endIndexExclusive = count($tokens); } for ($index = $startIndexInclusive; $index < $endIndexExclusive; ++$index) { $token = $tokens[$index]; if (!is_array($token) || !in_array($token[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT], true)) { return $index; } } return null; }
Skip to the next non-whitespace and non-comment token. @param array $tokens the whole list of tokens @param int $startIndexInclusive the initial index where the search should start (inclusive) @param int|null $endIndexExclusive the final index where the search should end (exclusive); if null we'll search until the end of the token list @return int|null the next index of non-whitespace and non-comment token; NULL when arriving to the end of the array
skipNonCodeTokens
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function decodeValueToken(array $token, $associatedName) { switch ($token[0][0]) { case T_CONSTANT_ENCAPSED_STRING: return $this->decodeString($token[0][1]); case T_DNUMBER: return (float) $token[0][1]; case T_LNUMBER: return (int) $token[0][1]; default: throw Exception::create(Exception::ERRORCODE_UNSUPPORTED_TOKENVALUE, t('Unsupported value %1$s for %2$s', token_name($token[0][0]), $associatedName)); } }
Get the actual PHP value described by a value token. @param array $token the token containing the value @param string $associatedName the name associated to the value (used to display a useful error message), @throws \Concrete\Core\Package\Offline\Exception in case of problems @return mixed
decodeValueToken
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
protected function decodeString($string) { $len = strlen($string); if ($len < 2) { throw Exception::create(Exception::ERRORCODE_INVALID_STRING_TOKEN, t('Malformed string: %s', $string)); } if ($string[0] !== $string[$len - 1]) { throw Exception::create(Exception::ERRORCODE_INVALID_STRING_TOKEN, t('Malformed string: %s', $string)); } $enclosing = $string[0]; switch ($enclosing) { case '"': $escapeMap = [ '\\' => '\\', '"' => '"', 'n' => "\n", 'r' => "\r", 't' => "\t", 'v' => "\v", 'e' => "\e", 'f' => "\f", '$' => '$', ]; case "'": $escapeMap = [ '\\' => '\\', "'" => "'", ]; break; default: throw Exception::create(Exception::ERRORCODE_INVALID_STRING_TOKEN, t('Malformed string: %s', $string)); } $string = substr($string, 1, -1); $result = ''; for (; ;) { $p = strpos($string, '\\'); if ($p === false || !isset($string[$p + 1])) { $result .= $string; break; } $nextChar = $string[$p + 1]; $string = substr($string, 2); if (isset($escapeMap[$nextChar])) { $result .= $escapeMap[$nextChar]; } else { $result .= '\\' . $nextChar; } } return $result; }
Decode the value of a T_CONSTANT_ENCAPSED_STRING token. @param string $string the value of a T_CONSTANT_ENCAPSED_STRING token @throws \Concrete\Core\Package\Offline\Exception in case of problems @return string
decodeString
php
concretecms/concretecms
concrete/src/Package/Offline/Parser.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser.php
MIT
public function canParseTokens(array $tokens) { // 5.7+ packages use PHP namespaces $namespaceIndex = $this->findTypedToken($tokens, [T_NAMESPACE]); if ($namespaceIndex === null) { return false; } // Multiple namespaces are not supported return $this->findTypedToken($tokens, [T_NAMESPACE], $namespaceIndex + 1) === null; }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::canParseTokens()
canParseTokens
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/FiveSeven.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/FiveSeven.php
MIT
protected function getControllerClassNameRegularExpression() { return '/^Controller$/'; }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getControllerClassNameRegularExpression()
getControllerClassNameRegularExpression
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/FiveSeven.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/FiveSeven.php
MIT
protected function getPackageHandleFromClassName(array $tokens, $className, $classStart) { $namespaceIndex = $this->findTypedToken($tokens, [T_NAMESPACE], 0, $classStart - 1); // PHP 8 changed namespace tokens if (\PHP_MAJOR_VERSION > 7) { $namespaceNameIndex = $this->findTypedToken($tokens, [T_NAME_QUALIFIED], $namespaceIndex + 1, $classStart - 1); } else { $namespaceNameIndex = $this->findTypedToken($tokens, [T_STRING, T_NS_SEPARATOR], $namespaceIndex + 1, $classStart - 1); } if ($namespaceNameIndex === null) { throw Exception::create(Exception::ERRORCODE_MISSING_NAMESPACENAME, t('Unable to find the namespace name')); } $namespaceName = ''; if (\PHP_MAJOR_VERSION < 8) { while (is_array($tokens[$namespaceNameIndex]) && in_array($tokens[$namespaceNameIndex][0], [T_STRING, T_NS_SEPARATOR])) { $namespaceName .= $tokens[$namespaceNameIndex][1]; ++$namespaceNameIndex; } $namespaceName = trim($namespaceName, '\\'); } else { $namespaceName = $tokens[$namespaceNameIndex][1]; } $matches = null; if (!preg_match('/^Concrete\\\\Package\\\\(\w+)$/', $namespaceName, $matches)) { throw Exception::create(Exception::ERRORCODE_INVALID_NAMESPACENAME, t('The namespace "%s" is not valid', $namespaceName)); } return uncamelcase($matches[1]); }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getPackageHandleFromClassName()
getPackageHandleFromClassName
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/FiveSeven.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/FiveSeven.php
MIT
protected function getDefaultPackageMinimumCodeVersion() { return '5.7.0'; // https://github.com/concretecms/concretecms/blob/8.5.1/concrete/src/Package/Package.php#L183 }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getDefaultPackageMinimumCodeVersion()
getDefaultPackageMinimumCodeVersion
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/FiveSeven.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/FiveSeven.php
MIT
public function canParseTokens(array $tokens) { // Pre 5.7 packages don't use namespaces return $this->findTypedToken($tokens, [T_NAMESPACE]) === null; }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::canParseTokens()
canParseTokens
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/Legacy.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/Legacy.php
MIT
protected function getControllerClassNameRegularExpression() { return '/^\w+Package$/'; }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getControllerClassNameRegularExpression()
getControllerClassNameRegularExpression
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/Legacy.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/Legacy.php
MIT
protected function getPackageHandleFromClassName(array $tokens, $className, $classStart) { $matches = null; preg_match('/^(.+)Package$/', $className, $matches); return uncamelcase($matches[1]); }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getPackageHandleFromClassName()
getPackageHandleFromClassName
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/Legacy.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/Legacy.php
MIT
protected function getDefaultPackageMinimumCodeVersion() { return '5.0.0'; // https://github.com/concretecms/concrete5-legacy/blob/5.6.4.0/web/concrete/core/models/package.php#L144 }
{@inheritdoc} @see \Concrete\Core\Package\Offline\Parser::getDefaultPackageMinimumCodeVersion()
getDefaultPackageMinimumCodeVersion
php
concretecms/concretecms
concrete/src/Package/Offline/Parser/Legacy.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Offline/Parser/Legacy.php
MIT
public function process(PackageInfo $packageInfo, array $filters, array $writers) { foreach ($this->generateFileList($packageInfo->getPackageDirectory(), $packageInfo->getPackageDirectory(), $filters) as $packerFile) { foreach ($writers as $writer) { $writer->add($packerFile); } } foreach ($writers as $writer) { $writer->completed(); } }
Apply the filters and the writers to the package described by $packageInfo. @param \Concrete\Core\Package\Offline\PackageInfo $packageInfo @param \Concrete\Core\Package\Packer\Filter\FilterInterface[] $filters @param \Concrete\Core\Package\Packer\Writer\WriterInterface[] $writers @throws \RuntimeException in case of processing problems
process
php
concretecms/concretecms
concrete/src/Package/Packer/PackagePacker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Packer/PackagePacker.php
MIT
protected function generateFileList($packageDirectory, $directoryToParse, array $filters) { $subDirectories = []; $iterator = new RecursiveDirectoryIterator($directoryToParse, FilesystemIterator::UNIX_PATHS | FilesystemIterator::SKIP_DOTS); foreach ($iterator as $originalFile) { if (in_array($originalFile->getFilename(), ['.', '..'], true)) { continue; } foreach ($this->applyFilters($packageDirectory, $originalFile, $filters) as $processedFile) { if ($processedFile->isDirectory()) { $subDirectories[] = $processedFile->getAbsolutePath(); } yield $processedFile; } } foreach ($subDirectories as $subDirectory) { foreach ($this->generateFileList($packageDirectory, $subDirectory, $filters) as $processedFile) { yield $processedFile; } } }
Generate the list of files/directories applying the filters specified. @param string $packageDirectory the path to the package root directory @param string $directoryToParse the path to be analyzed @param \Concrete\Core\Package\Packer\Filter\FilterInterface[] $filters the filters to be applied @return \Concrete\Core\Package\Packer\PackerFile[]|\Generator
generateFileList
php
concretecms/concretecms
concrete/src/Package/Packer/PackagePacker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Packer/PackagePacker.php
MIT
protected function applyFilters($packageDirectory, SplFileInfo $source, array $filters) { $files = [PackerFile::fromSourceFileInfo($packageDirectory, $source)]; foreach ($filters as $filter) { $result = []; foreach ($files as $file) { foreach ($filter->apply($file) as $filtered) { $result[] = $filtered; } } $files = $result; } return $files; }
Apply the filters to a file found in the package directory or in one of its sub-directories. @param string $packageDirectory the path to the package root directory @param \SplFileInfo $source the file to be processes @param \Concrete\Core\Package\Packer\Filter\FilterInterface[] $filters the filters to be applied @return \Concrete\Core\Package\Packer\PackerFile[]
applyFilters
php
concretecms/concretecms
concrete/src/Package/Packer/PackagePacker.php
https://github.com/concretecms/concretecms/blob/master/concrete/src/Package/Packer/PackagePacker.php
MIT