* # NanoController - A [KISS](https://en.wikipedia.org/wiki/KISS_principle) controller built for speed
* **NanoController** is an extremely simple and fast controller that uses the URI and not a routing table.
* ### Why NanoController?
* Traditional MVC frameworks use a routing table, which ends up being difficult to maintain and not obvious as to what the resulting URI is or what classes end up being invoked. Routing tables are a level of indirection that are really not needed for projects that define their own pathing, which is basically any business app behind a sign in page. In addition to requiring a complex routing table, the routing table takes up memory and execution time to resolve the route. **NanoController** has virtually no memory footprint and a very fast lookup algorithm. Reduced memory usage and fast execution times are especially important with an interpreted language such as PHP. Time and memory are cumulative, and best avoided where ever possible.
* ### [KISS](https://www.kissonline.com) - [Keep It Simple Stupid](https://en.wikipedia.org/wiki/KISS_principle)
* The **NanoController** maps namespaces, classes and methods directly to the URI and dispenses with a routing table. The result is an easy to understand namespace and class structure that exactly matches your URI. The URI tells you exactly where the class lives, and the class tells you the exact URI. No need to check a routing table to know what is invoked when.
* ### Naming Conventions
* **NanoController** follows standard naming conventions to figure out what namespace, class and method to call. Namespaces and classes should use [Studly Case](https://mentoor.io/posts/studlycase-vs-camelcase-vs-snakecase/1), capitalized first letter and capitalized letter of every word. Methods should follow [camelCase](https://mentoor.io/posts/studlycase-vs-camelcase-vs-snakecase/1), where the first letter is lowercase, with subsequent word's first letter upper cased, although this is not required, as PHP method names are case insensitive (unfortunately). **NanoController** uses the first lower case segment as the method name. The preceding segments form the namespace and class. **NanoController** will append the request method verb (in Studly Case) to the method name. If this method is not found, the base method name is tried. The method must be public.
* ### Parameters
* You can pass parameters with URI segments past the first lower case segment (which is the method name to call in the class) by simply specifying additional segments. **NanoController** uses method parameter types to cast the parameters to the right types. You can specify any scalar (**bool, int, float, string**), and **NanoController** will cast it to the correct type. If your parameter type is a class, **NanoController** will instantiate the class and pass the constuctor a string representation of the corresponding URI segment. If you specify **array** as the type, **NanoController** will pass all subsequent URI segments as an array of strings. No other parameters will be passed after an **array** parameter. Any parameters not specified will use the PHP default, so it is suggested that all parameters for the method have default values.
* ### Method Call
* **NanoController** will instantiate the class (which must impliment **\PHPFUI\Interfaces\NanoClass**) and call the specified method and pass any provided parameters. The run method returns the instantiated class with the specified method run. It is your job to deal with the object after that. Generally you would just call its output function (__toString normally) and return a completed page, but it is up to you.
* ### Landing Pages
* If a valid method is not found, but the class is, **NanoController** will attempt to call the default missing method if explicitly defined by calling **setMissingMethod**. This allows for a default landing page if a method is not called. If a default method is not specified, **NanoController** continues up the URI tree looking for a default method. If no class and default method are found, then the missing page is returned.
* ### Home Page
* If a blank URI (or \) is provided, it will return a class of **App\Missing**, unless **setHomePageClass** has been called. No method will be called on the HomePage class.
* ### Missing Class
* Users are prone to not typing in URIs exactly, so if **NanoController** can not find a class, or a class and method to instantiate, it will return a missing class of **App\Missing**, which can be overridden if needed by calling **setMissingClass**. If the namespace and class do not exist, the missing class will be returned. If the class exists, the missing method will be tried, and if not found, the missing method will be searched for back up the URI tree.
* ### Examples (assuming default App namespace)
* | URI | Namespace | Class | Method | Parameters |
* Run the controller and execute the class and method indicated by the URI
*
* @return \PHPFUI\Interfaces\NanoClass object instantiated class with the appropriate method called, except if the missing class is returned, then just the constructor has been called.
* If a class is found, but a method is not, then try calling this missing method. If no missing method is defined, go back up the tree looking for this method.