Вход Регистрация
Файл: symfony-2.7/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php
Строк: 124
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyBundleSecurityBundleCommand;

use 
SymfonyBundleFrameworkBundleCommandContainerAwareCommand;
use 
SymfonyComponentConsoleInputInputInterface;
use 
SymfonyComponentConsoleOutputOutputInterface;
use 
DoctrineDBALSchemaSchemaException;

/**
 * Installs the tables required by the ACL system.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class InitAclCommand extends ContainerAwareCommand
{
    
/**
     * {@inheritdoc}
     */
    
protected function configure()
    {
        
$this
            
->setName('init:acl')
            ->
setDescription('Mounts ACL tables in the database')
            ->
setHelp(<<<EOF
The <info>%command.name%</info> command mounts ACL tables in the database.

  <info>php %command.full_name%</info>

The name of the DBAL connection must be configured in your <info>app/config/security.yml</info> configuration file in the <info>security.acl.connection</info> variable.

  <info>security:
      acl:
          connection: default</info>
EOF
            )
        ;
    }

    
/**
     * {@inheritdoc}
     */
    
protected function execute(InputInterface $inputOutputInterface $output)
    {
        
$container $this->getContainer();

        
$connection $container->get('security.acl.dbal.connection');
        
$schema $container->get('security.acl.dbal.schema');

        try {
            
$schema->addToSchema($connection->getSchemaManager()->createSchema());
        } catch (
SchemaException $e) {
            
$output->writeln('Aborting: '.$e->getMessage());

            return 
1;
        }

        foreach (
$schema->toSql($connection->getDatabasePlatform()) as $sql) {
            
$connection->exec($sql);
        }

        
$output->writeln('ACL tables have been initialized successfully.');
    }
}
Онлайн: 1
Реклама