'', 'pattern' => '', 'lines' => 20, 'columns' => 200, ]; parent::__construct($configuration, $plugin_id, $plugin_definition); $this->appRoot = $app_root; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('app.root') ); } /** * {@inheritdoc} */ public function detectVersion(VersionedLibraryInterface $library) { if (!($library instanceof LocalLibraryInterface)) { throw new UnknownLibraryVersionException($library); } $filepath = $this->appRoot . '/' . $library->getLocalPath() . '/' . $this->configuration['file']; if (!file_exists($filepath)) { throw new UnknownLibraryVersionException($library); } $file = fopen($filepath, 'r'); $lines = $this->configuration['lines']; while ($lines && $line = fgets($file, $this->configuration['columns'])) { if (preg_match($this->configuration['pattern'], $line, $version)) { fclose($file); $library->setVersion($version[1]); return; } $lines--; } fclose($file); } }