Пример #1
0
$connector = null;
if ($options->bootstrap) {
    require $options->bootstrap;
}
if (!$mapper) {
    if (!$options->mapperClass) {
        $options->mapperClass = 'Amiss\\Mapper\\Note';
    }
    $mapper = new $options->mapperClass();
}
if (!$mapper) {
    echo "Please pass the --mapper parameter or define a mapper in a bootstrap file\n\n" . $usage;
    exit(1);
}
if (!$connector) {
    $connector = new \PDOK\Connector($options->dsn, $options->user, $options->password);
}
if ($connector->engine != 'sqlite') {
    if (!$options->db) {
        echo "DB not specified\n\n";
        echo $usage;
        exit(1);
    }
    $connector->execute("CREATE DATABASE IF NOT EXISTS " . $connector->quoteIdentifier($options->db));
    $connector->execute("USE " . $connector->quoteIdentifier($options->db));
}
$toCreate = find_classes($options->input);
if ($options->namespaces) {
    $toCreate = filter_classes_by_namespaces($toCreate, $options->namespaces);
}
if ($options->notes) {
Пример #2
0
if ($options->wfile) {
    $options->words = array_merge($options->words, explode("\n", trim(file_get_contents($options->wfile))));
}
$sep = '_';
$wtmp = $options->words;
$options->words = array();
foreach ($wtmp as $w) {
    $w = trim($w);
    if ($w) {
        $w = strtolower($w);
        $v = $w . $sep;
        $options->words[$w] = $v;
    }
}
$options->words = array_unique($options->words);
$connector = new \PDOK\Connector($options->dsn, $options->user, $options->password);
$stmt = $connector->query("SHOW TABLES");
while ($table = $stmt->fetchColumn()) {
    $oname = strtr($table, $options->words);
    $oname = preg_replace('/\\d+/', '$0' . $sep, $oname);
    $oname = ucfirst(preg_replace_callback('/' . preg_quote($sep, '/') . '(.)/', function ($match) {
        return strtoupper($match[1]);
    }, rtrim($oname, $sep)));
    $tableFields = $connector->query("SHOW FULL FIELDS FROM {$table}")->fetchAll(\PDO::FETCH_ASSOC);
    $fields = array();
    $primary = array();
    foreach ($tableFields as $field) {
        $prop = lcfirst(preg_replace_callback('/_(.)/', function ($match) {
            return strtoupper($match[1]);
        }, $field['Field']));
        $fields[$prop] = array('name' => $field['Field'], 'type' => $field['Type'], 'default' => $field['Default']);