TYPO3 CMS  TYPO3_6-2
PackageFactory.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\Flow\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 
20 
24  protected $packageManager;
25 
32  $this->packageManager = $packageManager;
33  }
34 
46  public function create($packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath = '') {
47  $packageClassPathAndFilename = Files::concatenatePaths(array($packagesBasePath, $packagePath, 'Classes/' . str_replace('.', '/', $packageKey) . '/Package.php'));
48  if (file_exists($packageClassPathAndFilename)) {
49  require_once($packageClassPathAndFilename);
54  $packageClassName = str_replace('.', '\\', $packageKey) . '\Package';
55  if (!class_exists($packageClassName)) {
56  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), 1327587091);
57  }
58  } else {
59  $packageClassName = 'TYPO3\Flow\Package\Package';
60  }
61  $packagePath = Files::concatenatePaths(array($packagesBasePath, $packagePath)) . '/';
62 
63  $package = new $packageClassName($this->packageManager, $packageKey, $packagePath, $classesPath, $manifestPath);
64 
65  return $package;
66  }
67 
82  public static function getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath) {
83  if (!is_object($manifest)) {
84  throw new \TYPO3\Flow\Package\Exception\InvalidPackageManifestException('Invalid composer manifest.', 1348146450);
85  }
86  if (isset($manifest->type) && substr($manifest->type, 0, 11) === 'typo3-flow-') {
87  $relativePackagePath = substr($packagePath, strlen($packagesBasePath));
88  $packageKey = substr($relativePackagePath, strpos($relativePackagePath, '/') + 1, -1);
92  } else {
93  $packageKey = str_replace('/', '.', $manifest->name);
94  if (isset($manifest->autoload) && isset($manifest->autoload->{"psr-0"})) {
95  $namespaces = array_keys(get_object_vars($manifest->autoload->{"psr-0"}));
96  foreach ($namespaces as $namespace) {
97  $namespaceLead = substr($namespace, 0, strlen($manifest->name));
98  $dottedNamespaceLead = str_replace('\\', '.', $namespaceLead);
99  if (strtolower($dottedNamespaceLead) === $packageKey) {
100  $packageKey = $dottedNamespaceLead;
101  }
102  }
103  }
104  }
105  $packageKey = preg_replace('/[^A-Za-z0-9.]/', '', $packageKey);
106  return $packageKey;
107  }
108 }
109 ?>
__construct(PackageManagerInterface $packageManager)
static concatenatePaths(array $paths)
Definition: Files.php:55
create($packagesBasePath, $packagePath, $packageKey, $classesPath, $manifestPath='')
static getPackageKeyFromManifest($manifest, $packagePath, $packagesBasePath)