Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Puli often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Puli, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 116 | class Puli |
||
| 117 | { |
||
| 118 | /** |
||
| 119 | * @var string|null |
||
| 120 | */ |
||
| 121 | private $rootDir; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var string |
||
| 125 | */ |
||
| 126 | private $env; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var EventDispatcherInterface|null |
||
| 130 | */ |
||
| 131 | private $dispatcher; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var Context|ProjectContext |
||
| 135 | */ |
||
| 136 | private $context; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @var ResourceRepository |
||
| 140 | */ |
||
| 141 | private $repo; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var Discovery |
||
| 145 | */ |
||
| 146 | private $discovery; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var object |
||
| 150 | */ |
||
| 151 | private $factory; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var FactoryManager |
||
| 155 | */ |
||
| 156 | private $factoryManager; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var ConfigFileManager |
||
| 160 | */ |
||
| 161 | private $configFileManager; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var RootPackageFileManager |
||
| 165 | */ |
||
| 166 | private $rootPackageFileManager; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var PackageManager |
||
| 170 | */ |
||
| 171 | private $packageManager; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var RepositoryManager |
||
| 175 | */ |
||
| 176 | private $repositoryManager; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var DiscoveryManager |
||
| 180 | */ |
||
| 181 | private $discoveryManager; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var AssetManager |
||
| 185 | */ |
||
| 186 | private $assetManager; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var InstallationManager |
||
| 190 | */ |
||
| 191 | private $installationManager; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @var InstallerManager |
||
| 195 | */ |
||
| 196 | private $installerManager; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @var ServerManager |
||
| 200 | */ |
||
| 201 | private $serverManager; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @var UrlGenerator |
||
| 205 | */ |
||
| 206 | private $urlGenerator; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @var Storage|null |
||
| 210 | */ |
||
| 211 | private $storage; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var ConfigFileStorage|null |
||
| 215 | */ |
||
| 216 | private $configFileStorage; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @var ConfigFileSerializer|null |
||
| 220 | */ |
||
| 221 | private $configFileSerializer; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @var PackageFileStorage|null |
||
| 225 | */ |
||
| 226 | private $packageFileStorage; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @var PackageFileSerializer|null |
||
| 230 | */ |
||
| 231 | private $packageFileSerializer; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var LoggerInterface |
||
| 235 | */ |
||
| 236 | private $logger; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @var bool |
||
| 240 | */ |
||
| 241 | private $started = false; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @var bool |
||
| 245 | */ |
||
| 246 | private $pluginsEnabled = true; |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Parses the system context for a home directory. |
||
| 250 | * |
||
| 251 | * @return null|string Returns the path to the home directory or `null` |
||
| 252 | * if none was found. |
||
| 253 | */ |
||
| 254 | 48 | private static function parseHomeDirectory() |
|
| 269 | |||
| 270 | /** |
||
| 271 | * Creates a new instance for the given Puli project. |
||
| 272 | * |
||
| 273 | * @param string|null $rootDir The root directory of the Puli project. |
||
| 274 | * If none is passed, the object operates in |
||
| 275 | * the global context. You can set or switch |
||
| 276 | * the root directories later on by calling |
||
| 277 | * {@link setRootDirectory()}. |
||
| 278 | * @param string $env One of the {@link Environment} constants. |
||
| 279 | * |
||
| 280 | * @see Puli, start() |
||
| 281 | */ |
||
| 282 | 50 | public function __construct($rootDir = null, $env = Environment::DEV) |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Starts the service container. |
||
| 290 | */ |
||
| 291 | 48 | public function start() |
|
| 292 | { |
||
| 293 | 48 | if ($this->started) { |
|
| 294 | throw new LogicException('Puli is already started'); |
||
| 295 | } |
||
| 296 | |||
| 297 | 48 | if ($this->rootDir) { |
|
|
|
|||
| 298 | 26 | $this->context = $this->createProjectContext($this->rootDir, $this->env); |
|
| 299 | 1 | $bootstrapFile = $this->context->getConfig()->get(Config::BOOTSTRAP_FILE); |
|
| 300 | |||
| 301 | // Run the project's bootstrap file to enable project-specific |
||
| 302 | // autoloading |
||
| 303 | 1 | if (null !== $bootstrapFile) { |
|
| 304 | // Backup autoload functions of the PHAR |
||
| 305 | $autoloadFunctions = spl_autoload_functions(); |
||
| 306 | |||
| 307 | foreach ($autoloadFunctions as $autoloadFunction) { |
||
| 308 | spl_autoload_unregister($autoloadFunction); |
||
| 309 | } |
||
| 310 | |||
| 311 | // Add project-specific autoload functions |
||
| 312 | require_once Path::makeAbsolute($bootstrapFile, $this->rootDir); |
||
| 313 | |||
| 314 | // Prepend autoload functions of the PHAR again |
||
| 315 | // This is needed if the user specific autoload functions were |
||
| 316 | // added with $prepend=true (as done by Composer) |
||
| 317 | // Classes in the PHAR should always take precedence |
||
| 318 | for ($i = count($autoloadFunctions) - 1; $i >= 0; --$i) { |
||
| 319 | spl_autoload_register($autoloadFunctions[$i], true, true); |
||
| 320 | } |
||
| 321 | } |
||
| 322 | 1 | } else { |
|
| 323 | 22 | $this->context = $this->createGlobalContext(); |
|
| 324 | } |
||
| 325 | |||
| 326 | 2 | $this->dispatcher = $this->context->getEventDispatcher(); |
|
| 327 | 2 | $this->started = true; |
|
| 328 | |||
| 329 | // Start plugins once the container is running |
||
| 330 | 2 | if ($this->rootDir && $this->pluginsEnabled) { |
|
| 331 | 1 | $this->activatePlugins(); |
|
| 332 | 1 | } |
|
| 333 | 2 | } |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Returns whether the service container is started. |
||
| 337 | * |
||
| 338 | * @return bool Returns `true` if the container is started and `false` |
||
| 339 | * otherwise. |
||
| 340 | */ |
||
| 341 | public function isStarted() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Sets the root directory of the managed Puli project. |
||
| 348 | * |
||
| 349 | * @param string|null $rootDir The root directory of the managed Puli |
||
| 350 | * project or `null` to start Puli outside of a |
||
| 351 | * specific project. |
||
| 352 | */ |
||
| 353 | 50 | public function setRootDirectory($rootDir) |
|
| 363 | |||
| 364 | /** |
||
| 365 | * Sets the environment of the managed Puli project. |
||
| 366 | * |
||
| 367 | * @param string $env One of the {@link Environment} constants. |
||
| 368 | */ |
||
| 369 | 50 | public function setEnvironment($env) |
|
| 379 | |||
| 380 | /** |
||
| 381 | * Retturns the environment of the managed Puli project. |
||
| 382 | * |
||
| 383 | * @return string One of the {@link Environment} constants. |
||
| 384 | */ |
||
| 385 | public function getEnvironment() |
||
| 386 | { |
||
| 387 | return $this->env; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Returns the root directory of the managed Puli project. |
||
| 392 | * |
||
| 393 | * If no Puli project is managed at the moment, `null` is returned. |
||
| 394 | * |
||
| 395 | * @return string|null The root directory of the managed Puli project or |
||
| 396 | * `null` if none is set. |
||
| 397 | */ |
||
| 398 | public function getRootDirectory() |
||
| 399 | { |
||
| 400 | return $this->rootDir; |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Sets the logger to use. |
||
| 405 | * |
||
| 406 | * @param LoggerInterface $logger The logger to use. |
||
| 407 | */ |
||
| 408 | public function setLogger(LoggerInterface $logger) |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Returns the used logger. |
||
| 419 | * |
||
| 420 | * @return LoggerInterface The used logger. |
||
| 421 | */ |
||
| 422 | public function getLogger() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Sets the event dispatcher to use. |
||
| 429 | * |
||
| 430 | * @param EventDispatcherInterface $dispatcher The event dispatcher to use. |
||
| 431 | */ |
||
| 432 | 2 | public function setEventDispatcher(EventDispatcherInterface $dispatcher) |
|
| 440 | |||
| 441 | /** |
||
| 442 | * Returns the used event dispatcher. |
||
| 443 | * |
||
| 444 | * @return EventDispatcherInterface|null The used logger. |
||
| 445 | */ |
||
| 446 | public function getEventDispatcher() |
||
| 447 | { |
||
| 448 | return $this->dispatcher; |
||
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Enables all Puli plugins. |
||
| 453 | */ |
||
| 454 | public function enablePlugins() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Disables all Puli plugins. |
||
| 461 | */ |
||
| 462 | 1 | public function disablePlugins() |
|
| 466 | |||
| 467 | /** |
||
| 468 | * Returns whether Puli plugins are enabled. |
||
| 469 | * |
||
| 470 | * @return bool Returns `true` if Puli plugins will be loaded and `false` |
||
| 471 | * otherwise. |
||
| 472 | */ |
||
| 473 | public function arePluginsEnabled() |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Returns the context. |
||
| 480 | * |
||
| 481 | * @return Context|ProjectContext The context. |
||
| 482 | */ |
||
| 483 | 2 | public function getContext() |
|
| 491 | |||
| 492 | /** |
||
| 493 | * Returns the resource repository of the project. |
||
| 494 | * |
||
| 495 | * @return EditableRepository The resource repository. |
||
| 496 | */ |
||
| 497 | View Code Duplication | public function getRepository() |
|
| 498 | { |
||
| 499 | if (!$this->started) { |
||
| 500 | throw new LogicException('Puli was not started'); |
||
| 501 | } |
||
| 502 | |||
| 503 | if (!$this->rootDir) { |
||
| 504 | return null; |
||
| 505 | } |
||
| 506 | |||
| 507 | if (!$this->repo) { |
||
| 508 | $this->repo = $this->getFactory()->createRepository(); |
||
| 509 | } |
||
| 510 | |||
| 511 | return $this->repo; |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Returns the resource discovery of the project. |
||
| 516 | * |
||
| 517 | * @return EditableDiscovery The resource discovery. |
||
| 518 | */ |
||
| 519 | View Code Duplication | public function getDiscovery() |
|
| 520 | { |
||
| 521 | if (!$this->started) { |
||
| 522 | throw new LogicException('Puli was not started'); |
||
| 523 | } |
||
| 524 | |||
| 525 | if (!$this->rootDir) { |
||
| 526 | return null; |
||
| 527 | } |
||
| 528 | |||
| 529 | if (!$this->discovery) { |
||
| 530 | $this->discovery = $this->getFactory()->createDiscovery($this->getRepository()); |
||
| 531 | } |
||
| 532 | |||
| 533 | return $this->discovery; |
||
| 534 | } |
||
| 535 | |||
| 536 | /** |
||
| 537 | * @return object |
||
| 538 | */ |
||
| 539 | public function getFactory() |
||
| 540 | { |
||
| 541 | if (!$this->started) { |
||
| 542 | throw new LogicException('Puli was not started'); |
||
| 543 | } |
||
| 544 | |||
| 545 | if (!$this->factory && $this->rootDir) { |
||
| 546 | $this->factory = $this->getFactoryManager()->createFactory(); |
||
| 547 | } |
||
| 548 | |||
| 549 | return $this->factory; |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @return FactoryManager |
||
| 554 | */ |
||
| 555 | public function getFactoryManager() |
||
| 556 | { |
||
| 557 | if (!$this->started) { |
||
| 558 | throw new LogicException('Puli was not started'); |
||
| 559 | } |
||
| 560 | |||
| 561 | if (!$this->factoryManager && $this->rootDir) { |
||
| 562 | $this->factoryManager = new FactoryManagerImpl( |
||
| 563 | $this->context, |
||
| 564 | new DefaultGeneratorRegistry(), |
||
| 565 | new ClassWriter() |
||
| 566 | ); |
||
| 567 | |||
| 568 | // Don't set via the constructor to prevent a cyclic dependency |
||
| 569 | $this->factoryManager->setServers($this->getServerManager()->getServers()); |
||
| 570 | } |
||
| 571 | |||
| 572 | return $this->factoryManager; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Returns the configuration file manager. |
||
| 577 | * |
||
| 578 | * @return ConfigFileManager The configuration file manager. |
||
| 579 | */ |
||
| 580 | public function getConfigFileManager() |
||
| 581 | { |
||
| 582 | if (!$this->started) { |
||
| 583 | throw new LogicException('Puli was not started'); |
||
| 584 | } |
||
| 585 | |||
| 586 | if (!$this->configFileManager && $this->context->getHomeDirectory()) { |
||
| 587 | $this->configFileManager = new ConfigFileManagerImpl( |
||
| 588 | $this->context, |
||
| 589 | $this->getConfigFileStorage(), |
||
| 590 | $this->getFactoryManager() |
||
| 591 | ); |
||
| 592 | } |
||
| 593 | |||
| 594 | return $this->configFileManager; |
||
| 595 | } |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Returns the root package file manager. |
||
| 599 | * |
||
| 600 | * @return RootPackageFileManager The package file manager. |
||
| 601 | */ |
||
| 602 | View Code Duplication | public function getRootPackageFileManager() |
|
| 603 | { |
||
| 604 | if (!$this->started) { |
||
| 605 | throw new LogicException('Puli was not started'); |
||
| 606 | } |
||
| 607 | |||
| 608 | if (!$this->rootPackageFileManager && $this->rootDir) { |
||
| 609 | $this->rootPackageFileManager = new RootPackageFileManagerImpl( |
||
| 610 | $this->context, |
||
| 611 | $this->getPackageFileStorage() |
||
| 612 | ); |
||
| 613 | } |
||
| 614 | |||
| 615 | return $this->rootPackageFileManager; |
||
| 616 | } |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Returns the package manager. |
||
| 620 | * |
||
| 621 | * @return PackageManager The package manager. |
||
| 622 | */ |
||
| 623 | View Code Duplication | public function getPackageManager() |
|
| 624 | { |
||
| 625 | if (!$this->started) { |
||
| 626 | throw new LogicException('Puli was not started'); |
||
| 627 | } |
||
| 628 | |||
| 629 | if (!$this->packageManager && $this->rootDir) { |
||
| 630 | $this->packageManager = new PackageManagerImpl( |
||
| 631 | $this->context, |
||
| 632 | $this->getPackageFileStorage() |
||
| 633 | ); |
||
| 634 | } |
||
| 635 | |||
| 636 | return $this->packageManager; |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * Returns the resource repository manager. |
||
| 641 | * |
||
| 642 | * @return RepositoryManager The repository manager. |
||
| 643 | */ |
||
| 644 | View Code Duplication | public function getRepositoryManager() |
|
| 645 | { |
||
| 646 | if (!$this->started) { |
||
| 647 | throw new LogicException('Puli was not started'); |
||
| 648 | } |
||
| 649 | |||
| 650 | if (!$this->repositoryManager && $this->rootDir) { |
||
| 651 | $this->repositoryManager = new RepositoryManagerImpl( |
||
| 652 | $this->context, |
||
| 653 | $this->getRepository(), |
||
| 654 | $this->getPackageManager()->findPackages(Expr::method('isEnabled', Expr::same(true))), |
||
| 655 | $this->getPackageFileStorage() |
||
| 656 | ); |
||
| 657 | } |
||
| 658 | |||
| 659 | return $this->repositoryManager; |
||
| 660 | } |
||
| 661 | |||
| 662 | /** |
||
| 663 | * Returns the resource discovery manager. |
||
| 664 | * |
||
| 665 | * @return DiscoveryManager The discovery manager. |
||
| 666 | */ |
||
| 667 | View Code Duplication | public function getDiscoveryManager() |
|
| 668 | { |
||
| 669 | if (!$this->started) { |
||
| 670 | throw new LogicException('Puli was not started'); |
||
| 671 | } |
||
| 672 | |||
| 673 | if (!$this->discoveryManager && $this->rootDir) { |
||
| 674 | $this->discoveryManager = new DiscoveryManagerImpl( |
||
| 675 | $this->context, |
||
| 676 | $this->getDiscovery(), |
||
| 677 | $this->getPackageManager()->findPackages(Expr::method('isEnabled', Expr::same(true))), |
||
| 678 | $this->getPackageFileStorage(), |
||
| 679 | $this->logger |
||
| 680 | ); |
||
| 681 | } |
||
| 682 | |||
| 683 | return $this->discoveryManager; |
||
| 684 | } |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Returns the asset manager. |
||
| 688 | * |
||
| 689 | * @return AssetManager The asset manager. |
||
| 690 | */ |
||
| 691 | public function getAssetManager() |
||
| 692 | { |
||
| 693 | if (!$this->started) { |
||
| 694 | throw new LogicException('Puli was not started'); |
||
| 695 | } |
||
| 696 | |||
| 697 | if (!$this->assetManager && $this->rootDir) { |
||
| 698 | $this->assetManager = new DiscoveryAssetManager( |
||
| 699 | $this->getDiscoveryManager(), |
||
| 700 | $this->getServerManager()->getServers() |
||
| 701 | ); |
||
| 702 | } |
||
| 703 | |||
| 704 | return $this->assetManager; |
||
| 705 | } |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Returns the installation manager. |
||
| 709 | * |
||
| 710 | * @return InstallationManager The installation manager. |
||
| 711 | */ |
||
| 712 | public function getInstallationManager() |
||
| 713 | { |
||
| 714 | if (!$this->started) { |
||
| 715 | throw new LogicException('Puli was not started'); |
||
| 716 | } |
||
| 717 | |||
| 718 | if (!$this->installationManager && $this->rootDir) { |
||
| 719 | $this->installationManager = new InstallationManagerImpl( |
||
| 720 | $this->getContext(), |
||
| 721 | $this->getRepository(), |
||
| 722 | $this->getServerManager()->getServers(), |
||
| 723 | $this->getInstallerManager() |
||
| 724 | ); |
||
| 725 | } |
||
| 726 | |||
| 727 | return $this->installationManager; |
||
| 728 | } |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Returns the installer manager. |
||
| 732 | * |
||
| 733 | * @return InstallerManager The installer manager. |
||
| 734 | */ |
||
| 735 | public function getInstallerManager() |
||
| 736 | { |
||
| 737 | if (!$this->started) { |
||
| 738 | throw new LogicException('Puli was not started'); |
||
| 739 | } |
||
| 740 | |||
| 741 | if (!$this->installerManager && $this->rootDir) { |
||
| 742 | $this->installerManager = new PackageFileInstallerManager( |
||
| 743 | $this->getRootPackageFileManager(), |
||
| 744 | $this->getPackageManager()->getPackages() |
||
| 745 | ); |
||
| 746 | } |
||
| 747 | |||
| 748 | return $this->installerManager; |
||
| 749 | } |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Returns the server manager. |
||
| 753 | * |
||
| 754 | * @return ServerManager The server manager. |
||
| 755 | */ |
||
| 756 | public function getServerManager() |
||
| 757 | { |
||
| 758 | if (!$this->started) { |
||
| 759 | throw new LogicException('Puli was not started'); |
||
| 760 | } |
||
| 761 | |||
| 762 | if (!$this->serverManager && $this->rootDir) { |
||
| 763 | $this->serverManager = new PackageFileServerManager( |
||
| 764 | $this->getRootPackageFileManager(), |
||
| 765 | $this->getInstallerManager() |
||
| 766 | ); |
||
| 767 | } |
||
| 768 | |||
| 769 | return $this->serverManager; |
||
| 770 | } |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Returns the resource URL generator. |
||
| 774 | * |
||
| 775 | * @return UrlGenerator The resource URL generator. |
||
| 776 | */ |
||
| 777 | public function getUrlGenerator() |
||
| 778 | { |
||
| 779 | if (!$this->started) { |
||
| 780 | throw new LogicException('Puli was not started'); |
||
| 781 | } |
||
| 782 | |||
| 783 | if (!$this->urlGenerator && $this->rootDir) { |
||
| 784 | $urlFormats = array(); |
||
| 785 | foreach ($this->getServerManager()->getServers() as $server) { |
||
| 786 | $urlFormats[$server->getName()] = $server->getUrlFormat(); |
||
| 787 | } |
||
| 788 | |||
| 789 | $this->urlGenerator = new DiscoveryUrlGenerator($this->getDiscovery(), $urlFormats); |
||
| 790 | } |
||
| 791 | |||
| 792 | return $this->urlGenerator; |
||
| 793 | } |
||
| 794 | |||
| 795 | /** |
||
| 796 | * Returns the cached file storage. |
||
| 797 | * |
||
| 798 | * @return Storage The storage. |
||
| 799 | */ |
||
| 800 | 46 | public function getStorage() |
|
| 808 | |||
| 809 | /** |
||
| 810 | * Returns the cached configuration file serializer. |
||
| 811 | * |
||
| 812 | * @return ConfigFileSerializer The configuration file serializer. |
||
| 813 | */ |
||
| 814 | 45 | public function getConfigFileSerializer() |
|
| 822 | |||
| 823 | /** |
||
| 824 | * Returns the cached package file serializer. |
||
| 825 | * |
||
| 826 | * @return PackageFileSerializer The package file serializer. |
||
| 827 | */ |
||
| 828 | 1 | public function getPackageFileSerializer() |
|
| 841 | |||
| 842 | 1 | private function activatePlugins() |
|
| 852 | |||
| 853 | 22 | private function createGlobalContext() |
|
| 854 | { |
||
| 855 | 22 | $homeDir = self::parseHomeDirectory(); |
|
| 856 | |||
| 857 | 21 | View Code Duplication | if (null !== $homeDir) { |
| 858 | 20 | Assert::fileExists($homeDir, 'Could not load Puli context: The home directory %s does not exist.'); |
|
| 859 | 20 | Assert::directory($homeDir, 'Could not load Puli context: The home directory %s is a file. Expected a directory.'); |
|
| 860 | |||
| 861 | // Create a storage without the factory manager |
||
| 862 | 20 | $configStorage = new ConfigFileStorage($this->getStorage(), $this->getConfigFileSerializer()); |
|
| 863 | 20 | $configPath = Path::canonicalize($homeDir).'/config.json'; |
|
| 864 | 20 | $configFile = $configStorage->loadConfigFile($configPath, new DefaultConfig()); |
|
| 865 | $baseConfig = $configFile->getConfig(); |
||
| 866 | } else { |
||
| 867 | 1 | $configFile = null; |
|
| 868 | 1 | $baseConfig = new DefaultConfig(); |
|
| 869 | } |
||
| 870 | |||
| 875 | |||
| 876 | /** |
||
| 877 | * Creates the context of a Puli project. |
||
| 878 | * |
||
| 879 | * The home directory is read from the context variable "PULI_HOME". |
||
| 880 | * If this variable is not set, the home directory defaults to: |
||
| 881 | * |
||
| 882 | * * `$HOME/.puli` on Linux, where `$HOME` is the context variable |
||
| 883 | * "HOME". |
||
| 884 | * * `$APPDATA/Puli` on Windows, where `$APPDATA` is the context |
||
| 885 | * variable "APPDATA". |
||
| 886 | * |
||
| 887 | * If none of these variables can be found, an exception is thrown. |
||
| 888 | * |
||
| 889 | * A .htaccess file is put into the home directory to protect it from web |
||
| 890 | * access. |
||
| 891 | * |
||
| 892 | * @param string $rootDir The path to the project. |
||
| 893 | * |
||
| 894 | * @return ProjectContext The project context. |
||
| 895 | */ |
||
| 896 | 26 | private function createProjectContext($rootDir, $env) |
|
| 926 | |||
| 927 | /** |
||
| 928 | * Returns the cached configuration file storage. |
||
| 929 | * |
||
| 930 | * @return ConfigFileStorage The configuration file storage. |
||
| 931 | */ |
||
| 932 | private function getConfigFileStorage() |
||
| 944 | |||
| 945 | /** |
||
| 946 | * Returns the cached package file storage. |
||
| 947 | * |
||
| 948 | * @return PackageFileStorage The package file storage. |
||
| 949 | */ |
||
| 950 | private function getPackageFileStorage() |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Validates the given plugin class name. |
||
| 965 | * |
||
| 966 | * @param string $pluginClass The fully qualified name of a plugin class. |
||
| 967 | */ |
||
| 968 | 1 | private function validatePluginClass($pluginClass) |
|
| 984 | } |
||
| 985 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: