/** * Main function * * @param array $argv argument list * @return mixed */ public function main(array $argv) { $parser = $this->getParser(); $parser->process($argv); if ($parser->optionIsSet("help")) { $this->out($parser->helpText()); return 0; } $output = [['Route name', 'URI template', 'Defaults']]; foreach (Router::getInstance()->routes() as $route) { $name = $route->name(); if (\CoreTyson\isEmpty($name)) { $name = "Unnamed"; } $output[] = [$name, $route->template, json_encode($route->defaults)]; } $this->helper('Table')->output($output); $this->out(); }
/** * Return the class name namespaced. This method checks if the class is defined on the * application/plugin, otherwise try to load from the CoreTyson core * * @param string $class Class name * @param string $type Type of class * @param string $suffix Class name suffix * @return bool|string False if the class is not found or namespaced class name */ public static function className($class, $type = '', $suffix = '') { if (class_exists($class, true)) { return $class; } list($plugin, $class) = \CoreTyson\pluginSplit($class); $base = $plugin ?: Configuration::getInstance()->get('App/namespace', 'App'); $base = str_replace('/', '\\', rtrim($base, '\\')); if (!\CoreTyson\isEmpty($type)) { $class = $type . '/' . $class; } $fullname = '\\' . str_replace('/', '\\', $class) . $suffix; if (static::_classExistsInBase($fullname, $base)) { return $base . $fullname; } if ($plugin) { return false; } if (static::_classExistsInBase($fullname, 'CoreTyson')) { return 'CoreTyson' . $fullname; } return false; }
/** * Remove helper method * * @param array $array * @param array $path * @return array */ private function _remove($array, $path) { $key = array_shift($path); if (is_numeric($key)) { $key = intval($key); } if (\CoreTyson\isEmpty($path)) { if (isset($array[$key])) { unset($array[$key]); } } elseif (isset($array[$key]) and is_array($array[$key])) { $result = $this->_remove($array[$key], $path); $array[$key] = $result; } return $array; }
/** * Get a table instance from the registry. * * Tables are only created once until the registry is flushed. * This means that aliases must be unique across your application. * This is important because table associations are resolved at runtime * and cyclic references need to be handled correctly. * * The options that can be passed are the same as in Cake\ORM\Table::__construct(), but the * `className` key is also recognized. * * ### Options * * - `className` Define the specific class name to use. If undefined, CakePHP will generate the * class name based on the alias. For example 'Users' would result in * `App\Model\Table\UsersTable` being used. If this class does not exist, * then the default `Cake\ORM\Table` class will be used. By setting the `className` * option you can define the specific class to use. The className option supports * plugin short class references {@link Cake\Core\App::shortName()}. * - `table` Define the table name to use. If undefined, this option will default to the underscored * version of the alias name. * - `connection` Inject the specific connection object to use. If this option and `connectionName` are undefined, * The table class' `defaultConnectionName()` method will be invoked to fetch the connection name. * - `connectionName` Define the connection name to use. The named connection will be fetched from * Cake\Datasource\ConnectionManager. * * *Note* If your `$alias` uses plugin syntax only the name part will be used as * key in the registry. This means that if two plugins, or a plugin and app provide * the same alias, the registry will only store the first instance. * * @param string $alias The alias name you want to get. * @param array $options The options you want to build the table with. * If a table has already been loaded the options will be ignored. * @return \Cake\ORM\Table * @throws \RuntimeException When you try to configure an alias that already exists. */ public function get($alias, array $options = []) { if (isset($this->_instances[$alias])) { if (!empty($options) && $this->_options[$alias] !== $options) { throw new RuntimeException(sprintf('You cannot configure "%s", it already exists in the registry.', $alias)); } return $this->_instances[$alias]; } $this->_options[$alias] = $options; list(, $classAlias) = pluginSplit($alias); $options = ['alias' => $classAlias] + $options; if (isset($this->_config[$alias])) { $options += $this->_config[$alias]; } if (empty($options['className'])) { $options['className'] = Inflector::camelize($alias); } $className = $this->_getClassName($alias, $options); if ($className) { $options['className'] = $className; } else { if (!isset($options['table']) && strpos($options['className'], '\\') === false) { list(, $table) = pluginSplit($options['className']); $options['table'] = Inflector::underscore($table); } $options['className'] = 'CoreTyson\\ORM\\Table'; } if (empty($options['connection'])) { if (!empty($options['connectionName'])) { $connectionName = $options['connectionName']; } else { $connectionName = $options['className']::defaultConnectionName(); } if (\CoreTyson\isEmpty(ConnectionManager::config($connectionName))) { ConnectionManager::config($connectionName, $this->_configAdapter(Configuration::getInstance()->get("Database/Connection/" . $connectionName, []))); } $options['connection'] = ConnectionManager::get($connectionName); } $options['registryAlias'] = $alias; $this->_instances[$alias] = $this->_create($options); if ($options['className'] === 'CoreTyson\\ORM\\Table') { $this->_fallbacked[$alias] = $this->_instances[$alias]; } return $this->_instances[$alias]; }
/** * @param mixed $name * @return Route */ public function name($name = "") { if (\CoreTyson\isEmpty($name)) { return $this->_name; } $this->_name = $name; }
/** * Returns an instance with the provided URI. * * This method MUST update the Host header of the returned request by * default if the URI contains a host component. If the URI does not * contain a host component, any pre-existing Host header MUST be carried * over to the returned request. * * You can opt-in to preserving the original state of the Host header by * setting `$preserveHost` to `true`. When `$preserveHost` is set to * `true`, this method interacts with the Host header in the following ways: * * - If the the Host header is missing or empty, and the new URI contains * a host component, this method MUST update the Host header in the returned * request. * - If the Host header is missing or empty, and the new URI does not contain a * host component, this method MUST NOT update the Host header in the returned * request. * - If a Host header is present and non-empty, this method MUST NOT update * the Host header in the returned request. * * This method MUST be implemented in such a way as to retain the * immutability of the message, and MUST return an instance that has the * new UriInterface instance. * * @link http://tools.ietf.org/html/rfc3986#section-4.3 * @param UriInterface $uri New request URI to use. * @param bool $preserveHost Preserve the original state of the Host header. * @return self */ public function withUri(UriInterface $uri, $preserveHost = false) { if ($uri === $this->_uri) { return $this; } $new = clone $this; $new->_uri = $uri; if (!$preserveHost) { $host = $uri->getHost(); if (\CoreTyson\isEmpty($host)) { if (($port = $uri->getPort()) !== null) { $host .= ':' . $port; } $this->withoutHeader('host'); // Ensure Host is the first header. // See: http://tools.ietf.org/html/rfc7230#section-5.4 $this->_headers = ['host' => [$host]] + $this->_headers; } } return $new; }