Ejemplo n.º 1
0
 /**
  * Prints the licenses of a package with metadata
  *
  * @param CompletePackageInterface $package
  */
 protected function printLicenses(CompletePackageInterface $package)
 {
     $spdxLicense = new SpdxLicense();
     $licenses = $package->getLicense();
     foreach ($licenses as $licenseId) {
         $license = $spdxLicense->getLicenseByIdentifier($licenseId);
         // keys: 0 fullname, 1 osi, 2 url
         if (!$license) {
             $out = $licenseId;
         } else {
             // is license OSI approved?
             if ($license[1] === true) {
                 $out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]);
             } else {
                 $out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]);
             }
         }
         $this->getIO()->write('<info>license</info>  : ' . $out);
     }
 }
Ejemplo n.º 2
0
 public static function createProject(Event $event)
 {
     $io = $event->getIO();
     $json = new JsonFile('./composer.json');
     $config = $json->read();
     $name = self::determineProjectName();
     $io->write('<info>Updating project properties...</info>');
     // update composer project name
     $name = $io->askAndValidate(self::formatQuestion('Composer project name', $name), function ($val) {
         $val = trim($val);
         if (strlen($val) < 3 || substr_count($val, '/') !== 1) {
             throw new RuntimeException("Correct project names follow the 'company/project' structure");
         }
         return $val;
     }, null, $name);
     $config['name'] = $name;
     // composer project description
     $config['description'] = $io->askAndValidate(self::formatQuestion('Description of the project', ''), function ($val) {
         if (strlen(trim($val)) < 1) {
             throw new RuntimeException('Description may not be empty');
         }
         return trim($val);
     }, null, '');
     // composer project license
     $licenseValidator = new SpdxLicense();
     $oldLicense = $config['license'];
     $config['license'] = $io->askAndValidate(self::formatQuestion('Project license', $config['license']), function ($val) use($licenseValidator) {
         $val = trim($val);
         if (strlen($val) < 1 || $val !== 'proprietary' && !$licenseValidator->validate($val)) {
             throw new RuntimeException("Please provide a license, either use 'proprietary' or one from http://www.spdx.org/licenses/");
         }
         return $val;
     }, null, $config['license']);
     unset($config['scripts']['post-root-package-install']);
     unlink('./src/ScriptHandler.php');
     // save config
     $io->write('<info>Updating composer.json</info>');
     $json->write($config);
     // remove license file if the license has changed
     if ($config['license'] !== $oldLicense && is_file('LICENSE')) {
         $io->write('<info>Found a LICENSE file, but you have changed the license.</info>');
         if ($io->askConfirmation('<question>Remove LICENSE file?</question>', false)) {
             $io->write('<info>Removing LICENSE file</info>');
             unlink('LICENSE');
         } else {
             $io->write('<info>Please check if the LICENSE file is still up to date</info>');
         }
     }
     // update parameters.yml.dist
     if (isset($config['extra']['incenteev-parameters']['file'])) {
         $dist = $config['extra']['incenteev-parameters']['file'] . '.dist';
         if (file_exists($dist)) {
             $database_name = self::determineDatabaseName();
             $secret = hash('sha1', uniqid(time(), true));
             $from = ['__secret__', '__database_name__'];
             $to = [$secret, $database_name];
             $io->write('<info>Updating parameters dist file</info>');
             file_put_contents($dist, str_replace($from, $to, file_get_contents($dist)));
         }
     }
     // update services.yml
     $sitename = self::determineProjectTitle();
     $sitename = $io->ask(self::formatQuestion('Sitename', $sitename), $sitename);
     $io->write('<info>Updating app/config/services.yml</info>');
     $services = 'app/config/services.yml';
     file_put_contents($services, str_replace('__sitename__', $sitename, file_get_contents($services)));
     $name = explode('/', $name);
     $name = count($name) > 1 ? $name[1] : $name[0];
     // update package.json
     $json = new JsonFile('./package.json');
     $config = $json->read();
     $config['name'] = $name;
     $io->write('<info>Updating package.json</info>');
     $json->write($config);
     // update bower.json
     $json = new JsonFile('./bower.json');
     $config = $json->read();
     $config['name'] = $name;
     $io->write('<info>Updating bower.json</info>');
     $json->write($config);
 }
Ejemplo n.º 3
0
 /**
  * Validates the config, and returns the result.
  *
  * @param string  $file                       The path to the file
  * @param integer $arrayLoaderValidationFlags Flags for ArrayLoader validation
  *
  * @return array a triple containing the errors, publishable errors, and warnings
  */
 public function validate($file, $arrayLoaderValidationFlags = ValidatingArrayLoader::CHECK_ALL)
 {
     $errors = array();
     $publishErrors = array();
     $warnings = array();
     // validate json schema
     $laxValid = false;
     try {
         $json = new JsonFile($file, new RemoteFilesystem($this->io));
         $manifest = $json->read();
         $json->validateSchema(JsonFile::LAX_SCHEMA);
         $laxValid = true;
         $json->validateSchema();
     } catch (JsonValidationException $e) {
         foreach ($e->getErrors() as $message) {
             if ($laxValid) {
                 $publishErrors[] = $message;
             } else {
                 $errors[] = $message;
             }
         }
     } catch (\Exception $e) {
         $errors[] = $e->getMessage();
         return array($errors, $publishErrors, $warnings);
     }
     // validate actual data
     if (!empty($manifest['license'])) {
         // strip proprietary since it's not a valid SPDX identifier, but is accepted by composer
         if (is_array($manifest['license'])) {
             foreach ($manifest['license'] as $key => $license) {
                 if ('proprietary' === $license) {
                     unset($manifest['license'][$key]);
                 }
             }
         }
         $licenseValidator = new SpdxLicense();
         if ('proprietary' !== $manifest['license'] && array() !== $manifest['license'] && !$licenseValidator->validate($manifest['license'])) {
             $warnings[] = sprintf('License %s is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if you use an open license.' . "\nIf the software is closed-source, you may use \"proprietary\" as license.", json_encode($manifest['license']));
         }
     } else {
         $warnings[] = 'No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.';
     }
     if (isset($manifest['version'])) {
         $warnings[] = 'The version field is present, it is recommended to leave it out if the package is published on Packagist.';
     }
     if (!empty($manifest['name']) && preg_match('{[A-Z]}', $manifest['name'])) {
         $suggestName = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $manifest['name']);
         $suggestName = strtolower($suggestName);
         $warnings[] = sprintf('Name "%s" does not match the best practice (e.g. lower-cased/with-dashes). We suggest using "%s" instead. As such you will not be able to submit it to Packagist.', $manifest['name'], $suggestName);
     }
     if (!empty($manifest['type']) && $manifest['type'] == 'composer-installer') {
         $warnings[] = "The package type 'composer-installer' is deprecated. Please distribute your custom installers as plugins from now on. See http://getcomposer.org/doc/articles/plugins.md for plugin documentation.";
     }
     // check for require-dev overrides
     if (isset($manifest['require']) && isset($manifest['require-dev'])) {
         $requireOverrides = array_intersect_key($manifest['require'], $manifest['require-dev']);
         if (!empty($requireOverrides)) {
             $plural = count($requireOverrides) > 1 ? 'are' : 'is';
             $warnings[] = implode(', ', array_keys($requireOverrides)) . " {$plural} required both in require and require-dev, this can lead to unexpected behavior";
         }
     }
     try {
         $loader = new ValidatingArrayLoader(new ArrayLoader(), true, null, $arrayLoaderValidationFlags);
         if (!isset($manifest['version'])) {
             $manifest['version'] = '1.0.0';
         }
         if (!isset($manifest['name'])) {
             $manifest['name'] = 'dummy/dummy';
         }
         $loader->load($manifest);
     } catch (InvalidPackageException $e) {
         $errors = array_merge($errors, $e->getErrors());
     }
     $warnings = array_merge($warnings, $loader->getWarnings());
     return array($errors, $publishErrors, $warnings);
 }