title: What are some PHP object-oriented framework initialization techniques?
body: <p>I have an object oriented framework that uses a page design, where each page extends a view of the framework. So, for instance, my index page for a site is actually a class that implements the abstract class <code>View</code> provided by the framework. I hook the framework by including a startup script at the top of the page and after some processing the framework creates an instance of the page and processes its view data. To add flexibility to the system, I don't require the class name to be the name of the file itself. This allows me to create something like a support class and have it behave as the index for the <code>/support/</code> subdomain.</p>
  
  <p>I was initially passing the page's class name into the framework via the framework's constructor, but this added a few more steps to the top or bottom of the page. I currently obtain the class name via a pages table in the database identified by a filtered requested <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Identifier" rel="nofollow noreferrer">URI</a>. I use this table to build navigation and adding an extra table column was practically free. This works OK as long as I have a database connection, but I'm trying to implement static page support for status messages and error reporting, and I need another method for creating an instance of the page's class. If I use the standard convention of naming the class the file's name, then I know I have a dependable way of extrapolating the class name. I don't really want to name all my classes index just for presentation reasons. What is some advice or some standards for how object oriented frameworks are initialized?</p>
  
  <h3>View.inc</h3>
  
  <pre><code>&lt;?php
  abstract class View
  {
      abstract function getView();
  }
  ?&gt;
  </code></pre>
  
  <h3>Startup.inc</h3>
  
  <pre><code>&lt;?php
      require_once("View.inc");
      require_once("CoreController.inc");
  
      $Framework = new CoreController();
      $Framework-&gt;Initialize();
      exit;
  ?&gt;
  </code></pre>
  
  <h3>index.php</h3>
  
  <pre><code>&lt;?php
      require_once("Startup.inc");
  
      class Index extends View
      {
          public function getView()
          {
              echo "&lt;pre&gt;View Data&lt;/pre&gt;";
          }
      }
  ?&gt;
  </code></pre>
  
  <p>Within my framework I have a TemplateController that processes the page. The page class is known because it is mapped via another class. Without a database however, I would like to discover the class within, say, <code>index.php</code> without changing the way it's currently set up. Here is the actual code within the TemplateController.</p>
  
  <pre><code>//Get the View Class from Page
  $view = $page-&gt;getPageClass();
  
  //We need to catch View creation failure
  $this-&gt;Page = new $view($this-&gt;Framework);
  
  //Initialize the Page View
  $this-&gt;Page-&gt;Initialize();
  
  //Cache the Page View
  $this-&gt;cacheView($this-&gt;Page, $page-&gt;getPageName(), $this-&gt;SiteID.TCS_PAGE_SORTID);
  </code></pre>
  
  <p>In the snippet above <code>$view</code> is the actual name of the class that was mapped from another controller. I'm passing a reference to the framework to the view's constructor and the rest is really irrelevant. I'm trying to come up with a similar mapping technique to identify the page class in the event the database is down. I like the one include line for the framework startup and would like to keep it that simple.</p>
  
  <p>At the top of the TemplateController I have to also reinclude the actual page, since my startup script is at the top, the actual class is not included even though it is the requested page.</p>
  
  <pre><code>include($_SERVER['SCRIPT_FILENAME']);
  </code></pre>
  
  <p>Please review Stack Overflow question <em><a href="https://stackoverflow.com/questions/5726934/indentifying-class-names-from-serverscript-filename">Identifying class names from $_SERVER['SCRIPT_FILENAME']</a></em> for more information on what I'm attempting to do.</p>