Skip to content


New term in the PHP World: Introducing the MVC - SSC Pattern

SSC Pattern (Super Static Controllers):

I guess SSC (Super Static Controllers) pattern a new term that i found in the php world. I used SSC (static methods) to control none static library functions in my mvc framework.

The Goal of the SSC pattern to prevent the long writing style, we use it like this ssc::my_method() instead of $this->class->my_method() style ..

We can call SSC Pattern also as MVC-SSC because of SSC make sense along MVC pattern.

SSC is not same with php5 __callStatic function, call static function just for to call none static claseses directly and it works with Php5.3.0 and newer versions. A SSC class means just user predefined static functions that interested in current php scope.And it makes easier to controlling framework libraries.

Look at Figure 1.

SSC Pattern

SSC Pattern

User and ob classes our super static controller classes we can call them as static.Ob is the most important class in the SSC because every controllers, model and library classes extends to Ob class.

We know php allows to call none static methods as static in the current scope without any error so Ob class is our big current scope.Developer can call user and ob classes as static from test controller or from any class which extends to ob class.

We use user class as a common __constructor, framework user can define their custom static functions inside to user class.

Below the example shows a SSC Pattern how can we implement it simply.


<?php
/**
* SSC pattern (Super Static Controllers Pattern)
*
* @author Ersin Güvenç
* @copyright develturk.com (c) 2009
*/

/**
*  We use Super Static Controllers
*  for prevent long writing ($this->navigation->nav_level1())
*  we just write user::nav_level1();
*/

// Basic Simulation

Class user
{
    public $base_url = 'http://localhost/obullo/';
    public $base_img;
    public $base_css;

    /**
    * parent::__user();
    * User __construct for all constructors.
    * User common __construct for all controllers
    */
    function __user()
    {
        loader::library('navigation');
        echo 'this my top __Constructor for all controllers !';
        echo 'It comes from /application/extends/Ob_user.php<br />';
    }

    public function nav_level1()
    {
      return $this->navigation->nav_level1();
    }

    public function nav_level2()
    {
      return $this->navigation->nav_level2();
    }  

} // end class.

Class loader extends user {

    function library(){/* .... */}
    function model(){}
    function view(){}
    function helper(){}
}

Class SSC extends loader
{
    // You should not declare as static
    // for prevent to static vars error
    public function ip()
    {
        return $this->input->ip();
    }
}

// Our Super Object
Class ob extends SSC
{
    private static $instance;

    public function __construct()
    {
        self::$instance = $this;

        parent::__construct();
    }

    static function instance()
    {
        return self::$instance;
    } 

}

Class Controller extends ob
{ /* .... */ }

Class Model extends ob
{ /* .... */ }

Class Library extends ob
{ /* .... */ }

// Obullo input class.
// base/libraries/Input.php

Class Input extends Library
{
    function ip()
    {
        return $_SERVER['REMOTE_ADDR'];
    }
}

Class test extends Controller {

    function __construct()
    {
        parent::__construct();
        parent::__user();

        loader::library('input');
    }

    function run()
    {
        // Run Our SSC Function.
        echo ob::ip();
        echo user::nav_level1();

        // now i can use base url every wherer !
        echo $this->base_url;
    }

}

// No Php Static $this vars error  !!!
// because of php allows using $this vars
// ( inside none declared static functions )
// in current scope 

// Output: 127.0.0.1
// im the navigation level 1 !
// http://localhost/obullo/

?>

Call ip and user functions like static.

<?php

        // Run Our SSC Function.
        echo ob::ip();
        echo user::nav_level1();

        // now i can use base url every where !
        echo $this->base_url;
?>

This functions calls a background functions that we defined it before.

ob::ip(); | background func: $this->input->ip();
user::nav_level1(); | background func: $this->navigation->nav_level1();

No Php Static $this vars error because of php allows using $this vars inside current scope (ob class).

You can look a real SSC class inside Obullo 1.0 @alpha 2 software (wait for the next article ! )

  • Facebook
  • Digg
  • Delicious
  • Google Bookmarks
  • Technorati Favorites
  • Yahoo Bookmarks
  • Webnews
  • Technotizie
  • Taggly
  • Linkatopia
  • Ping
  • StumbleUpon
  • Twitter
  • Share/Bookmark

Posted in php articles.

Tagged with , , , , , , , .


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. ersin says

    Note

    Advantages of SSC:
    - Your codes will be minimal
    - Pattern prevents all confisuon
    - Readability go up
    - You will wriite less code

    Disadvantages:
    - All predefined SSC functions reserved in current controller.So you can’t use them in your controller.Forexample you can’t declare post function in the controller because of it defined before in SSC class (ob::post) which extend to Controller.

Continuing the Discussion

  1. Writing a PHP5 MVC Framework Part3: Intregrating CI Router to Obullo and Learning SSC Pattern - Php Developer - Istanbul linked to this post on 26/09/2009

    [...] MVC-SSC: SSC (Super Static Controllers) pattern a new term that i found in the php world.Look at (http://develturk.com/2009/09/25/new-term-in-the-php-world-introducing-new-php-mvc-ssc-pattern/) We have three main classes; Controller , Model and Library which extends to Ob class.ob , user, [...]



Some HTML is OK

or, reply to this post via trackback.



Easy AdSense by Unreal