/** * Get the plural name for a class. */ public static function plural_name($name) { if (isset($name::$plural_name)) { return $name::$plural_name; } if (strpos($name, '\\') !== false) { $name = substr($name, strrpos($name, '\\') + 1); } $ar = new ActiveResource(); return $ar->pluralize($name); }
Cli::block($usage); die; } $types = array('checkbox', 'date', 'datetime', 'email', 'password', 'pkey', 'radio', 'select', 'text', 'textarea', 'time', 'wysiwyg'); if ($_SERVER['argv'][2] === 'list-types') { Cli::out(' - ' . join("\n - ", $types), 'info'); die; } if (!isset($_SERVER['argv'][3])) { Cli::block($usage); die; } $name = strtolower($_SERVER['argv'][2]); // get plural name $ar = new ActiveResource(); $plural = $ar->pluralize($name); unset($ar); if (file_exists('apps/' . $plural)) { Cli::out('apps/' . $plural . ' already exists. Please choose a different name for your new app.', 'info'); die; } // build list of fields $fields = array(); $pkey = false; for ($i = 3; $i < count($_SERVER['argv']); $i++) { // match name:type if (preg_match('/^([a-zA-Z0-9_]+):(' . join('|', $types) . ')$/', $_SERVER['argv'][$i], $regs)) { $fields[] = (object) array('name' => $regs[1], 'type' => $regs[2]); if ($regs[2] === 'pkey') { $pkey = $regs[1]; }