Exemple #1
0
<?php

// TODO: Parametricke zadani vstupnich dat
// TODO: Podpora pro uziv. role
use vBuilder\Security\User, vBuilder\Utils\CliArgsParser, vBuilder\Utils\Strings, vBuilder\Security\IdentityFactory;
$container = (require __DIR__ . '/bootstrap.php');
// -----------------------------------------------------------------------------
// ARGUMENTS
// -----------------------------------------------------------------------------
$args = new CliArgsParser();
$args->addOption('password', 'secret', 'user password', NULL)->setNumRequiredArgs(1, 1)->setArgumentHelp('username');
if (!$args->parse()) {
    echo "\n" . $args->getErrorMsg() . "\n\n";
    $args->printUsage();
    echo "\n";
    exit;
}
list($user) = $args->getArguments();
$password = $args->get('password') !== FALSE ? $args->get('password') : Strings::randomHumanToken();
// -----------------------------------------------------------------------------
// INIT
// -----------------------------------------------------------------------------
$db = $container->getByType('DibiConnection');
$authn = $container->user->getAuthenticator(User::AUTHN_METHOD_PASSWORD, User::AUTHN_SOURCE_DATABASE);
$rolesTable = $authn->identityFactory->getTableName(IdentityFactory::TABLE_ROLES);
$roles = array('Administrator');
// -----------------------------------------------------------------------------
// DB
// -----------------------------------------------------------------------------
$data = array($authn->getColumn($authn::USERNAME) => $user, $authn->getColumn($authn::PASSWORD) => $authn->getPasswordHasher()->hashPassword($password));
try {
        } else {
            echo "\n!!! ERROR !!! Given entity name {$entityName} is ambiguous.\n";
            $entities = $matches;
            $entityName = NULL;
        }
    }
    if (isset($entityName)) {
        echo "\n";
        echo "Entity: {$entityName}\n";
        echo "\nCreate syntax:\n";
        echo DdlHelper::createQuery($entityName::getMetadata());
        $alter = DdlHelper::alterQuery($entityName::getMetadata(), $db);
        if ($alter) {
            echo "\n\nAlter syntax:\n";
            echo $alter;
        }
        echo "\n";
        exit(0);
    }
}
// -----------------------------------------------------------------------------
if ($args->getErrorMsg() !== FALSE) {
    echo "\n";
    $args->printUsage();
}
echo "\n";
echo "List of project entities:\n";
foreach ($entities as $curr) {
    echo "\t- " . str_replace('\\', '\\\\', $curr) . "\n";
}
echo "\n";