console-helpers /
svn-buddy
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the SVN-Buddy library. |
||
| 4 | * For the full copyright and license information, please view |
||
| 5 | * the LICENSE file that was distributed with this source code. |
||
| 6 | * |
||
| 7 | * @copyright Alexander Obuhovich <[email protected]> |
||
| 8 | * @link https://github.com/console-helpers/svn-buddy |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ConsoleHelpers\SVNBuddy; |
||
| 12 | |||
| 13 | |||
| 14 | use ConsoleHelpers\ConsoleKit\Config\ConfigEditor; |
||
| 15 | use ConsoleHelpers\DatabaseMigration\MigrationManager; |
||
| 16 | use ConsoleHelpers\DatabaseMigration\PhpMigrationRunner; |
||
| 17 | use ConsoleHelpers\DatabaseMigration\SqlMigrationRunner; |
||
| 18 | use ConsoleHelpers\SVNBuddy\Cache\CacheManager; |
||
| 19 | use ConsoleHelpers\SVNBuddy\Command\ChangelogCommand; |
||
| 20 | use ConsoleHelpers\SVNBuddy\Command\CleanupCommand; |
||
| 21 | use ConsoleHelpers\SVNBuddy\Command\CommitCommand; |
||
| 22 | use ConsoleHelpers\SVNBuddy\Command\CompletionCommand; |
||
| 23 | use ConsoleHelpers\SVNBuddy\Command\ConfigCommand; |
||
| 24 | use ConsoleHelpers\SVNBuddy\Command\ConflictsCommand; |
||
| 25 | use ConsoleHelpers\SVNBuddy\Command\DeployCommand; |
||
| 26 | use ConsoleHelpers\SVNBuddy\Command\Dev\MigrationCreateCommand; |
||
| 27 | use ConsoleHelpers\SVNBuddy\Command\Dev\PharCreateCommand; |
||
| 28 | use ConsoleHelpers\SVNBuddy\Command\InfoCommand; |
||
| 29 | use ConsoleHelpers\SVNBuddy\Command\LogCommand; |
||
| 30 | use ConsoleHelpers\SVNBuddy\Command\MergeCommand; |
||
| 31 | use ConsoleHelpers\SVNBuddy\Command\ProjectCommand; |
||
| 32 | use ConsoleHelpers\SVNBuddy\Command\ReparseCommand; |
||
| 33 | use ConsoleHelpers\SVNBuddy\Command\RevertCommand; |
||
| 34 | use ConsoleHelpers\SVNBuddy\Command\SearchCommand; |
||
| 35 | use ConsoleHelpers\SVNBuddy\Command\SelfUpdateCommand; |
||
| 36 | use ConsoleHelpers\SVNBuddy\Command\UpdateCommand; |
||
| 37 | use ConsoleHelpers\SVNBuddy\Config\CommandConfig; |
||
| 38 | use ConsoleHelpers\SVNBuddy\Database\StatementProfiler; |
||
| 39 | use ConsoleHelpers\SVNBuddy\Helper\DateHelper; |
||
| 40 | use ConsoleHelpers\SVNBuddy\Helper\OutputHelper; |
||
| 41 | use ConsoleHelpers\SVNBuddy\Helper\SizeHelper; |
||
| 42 | use ConsoleHelpers\SVNBuddy\MergeSourceDetector\ClassicMergeSourceDetector; |
||
| 43 | use ConsoleHelpers\SVNBuddy\MergeSourceDetector\InPortalMergeSourceDetector; |
||
| 44 | use ConsoleHelpers\SVNBuddy\MergeSourceDetector\MergeSourceDetectorAggregator; |
||
| 45 | use ConsoleHelpers\SVNBuddy\Process\ProcessFactory; |
||
| 46 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\CommitMessageBuilder; |
||
| 47 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\EmptyMergeTemplate; |
||
| 48 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\GroupByBugMergeTemplate; |
||
| 49 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\GroupByRevisionMergeTemplate; |
||
| 50 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\MergeTemplateFactory; |
||
| 51 | use ConsoleHelpers\SVNBuddy\Repository\CommitMessage\SummaryMergeTemplate; |
||
| 52 | use ConsoleHelpers\SVNBuddy\Repository\Connector\CommandFactory; |
||
| 53 | use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
||
| 54 | use ConsoleHelpers\SVNBuddy\Repository\Connector\UrlResolver; |
||
| 55 | use ConsoleHelpers\SVNBuddy\Repository\Parser\LogMessageParserFactory; |
||
| 56 | use ConsoleHelpers\SVNBuddy\Repository\Parser\RevisionListParser; |
||
| 57 | use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\DatabaseManager; |
||
| 58 | use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionLogFactory; |
||
| 59 | use ConsoleHelpers\SVNBuddy\Repository\RevisionLog\RevisionPrinter; |
||
| 60 | use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyConflictTracker; |
||
| 61 | use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyResolver; |
||
| 62 | use ConsoleHelpers\SVNBuddy\Updater\UpdateManager; |
||
| 63 | use ConsoleHelpers\SVNBuddy\Updater\Updater; |
||
| 64 | use ConsoleHelpers\SVNBuddy\Updater\VersionUpdateStrategy; |
||
| 65 | use Symfony\Component\Console\CommandLoader\CommandLoaderInterface; |
||
| 66 | use Symfony\Component\Console\Exception\CommandNotFoundException; |
||
| 67 | use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
||
| 68 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 69 | |||
| 70 | class Container extends \ConsoleHelpers\ConsoleKit\Container implements CommandLoaderInterface |
||
| 71 | { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Command factories. |
||
| 75 | * |
||
| 76 | * @var callable[] |
||
| 77 | */ |
||
| 78 | protected $commandFactories = array(); |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 195 | public function __construct(array $values = array()) |
|
| 84 | { |
||
| 85 | 195 | parent::__construct($values); |
|
| 86 | |||
| 87 | 195 | $this['app_name'] = 'SVN-Buddy'; |
|
| 88 | 195 | $this['app_version'] = '@git-version@'; |
|
| 89 | |||
| 90 | 195 | $this['working_directory_sub_folder'] = '.svn-buddy'; |
|
| 91 | |||
| 92 | 195 | $this['config_defaults'] = array( |
|
| 93 | 195 | 'repository-connector.username' => '', |
|
| 94 | 195 | 'repository-connector.password' => '', |
|
| 95 | 195 | 'repository-connector.last-revision-cache-duration' => '10 minutes', |
|
| 96 | 195 | 'update-channel' => 'stable', |
|
| 97 | 195 | 'theme' => 'dark', |
|
| 98 | 195 | ); |
|
| 99 | |||
| 100 | 195 | $this['dark_theme'] = function ($c) { |
|
| 101 | /** @var ConfigEditor $config_editor */ |
||
| 102 | 1 | $config_editor = $c['config_editor']; |
|
| 103 | |||
| 104 | 1 | return $config_editor->get('theme', $c['config_defaults']['theme']) === 'dark'; |
|
| 105 | 195 | }; |
|
| 106 | |||
| 107 | 195 | $this->extend('output', function ($output) { |
|
| 108 | /** @var OutputInterface $output */ |
||
| 109 | 12 | $output->getFormatter()->setStyle('debug', new OutputFormatterStyle('white', 'magenta')); |
|
| 110 | |||
| 111 | 12 | return $output; |
|
| 112 | 195 | }); |
|
| 113 | |||
| 114 | 195 | $this['process_factory'] = function () { |
|
| 115 | 10 | return new ProcessFactory(); |
|
| 116 | 195 | }; |
|
| 117 | |||
| 118 | 195 | $this['merge_source_detector'] = function () { |
|
| 119 | 1 | $merge_source_detector = new MergeSourceDetectorAggregator(0); |
|
| 120 | 1 | $merge_source_detector->add(new ClassicMergeSourceDetector(0)); |
|
| 121 | 1 | $merge_source_detector->add(new InPortalMergeSourceDetector(50)); |
|
| 122 | |||
| 123 | 1 | return $merge_source_detector; |
|
| 124 | 195 | }; |
|
| 125 | |||
| 126 | 195 | $this['repository_url_resolver'] = function ($c) { |
|
| 127 | 1 | return new UrlResolver($c['repository_connector']); |
|
| 128 | 195 | }; |
|
| 129 | |||
| 130 | 195 | $this['cache_manager'] = function ($c) { |
|
| 131 | 10 | return new CacheManager($c['working_directory'], $c['size_helper'], $c['io']); |
|
| 132 | 195 | }; |
|
| 133 | |||
| 134 | 195 | $this['statement_profiler'] = function () { |
|
| 135 | 20 | $statement_profiler = new StatementProfiler(); |
|
| 136 | |||
| 137 | // The "AbstractPlugin::getLastRevision" method. |
||
| 138 | 20 | $statement_profiler->ignoreDuplicateStatement('SELECT LastRevision FROM PluginData WHERE Name = :name'); |
|
| 139 | |||
| 140 | // The "AbstractPlugin::getProject" method. |
||
| 141 | 20 | $statement_profiler->ignoreDuplicateStatement('SELECT Id FROM Projects WHERE Path = :path'); |
|
| 142 | |||
| 143 | // The "AbstractDatabaseCollectorPlugin::getProjects" method. |
||
| 144 | 20 | $statement_profiler->ignoreDuplicateStatement( |
|
| 145 | 20 | 'SELECT Path, Id AS PathId, RevisionAdded, RevisionDeleted, RevisionLastSeen |
|
| 146 | FROM Paths |
||
| 147 | 20 | WHERE PathHash IN (:path_hashes)' |
|
| 148 | 20 | ); |
|
| 149 | |||
| 150 | // The "ProjectsPlugin::createRepositoryWideProject" method. |
||
| 151 | 20 | $statement_profiler->ignoreDuplicateStatement( |
|
| 152 | 20 | 'SELECT Id FROM Paths WHERE ProjectPath = :project_path LIMIT 100' |
|
| 153 | 20 | ); |
|
| 154 | |||
| 155 | 20 | $statement_profiler->setActive(true); |
|
| 156 | 20 | $statement_profiler->trackDuplicates(false); |
|
| 157 | |||
| 158 | 20 | return $statement_profiler; |
|
| 159 | 195 | }; |
|
| 160 | |||
| 161 | 195 | $this['project_root_folder'] = function () { |
|
| 162 | 165 | return dirname(dirname(__DIR__)); |
|
| 163 | 195 | }; |
|
| 164 | |||
| 165 | 195 | $this['migration_manager'] = function ($c) { |
|
| 166 | 165 | $migrations_directory = $c['project_root_folder'] . '/migrations'; |
|
| 167 | 165 | $migration_manager = new MigrationManager($migrations_directory, $c); |
|
| 168 | 165 | $migration_manager->registerMigrationRunner(new SqlMigrationRunner()); |
|
| 169 | 165 | $migration_manager->registerMigrationRunner(new PhpMigrationRunner()); |
|
| 170 | |||
| 171 | 165 | return $migration_manager; |
|
| 172 | 195 | }; |
|
| 173 | |||
| 174 | 195 | $this['db_manager'] = function ($c) { |
|
| 175 | 2 | return new DatabaseManager($c['working_directory'], $c['migration_manager'], $c['statement_profiler']); |
|
| 176 | 195 | }; |
|
| 177 | |||
| 178 | 195 | $this['revision_log_factory'] = function ($c) { |
|
| 179 | 2 | return new RevisionLogFactory( |
|
| 180 | 2 | $c['repository_connector'], |
|
| 181 | 2 | $c['db_manager'], |
|
| 182 | 2 | $c['log_message_parser_factory'], |
|
| 183 | 2 | $c['working_directory'] |
|
| 184 | 2 | ); |
|
| 185 | 195 | }; |
|
| 186 | |||
| 187 | 195 | $this['log_message_parser_factory'] = function () { |
|
| 188 | 3 | return new LogMessageParserFactory(); |
|
| 189 | 195 | }; |
|
| 190 | |||
| 191 | 195 | $this['revision_list_parser'] = function () { |
|
| 192 | 9 | return new RevisionListParser(); |
|
| 193 | 195 | }; |
|
| 194 | |||
| 195 | 195 | $this['revision_printer'] = function ($c) { |
|
| 196 | 1 | return new RevisionPrinter($c['date_helper'], $c['output_helper'], $c['dark_theme']); |
|
| 197 | 195 | }; |
|
| 198 | |||
| 199 | 195 | $this['command_factory'] = function ($c) { |
|
| 200 | 9 | return new CommandFactory($c['config_editor'], $c['process_factory'], $c['io'], $c['cache_manager']); |
|
| 201 | 195 | }; |
|
| 202 | |||
| 203 | 195 | $this['repository_connector'] = function ($c) { |
|
| 204 | 8 | return new Connector( |
|
| 205 | 8 | $c['config_editor'], |
|
| 206 | 8 | $c['command_factory'], |
|
| 207 | 8 | $c['io'], |
|
| 208 | 8 | $c['revision_list_parser'] |
|
| 209 | 8 | ); |
|
| 210 | 195 | }; |
|
| 211 | |||
| 212 | 195 | $this['commit_message_builder'] = function ($c) { |
|
| 213 | 1 | return new CommitMessageBuilder($c['working_copy_conflict_tracker']); |
|
| 214 | 195 | }; |
|
| 215 | |||
| 216 | 195 | $this['working_copy_resolver'] = function ($c) { |
|
| 217 | 4 | return new WorkingCopyResolver($c['repository_connector']); |
|
| 218 | 195 | }; |
|
| 219 | |||
| 220 | 195 | $this['working_copy_conflict_tracker'] = function ($c) { |
|
| 221 | 2 | return new WorkingCopyConflictTracker($c['repository_connector'], $c['command_config']); |
|
| 222 | 195 | }; |
|
| 223 | |||
| 224 | 195 | $this['merge_template_factory'] = function ($c) { |
|
| 225 | 1 | $factory = new MergeTemplateFactory(); |
|
| 226 | 1 | $repository_connector = $c['repository_connector']; |
|
| 227 | 1 | $revision_log_factory = $c['revision_log_factory']; |
|
| 228 | |||
| 229 | 1 | $factory->add(new GroupByBugMergeTemplate($repository_connector, $revision_log_factory)); |
|
| 230 | 1 | $factory->add(new GroupByRevisionMergeTemplate($repository_connector, $revision_log_factory)); |
|
| 231 | 1 | $factory->add(new SummaryMergeTemplate($repository_connector, $revision_log_factory)); |
|
| 232 | 1 | $factory->add(new EmptyMergeTemplate($repository_connector, $revision_log_factory)); |
|
| 233 | |||
| 234 | 1 | return $factory; |
|
| 235 | 195 | }; |
|
| 236 | |||
| 237 | 195 | $this['command_config'] = function ($c) { |
|
| 238 | 3 | return new CommandConfig($c['config_editor'], $c['working_copy_resolver']); |
|
| 239 | 195 | }; |
|
| 240 | |||
| 241 | 195 | $this['date_helper'] = function () { |
|
| 242 | 2 | return new DateHelper(); |
|
| 243 | 195 | }; |
|
| 244 | |||
| 245 | 195 | $this['size_helper'] = function () { |
|
| 246 | 11 | return new SizeHelper(); |
|
| 247 | 195 | }; |
|
| 248 | |||
| 249 | 195 | $this['output_helper'] = function () { |
|
| 250 | 2 | return new OutputHelper(); |
|
| 251 | 195 | }; |
|
| 252 | |||
| 253 | 195 | $this['editor'] = function () { |
|
| 254 | 1 | return new InteractiveEditor(); |
|
| 255 | 195 | }; |
|
| 256 | |||
| 257 | 195 | $this['updater'] = function ($c) { |
|
| 258 | /** @var ConfigEditor $config_editor */ |
||
| 259 | 1 | $config_editor = $c['config_editor']; |
|
| 260 | |||
| 261 | 1 | $update_strategy = new VersionUpdateStrategy(); |
|
| 262 | 1 | $update_strategy->setStability($config_editor->get('update-channel')); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 263 | 1 | $update_strategy->setCurrentLocalVersion($c['app_version']); |
|
| 264 | |||
| 265 | 1 | $updater = new Updater(null, false); |
|
| 266 | 1 | $updater->setStrategyObject($update_strategy); |
|
| 267 | |||
| 268 | 1 | return $updater; |
|
| 269 | 195 | }; |
|
| 270 | |||
| 271 | 195 | $this['update_manager'] = function ($c) { |
|
| 272 | return new UpdateManager( |
||
| 273 | $c['updater'], |
||
| 274 | $c['config_editor'], |
||
| 275 | $c['process_factory'], |
||
| 276 | $c['working_directory'] |
||
| 277 | ); |
||
| 278 | 195 | }; |
|
| 279 | |||
| 280 | 195 | $this->addCommandFactories(); |
|
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Adds command factories. |
||
| 285 | * |
||
| 286 | * @return void |
||
| 287 | */ |
||
| 288 | 195 | protected function addCommandFactories() |
|
| 289 | { |
||
| 290 | 195 | $this->commandFactories['merge'] = function () { |
|
| 291 | return new MergeCommand(); |
||
| 292 | 195 | }; |
|
| 293 | 195 | $this->commandFactories['cleanup'] = function () { |
|
| 294 | return new CleanupCommand(); |
||
| 295 | 195 | }; |
|
| 296 | 195 | $this->commandFactories['revert'] = function () { |
|
| 297 | return new RevertCommand(); |
||
| 298 | 195 | }; |
|
| 299 | 195 | $this->commandFactories['reparse'] = function () { |
|
| 300 | return new ReparseCommand(); |
||
| 301 | 195 | }; |
|
| 302 | 195 | $this->commandFactories['log'] = function () { |
|
| 303 | return new LogCommand(); |
||
| 304 | 195 | }; |
|
| 305 | 195 | $this->commandFactories['update'] = function () { |
|
| 306 | return new UpdateCommand(); |
||
| 307 | 195 | }; |
|
| 308 | 195 | $this->commandFactories['up'] = function () { |
|
| 309 | return new UpdateCommand(); |
||
| 310 | 195 | }; |
|
| 311 | 195 | $this->commandFactories['commit'] = function () { |
|
| 312 | return new CommitCommand(); |
||
| 313 | 195 | }; |
|
| 314 | 195 | $this->commandFactories['ci'] = function () { |
|
| 315 | return new CommitCommand(); |
||
| 316 | 195 | }; |
|
| 317 | 195 | $this->commandFactories['conflicts'] = function () { |
|
| 318 | return new ConflictsCommand(); |
||
| 319 | 195 | }; |
|
| 320 | 195 | $this->commandFactories['cf'] = function () { |
|
| 321 | return new ConflictsCommand(); |
||
| 322 | 195 | }; |
|
| 323 | 195 | $this->commandFactories['config'] = function () { |
|
| 324 | return new ConfigCommand(); |
||
| 325 | 195 | }; |
|
| 326 | 195 | $this->commandFactories['cfg'] = function () { |
|
| 327 | return new ConfigCommand(); |
||
| 328 | 195 | }; |
|
| 329 | 195 | $this->commandFactories['project'] = function () { |
|
| 330 | return new ProjectCommand(); |
||
| 331 | 195 | }; |
|
| 332 | 195 | $this->commandFactories['info'] = function () { |
|
| 333 | return new InfoCommand(); |
||
| 334 | 195 | }; |
|
| 335 | 195 | $this->commandFactories['_completion'] = function () { |
|
| 336 | return new CompletionCommand(); |
||
| 337 | 195 | }; |
|
| 338 | 195 | $this->commandFactories['search'] = function () { |
|
| 339 | return new SearchCommand(); |
||
| 340 | 195 | }; |
|
| 341 | 195 | $this->commandFactories['self-update'] = function () { |
|
| 342 | return new SelfUpdateCommand(); |
||
| 343 | 195 | }; |
|
| 344 | 195 | $this->commandFactories['changelog'] = function () { |
|
| 345 | return new ChangelogCommand(); |
||
| 346 | 195 | }; |
|
| 347 | 195 | $this->commandFactories['deploy'] = function () { |
|
| 348 | return new DeployCommand(); |
||
| 349 | 195 | }; |
|
| 350 | |||
| 351 | 195 | if ( strpos(__DIR__, 'phar://') === false ) { |
|
| 352 | 195 | $this->commandFactories['dev:migration-create'] = function () { |
|
| 353 | return new MigrationCreateCommand(); |
||
| 354 | 195 | }; |
|
| 355 | 195 | $this->commandFactories['dev:phar-create'] = function () { |
|
| 356 | return new PharCreateCommand(); |
||
| 357 | 195 | }; |
|
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * {@inheritdoc} |
||
| 363 | */ |
||
| 364 | public function has($name) |
||
| 365 | { |
||
| 366 | return isset($this->commandFactories[$name]); |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * {@inheritdoc} |
||
| 371 | * |
||
| 372 | * @throws CommandNotFoundException When command wasn't found. |
||
| 373 | */ |
||
| 374 | public function get($name) |
||
| 375 | { |
||
| 376 | if ( !isset($this->commandFactories[$name]) ) { |
||
| 377 | throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); |
||
| 378 | } |
||
| 379 | |||
| 380 | $factory = $this->commandFactories[$name]; |
||
| 381 | |||
| 382 | return $factory(); |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * {@inheritdoc} |
||
| 387 | */ |
||
| 388 | public function getNames() |
||
| 389 | { |
||
| 390 | return array_keys($this->commandFactories); |
||
| 391 | } |
||
| 392 | |||
| 393 | } |
||
| 394 |