示例#1
0
<?php

use vBuilder\Utils\CliArgsParser, vBuilder\Utils\FileSystem;
// -----------------------------------------------------------------------------
// INIT
// -----------------------------------------------------------------------------
$container = (require __DIR__ . '/bootstrap.php');
$tm = $container->getByType('vBuilder\\Database\\TableManager');
$db = $container->getByType('DibiConnection');
$workPath = realpath(getcwd());
// -----------------------------------------------------------------------------
// ARGUMENTS
// -----------------------------------------------------------------------------
$args = new CliArgsParser();
$args->addSwitch('data', 'Dump data')->addSwitch('help', 'Help');
if (!$args->parse() || $args->get('help')) {
    if ($args->get('help')) {
        echo "\n";
    } else {
        echo "\n" . $args->getErrorMsg() . "\n\n";
    }
    $args->printUsage();
    echo "\n";
    exit;
}
// -----------------------------------------------------------------------------
// ROUTINES
// -----------------------------------------------------------------------------
/**
 * @param DibiConnection
 * @param string table name
示例#2
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 {
示例#3
0
<?php

use vBuilder\Utils\Classinfo as ClassInfo, vBuilder\Utils\CliArgsParser, vBuilder\Utils\Strings, vBuilder\Orm\DdlHelper;
const ENTITY_CLASS = 'vBuilder\\Orm\\Entity';
$container = (require __DIR__ . '/bootstrap.php');
$db = $container->getByType('DibiConnection');
$args = new CliArgsParser();
$args->setNumRequiredArgs(1, 1);
$args->setArgumentHelp('entity name');
$entities = $container->classInfo->getAllChildrenOf(ENTITY_CLASS);
// -----------------------------------------------------------------------------
if ($args->parse()) {
    list($entityName) = $args->getArguments();
    // PHP >= 5.0.3
    if (!class_exists($entityName) || !is_subclass_of($entityName, ENTITY_CLASS)) {
        $matches = array();
        foreach ($entities as $curr) {
            if (Strings::endsWith($curr, '\\' . $entityName)) {
                $matches[] = $curr;
            }
        }
        if (count($matches) == 0) {
            echo "\n!!! ERROR !!! Entity {$entityName} does not exist.\nHalting.\n\n";
            exit(1);
        } elseif (count($matches) == 1) {
            list($entityName) = $matches;
        } else {
            echo "\n!!! ERROR !!! Given entity name {$entityName} is ambiguous.\n";
            $entities = $matches;
            $entityName = NULL;
        }