TYPO3 CMS  TYPO3_6-2
PackageFactory.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Package;
3 
4 /* *
5  * This script belongs to the TYPO3 Flow framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
15 
21 
25  protected $packageManager;
26 
33  $this->packageManager = $packageManager;
34  }
35 
47  public function create($packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath = '') {
48  $packagePath = Files::getNormalizedPath(Files::concatenatePaths(array($packagesBasePath, $packagePath)));
49  $packageClassPathAndFilename = Files::concatenatePaths(array($packagePath, 'Classes/' . str_replace('.', '/', $packageKey) . '/Package.php'));
50  $alternativeClassPathAndFilename = Files::concatenatePaths(array($packagePath, 'Classes/Package.php'));
51  $packageClassPathAndFilename = @file_exists($alternativeClassPathAndFilename) ? $alternativeClassPathAndFilename : $packageClassPathAndFilename;
52  if (@file_exists($packageClassPathAndFilename)) {
53  require_once($packageClassPathAndFilename);
54  if (substr($packagePath, 0, strlen(PATH_typo3)) === PATH_typo3 && strpos($packageKey, '.') === FALSE) {
55  //TODO Remove this exception once the systextension are renamed to proper Flow naming scheme packages
56  $packageClassName = 'TYPO3\\CMS\\' . \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($packageKey) . '\Package';
57  } else {
58  $packageClassName = str_replace('.', '\\', $packageKey) . '\Package';
59  }
60  if (!class_exists($packageClassName, FALSE)) {
61  throw new \TYPO3\Flow\Package\Exception\CorruptPackageException(sprintf('The package "%s" does not contain a valid package class. Check if the file "%s" really contains a class called "%s".', $packageKey, $packageClassPathAndFilename, $packageClassName), 1327587092);
62  }
63  } else {
64  $emConfPath = Files::concatenatePaths(array($packagePath, 'ext_emconf.php'));
65  $packageClassName = @file_exists($emConfPath) ? 'TYPO3\CMS\Core\Package\Package' : 'TYPO3\Flow\Package\Package';
66  }
67 
69  $package = new $packageClassName($this->packageManager, $packageKey, $packagePath, $classesPath, $manifestPath);
70 
71  return $package;
72  }
73 
90  public static function getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath) {
91  if (!is_object($manifest)) {
92  throw new \TYPO3\Flow\Package\Exception\InvalidPackageManifestException('Invalid composer manifest in package path: ' . $packagePath, 1348146451);
93  }
94  if (isset($manifest->type) && substr($manifest->type, 0, 10) === 'typo3-cms-') {
95  $relativePackagePath = substr($packagePath, strlen($packagesBasePath));
96  $packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1);
100  $packageKey = preg_replace('/[^A-Za-z0-9._-]/', '', $packageKey);
101  return $packageKey;
102  } else {
103  return parent::getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath);
104  }
105  }
106 
107 }
static getNormalizedPath($path)
Definition: Files.php:41
static getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath)
static concatenatePaths(array $paths)
Definition: Files.php:55
create($packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath='')
__construct(PackageManager $packageManager)