<?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
<?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 {
<?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[1;31m!!! ERROR !!![0m Entity [1;33m{$entityName}[0m does not exist.\nHalting.\n\n"; exit(1); } elseif (count($matches) == 1) { list($entityName) = $matches; } else { echo "\n[1;31m!!! ERROR !!![0m Given entity name [1;33m{$entityName}[0m is ambiguous.\n"; $entities = $matches; $entityName = NULL; }