<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.surebert.com/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.surebert.com/index.php?title=Special:NewPages&amp;feed=atom&amp;hideliu=&amp;hidepatrolled=&amp;hidebots=&amp;hideredirs=1&amp;limit=50&amp;namespace=0</id>
		<title>Surebert wiki - New pages [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.surebert.com/index.php?title=Special:NewPages&amp;feed=atom&amp;hideliu=&amp;hidepatrolled=&amp;hidebots=&amp;hideredirs=1&amp;limit=50&amp;namespace=0"/>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Special:NewPages"/>
		<updated>2012-05-20T09:43:01Z</updated>
		<subtitle>From Surebert wiki</subtitle>
		<generator>MediaWiki 1.16.2</generator>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework::sb_Event_Dispatcher_-_Advanced</id>
		<title>Framework::sb Event Dispatcher - Advanced</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework::sb_Event_Dispatcher_-_Advanced"/>
				<updated>2012-05-01T21:50:28Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: /* Additional Event Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
The [[Framework:Sb_Event_Dispatcher]] page covers basic event usage.  Here are some more advanced options.&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:Sb_Event_Dispatcher</id>
		<title>Framework:Sb Event Dispatcher</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:Sb_Event_Dispatcher"/>
				<updated>2012-05-01T21:13:37Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: /* Custom Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
The event dispatcher is used to allow the programmer to add events which other code can listen for.  It helps decouple the event dispatch code from the event listening code in a similar way to how javascript handles events.  It also makes it easy for you to allow other programmers to make modules that react to your main application without directly touching your code.&lt;br /&gt;
&lt;br /&gt;
=Creating the Dispatcher=&lt;br /&gt;
First create an event dispatcher.  It is common practice to create one global event dispatcher for your app, however, you can make as many instances as you want.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
App::$events = new sb_Event_Dispatcher();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Adding Listeners=&lt;br /&gt;
Next go ahead and add some listeners.  You can pass a function, a closure, a static class method reference, or a class instance method reference to a listener.  See the following examples.&lt;br /&gt;
&lt;br /&gt;
==function==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function crashed_car(sb_Event $e){&lt;br /&gt;
    echo &amp;quot;Oh no the car crashed... the survivor count was &amp;quot;.$e-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
}&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', 'crashed_car');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
==closure==&lt;br /&gt;
This one should look a lot like javascript&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
    echo &amp;quot;Oh no the car crashed... the survivor count was &amp;quot;.$e-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==static method==&lt;br /&gt;
The nice thing about using static methods is that the listening class is not autoloaded until the event fires.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
Class Car{&lt;br /&gt;
    public static function crash(sb_Event $e){&lt;br /&gt;
        echo &amp;quot;Oh no the car crashed... the survivor count was &amp;quot;.$e-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', Array('crashed_car', 'crash'));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==instance method==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
Class Car{&lt;br /&gt;
    public function crash(sb_Event $e){&lt;br /&gt;
        echo &amp;quot;Oh no the car crashed... the survivor count was &amp;quot;.$e-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$car = new Car();&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', Array($car, 'crash));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Stopping Propagation=&lt;br /&gt;
Sometimes you may want to prevent the event from propagating up to other subscribed listeners.  Make sure to only use this if you know what you are doing  as other programmers whose listeners would fire after yours will not receive anything.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
    echo &amp;quot;Oh no the car crashed&amp;quot;;&lt;br /&gt;
    $e-&amp;gt;stop_propagation();&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Setting/Getting Event Arguments=&lt;br /&gt;
In the examples above, the listeners were getting argument past from the when dispatcher fired the event.  Each listener can grab arguments and event edit or add to them.&lt;br /&gt;
&lt;br /&gt;
In this example, the one listener reports the survivor count but then changes it for the next listener.  &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
    echo &amp;quot;Oh no the car crashed... The survivor count was &amp;quot;.$e-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
    $e-&amp;gt;set_arg('survivor_count', 10);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While this type of usage may be very useful, it could also cause issues if you rely on the data matching the data originally past to the dispatcher.  If you wish to prevent this type of behavior you can pass an instance of sb_Event_Unchangeable instead of sb_Event to your event dispatcher.&lt;br /&gt;
&lt;br /&gt;
=Getting the Event Name=&lt;br /&gt;
You can get the current event name of the event being fired by calling the events get_name() method.  This is especially useful if you are reusing a single function listeners for multiple events and want to know which one fired.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
function generic_listener(sb_Event $e){&lt;br /&gt;
    if($e-&amp;gt;get_name() == 'car.crash'){&lt;br /&gt;
        //do something&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', 'generic_listener');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Getting the Event Subject=&lt;br /&gt;
Programmers can choose to pass a specific subject with the event by setting the second argument to the event __constructor.  See the dispatching the event details below for more info.  If the subject is set you can get it with $e-&amp;gt;get_subject() in the listener.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
    if($e-&amp;gt;get_subject() instanceOf Car){&lt;br /&gt;
        //do something&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Dispatching the Event=&lt;br /&gt;
When you dispatch the event, each listener is fired in the order that they were added and each listener receives the event passed as the second argument.  You can pass data to the event constructor.  It is then available in the listeners using the events -&amp;gt;get_arg() or -&amp;gt;get_args() method.&lt;br /&gt;
&lt;br /&gt;
This returns the event object back in the state it is at after passing through each listener which can do things like change the args, etc.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$e = App::$events-&amp;gt;dispatch('car.crash', new sb_Event(Array(&lt;br /&gt;
    'survivor_count' =&amp;gt; '3'&lt;br /&gt;
)));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Dispatching the event with a specific subject by passing the subject as the second argument to the event constructor.  This is options.  Once set, it can be referenced in the listener using $e-&amp;gt;get_subject();&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
$car = new Car(&amp;quot;AXT-2293&amp;quot;);&lt;br /&gt;
$e = App::$events-&amp;gt;dispatch('car.crash', new sb_Event(Array(&lt;br /&gt;
    'survivor_count' =&amp;gt; '3'&lt;br /&gt;
), $car));&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also dispatch the event and allow partial matches so listeners for event_name &amp;quot;car&amp;quot; would receive &amp;quot;car.paint&amp;quot; and &amp;quot;car.crash&amp;quot; events and can decide what to do based on $e-&amp;gt;get_name();  To do so set the third argument to dispatch &amp;quot;$allow_partial_match&amp;quot; to true.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
App::$events-&amp;gt;dispatch('car.crash', new sb_Event(), true);&lt;br /&gt;
App::$events-&amp;gt;dispatch('car.paint', new sb_Event(), true);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This listener would fire for car.crash or car.paint&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
App::$events-&amp;gt;add_listener('car', function(sb_Event $e){&lt;br /&gt;
    if($e-&amp;gt;get_name() == 'car.crash'){&lt;br /&gt;
        //do something&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Removing a Listener=&lt;br /&gt;
Everytime you add a listener, its unique id for that event is returned.  You can remove it by calling remove_listener and passing in the id.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
   //do something&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
App::$events-&amp;gt;remove_listener($id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Referencing the Dispatcher From The Listener=&lt;br /&gt;
You can always reference the dispatcher from the listener using the $e-&amp;gt;get_dispatcher() method;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(sb_Event $e){&lt;br /&gt;
   var_dump($this-&amp;gt;get_dispatcher()-&amp;gt;logger);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Custom Events=&lt;br /&gt;
You can easily extend the sb_Event to add custom events which can have their own easy access methods.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
class CarCrashEvent extends sb_Event{&lt;br /&gt;
    public function get_survivor_count(){&lt;br /&gt;
        return 'The survivor count was '.$this-&amp;gt;get_arg('survivor_count');&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then in the listener you can use the methods and properties of that extended Event class as needed.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$id = App::$events-&amp;gt;add_listener('car.crash', function(CarCrashEvent $e){&lt;br /&gt;
   echo $e-&amp;gt;get_survivor_count();&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Logging/Debugging=&lt;br /&gt;
You can have your event dispatcher log all events that fire making it much easier to bug decoupled code.  To do so simply set the logger for the event dispatcher.  After that new logs will be created matching the events that fire.  The logs are based on the event name and each capture includes whatever you normally include in the log headers e.g. username, ip, etc followed by information about where the listener that was fired is located and the data associated with the event being fired.&lt;br /&gt;
&lt;br /&gt;
You can expect logging to reduce the efficiency of event handling.  Therefore, it is best used for debugging in a dev environment.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
App::$events-&amp;gt;set_logger(App::$logger);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example logs&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2012/05/01 17:19:15	visco	14650	10.51.10.19	~visco	~14650&lt;br /&gt;
{&amp;quot;listener&amp;quot;:{&amp;quot;func&amp;quot;:&amp;quot;hello($e)&amp;quot;,&amp;quot;file&amp;quot;:&amp;quot;\/private\/views\/test\/page.view&amp;quot;,&amp;quot;line&amp;quot;:13},&amp;quot;event&amp;quot;:{&amp;quot;args&amp;quot;:{&amp;quot;survivor_count&amp;quot;:&amp;quot;3&amp;quot;,&amp;quot;func&amp;quot;:{}},&amp;quot;stopped_propagation&amp;quot;:0}}&lt;br /&gt;
&lt;br /&gt;
2012/05/01 17:19:15	visco	14650	10.51.10.19	~visco	~14650&lt;br /&gt;
{&amp;quot;listener&amp;quot;:{&amp;quot;func&amp;quot;:&amp;quot;Test::crash($e)&amp;quot;,&amp;quot;file&amp;quot;:&amp;quot;\/private\/models\/Test.php&amp;quot;,&amp;quot;line&amp;quot;:4},&amp;quot;event&amp;quot;:{&amp;quot;args&amp;quot;:{&amp;quot;survivor_count&amp;quot;:&amp;quot;3&amp;quot;,&amp;quot;func&amp;quot;:{}},&amp;quot;stopped_propagation&amp;quot;:0}}&lt;br /&gt;
&lt;br /&gt;
2012/05/01 17:19:15	visco	14650	10.51.10.19	~visco	~14650&lt;br /&gt;
{&amp;quot;listener&amp;quot;:{&amp;quot;func&amp;quot;:&amp;quot;new Test2()-&amp;gt;crash($e)&amp;quot;,&amp;quot;file&amp;quot;:&amp;quot;\/private\/views\/test\/page.view&amp;quot;,&amp;quot;line&amp;quot;:3},&amp;quot;event&amp;quot;:{&amp;quot;args&amp;quot;:{&amp;quot;survivor_count&amp;quot;:&amp;quot;3&amp;quot;,&amp;quot;func&amp;quot;:{}},&amp;quot;stopped_propagation&amp;quot;:0}}&lt;br /&gt;
&lt;br /&gt;
2012/05/01 17:19:15	visco	14650	10.51.10.19	~visco	~14650&lt;br /&gt;
{&amp;quot;listener&amp;quot;:{&amp;quot;func&amp;quot;:&amp;quot;{closure}($e)&amp;quot;,&amp;quot;file&amp;quot;:&amp;quot;\/private\/views\/test\/page.view&amp;quot;,&amp;quot;line&amp;quot;:19},&amp;quot;event&amp;quot;:{&amp;quot;args&amp;quot;:{&amp;quot;survivor_count&amp;quot;:&amp;quot;3&amp;quot;,&amp;quot;func&amp;quot;:{}},&amp;quot;stopped_propagation&amp;quot;:1}}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Advanced Usage=&lt;br /&gt;
There are more advanced things you can do with events but the above code should get you started.  See [[Framework::sb_Event_Dispatcher - Advanced]] for more info&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:sb_Controller_Command_Line</id>
		<title>Framework:sb Controller Command Line</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:sb_Controller_Command_Line"/>
				<updated>2011-06-30T16:28:30Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: /* Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
Used to create command line script for your surebert application.  While all views/controllers can be accessed via the command line, controllers that extended sb_Controller_Command_Line are Great for running cron jobs.  It calculates the time and memory used to run the script and logs to both screen and log file.&lt;br /&gt;
&lt;br /&gt;
It also prevents execution from anywhere but the command line.  E.g. will not serve over http.  You can change that by overriding the contructor.&lt;br /&gt;
&lt;br /&gt;
=Methods=&lt;br /&gt;
==log($message, $type='MESSAGE')==&lt;br /&gt;
Logs the message to screen and log file.  Type is displayed at beginning of log message.  If type is set to 'ERROR' then the message counts as an error in the total errors count.&lt;br /&gt;
&lt;br /&gt;
==set_memory_limit($message, $memory_in_MB=200)==&lt;br /&gt;
Sets the memory limit for the script&lt;br /&gt;
&lt;br /&gt;
==set_max_execution_time($time_in_seconds=3600)==&lt;br /&gt;
Sets the max execution time in seconds&lt;br /&gt;
&lt;br /&gt;
=Usage=&lt;br /&gt;
Create a new controller which extends sb_Controller_Command_Line.  Create a method with @servable true&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
class CronController extends sb_Controller_Command_Line {&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Does something&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function do_something() {&lt;br /&gt;
		$this-&amp;gt;log('Did something');&lt;br /&gt;
		$this-&amp;gt;log('Found Error', 'ERROR');&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Visit from the command line&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
php gateway.php --request=/cron/do_something&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Should report back something like.  Obviously, memory and time required depend on script, php configuration, and hardware.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
MESSAGE: 2011/06/30 12:28:02 - Begin Process CronController&lt;br /&gt;
MESSAGE: Did something&lt;br /&gt;
ERROR: Found Error&lt;br /&gt;
MESSAGE: PEAK MEMORY USAGE: 1 MB&lt;br /&gt;
MESSAGE: TOTAL ERRORS: 1&lt;br /&gt;
MESSAGE: TOTAL TIME REQUIRED: 6.09ms&lt;br /&gt;
MESSAGE: 2011/06/30 12:28:02 - End Log&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It would also log this same data to the file /private/logs/CronController/2011_06_30.log - replacing date with current date&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Repository</id>
		<title>Repository</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Repository"/>
				<updated>2011-06-11T01:22:43Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: Created page with &amp;quot;=Surebert Framework= Repository: http://surebert.com/svn/framework  Logs: &amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt; svn log -v http://surebert.com/svn/framework/ &amp;lt;/source&amp;gt;  =Surebert Toolkit= Reposit...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Surebert Framework=&lt;br /&gt;
Repository: http://surebert.com/svn/framework&lt;br /&gt;
&lt;br /&gt;
Logs:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
svn log -v http://surebert.com/svn/framework/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Surebert Toolkit=&lt;br /&gt;
Repository: http://surebert.com/svn/toolkit&lt;br /&gt;
&lt;br /&gt;
Logs:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
svn log -v http://surebert.com/svn/toolkit/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Surebert Application=&lt;br /&gt;
Repository: http://surebert.com/svn/application&lt;br /&gt;
&lt;br /&gt;
Logs:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
svn log -v http://surebert.com/svn/application/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/MIT_license</id>
		<title>MIT license</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/MIT_license"/>
				<updated>2011-06-11T01:17:33Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: Created page with &amp;quot;Copyright (c) 2011 Paul Visco  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &amp;quot;Software&amp;quot;), ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Copyright (c) 2011 Paul Visco&lt;br /&gt;
&lt;br /&gt;
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:&lt;br /&gt;
&lt;br /&gt;
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&lt;br /&gt;
&lt;br /&gt;
THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:.htaccess</id>
		<title>Framework:.htaccess</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:.htaccess"/>
				<updated>2011-03-31T05:25:17Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: Created page with &amp;quot;The .htaccess file looks for files in the public folder and if there is no match it redirects the request to the gateway in order to facilitate the request.  If using another ser...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The .htaccess file looks for files in the public folder and if there is no match it redirects the request to the gateway in order to facilitate the request.&lt;br /&gt;
&lt;br /&gt;
If using another server besides apache you would have to emulate this behavior.  Most servers can do this.  See [[Serving_with_nginx]] for using with nginx.&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:sb_Controller_REST</id>
		<title>Framework:sb Controller REST</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:sb_Controller_REST"/>
				<updated>2011-03-31T03:34:27Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: /* Explaination */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=sb_Controller_REST=&lt;br /&gt;
sb_Controller_REST is a custom controller you can extend which handles the full spectrum of HTTP request methods and fires the corresponding controller method that matches the HTTP request method.&lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class BlogController extends sb_Controller_REST{&lt;br /&gt;
&lt;br /&gt;
	public function __construct(){&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Accepts GET requests&lt;br /&gt;
	 * @return string&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function get(){&lt;br /&gt;
		return 'get: '.json_encode($this-&amp;gt;request);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Accepts PUT requests&lt;br /&gt;
	 * @return string&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function put(){&lt;br /&gt;
		return 'put: '.json_encode($this-&amp;gt;request-&amp;gt;data);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Accepts POST requests&lt;br /&gt;
	 * @return string&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function post(){&lt;br /&gt;
		return 'post: '.json_encode($this-&amp;gt;request-&amp;gt;post);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Accepts DELETE requests&lt;br /&gt;
	 * @return string&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function delete(){&lt;br /&gt;
		return 'delete: '.json_encode($this-&amp;gt;request-&amp;gt;data);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Explaination=&lt;br /&gt;
Using the example BlogControler above, a visit to yoursite.com/blog/ would fire the controller's get method because it is a get request.  You could then query the $this-&amp;gt;request for more info about the request.&lt;br /&gt;
&lt;br /&gt;
You could also request via ajax using the toolkit&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
new sb.ajax({&lt;br /&gt;
	url : '/blog/4',&lt;br /&gt;
	onResponse : function(r){&lt;br /&gt;
		//do something&lt;br /&gt;
	}&lt;br /&gt;
}).fetch();&lt;br /&gt;
&lt;br /&gt;
//or the shortcut&lt;br /&gt;
sb.get('/blog/4', function(){//do something});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using the surebert toolkit you could make a PUT or DELETE request via sb.ajax.  There is currently no shortcut call for PUT or DELETE requests, you must use a full sb.ajax request&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
new sb.ajax({&lt;br /&gt;
	url : '/blog',&lt;br /&gt;
	method : 'PUT',&lt;br /&gt;
	data : {title : 'Programming', entry : 'A fun activity'},&lt;br /&gt;
	onResponse : function(r){&lt;br /&gt;
		//do something&lt;br /&gt;
	}&lt;br /&gt;
}).fetch();&lt;br /&gt;
&lt;br /&gt;
new sb.ajax({&lt;br /&gt;
	url : '/blog/4',&lt;br /&gt;
	method : 'DELETE',&lt;br /&gt;
	onResponse : function(r){&lt;br /&gt;
		//do something&lt;br /&gt;
	}&lt;br /&gt;
}).fetch();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:sb_Controller_JSON_RPC2</id>
		<title>Framework:sb Controller JSON RPC2</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:sb_Controller_JSON_RPC2"/>
				<updated>2011-03-31T03:31:14Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: Created page with &amp;quot;=Creating a JSON RPC2 Server Using sb_Controller_JSON_RPC2= Creatng a JSON RPC2 server with the surebert framework is easy.  Simple extend the sb_Controller_JSON_RPC2_Server clas...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Creating a JSON RPC2 Server Using sb_Controller_JSON_RPC2=&lt;br /&gt;
Creatng a JSON RPC2 server with the surebert framework is easy.  Simple extend the sb_Controller_JSON_RPC2_Server class with your own.  This will allow you to select methods of you app which can then be called from another application.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
class CalculatorController extends sb_Controller_JSON_RPC2_Server{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Adds two numbers together&lt;br /&gt;
	 * @param integer $x&lt;br /&gt;
	 * @param integer $y&lt;br /&gt;
	 * @return integer&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function add($x, $y){&lt;br /&gt;
		return $x+$y;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You could then call it with a client as such&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$client = new sb_JSON_RPC2_Client('http://yoursite.com/calculator');&lt;br /&gt;
$result = $client-&amp;gt;add(1,2);&lt;br /&gt;
//$result would equal 3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==HTTP Status Headers==&lt;br /&gt;
By default a sb_JSON_RPC2_Server serves the appropriate HTTP status header with the response, see the table above.  If you would like to suppress the headers from being sent set the controllers's surpress_http_status to true;  You may have to do this for certain clients that won't read the message body if a status other than 200 is returned, e.g. 400, 404, 500&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
public $suppress_http_status = true;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==GZ Compression==&lt;br /&gt;
A sb_JSON_RPC2_Server instance can serve the json data gzipped.  This is an excellent way to save bandwith for larger data transfers.  You can set the gz compression level by passing a level 0-9 to the $server-&amp;gt;use_gz_encoding(3); method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
public $use_gz_encoding(6);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Encryption==&lt;br /&gt;
&lt;br /&gt;
sb_JSON_RPC2_Client and Server can encrypt communication using mcrypt. In order for it to work, both client and server must use the same key.&lt;br /&gt;
javascript code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
//use encryption for transfer, pass the same key the server is using&lt;br /&gt;
public $use_encryption($key);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	<entry>
		<id>http://wiki.surebert.com/index.php/Framework:Controllers</id>
		<title>Framework:Controllers</title>
		<link rel="alternate" type="text/html" href="http://wiki.surebert.com/index.php/Framework:Controllers"/>
				<updated>2011-03-31T03:29:14Z</updated>
		
		<summary type="html">&lt;p&gt;Paul: moved Framework:Controllers to Application:Controllers&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Framework:Controllers Overview=&lt;br /&gt;
The controllers basically intercept all requests coming in from the Gateway and respond back with the appropriate data.&lt;br /&gt;
&lt;br /&gt;
The controller being used to respond to the request is also the $this of any .view file that is rendered. The behind the scenes controller is called Gateway.  It passes off control to the default Controller which is called IndexController and is found in the /private/controllers directory.&lt;br /&gt;
&lt;br /&gt;
By default IndexController extends [[Framework:sb_Controller_HTML5|sb_Controller_HTML5]] which in turn extends sb_Contoller&lt;br /&gt;
&lt;br /&gt;
=sb_Controller Properties=&lt;br /&gt;
==$request==&lt;br /&gt;
The $this-&amp;gt;request property of a sb_Controller is an instance of sb_Request modeling the request that was given to the controller.  You can access this from any method of a controller other than __construct() at which time you can only refer to Gateway::$request.&lt;br /&gt;
&lt;br /&gt;
=sb_Controller Methods=&lt;br /&gt;
==__construct==&lt;br /&gt;
Called when the controller is instantiated.  The $this-&amp;gt;request is not available at this point.  See on_before_render() below if you need that.&lt;br /&gt;
&lt;br /&gt;
==on_before_render()==&lt;br /&gt;
Similar to __construct(), on_before_render() is called before any methods are called to render a response.  Unlike the constructor you do have access to the $this-&amp;gt;request property at this point. You can use on_before_render() to do things like check for GET query variables, cookies, admin status, etc.  If you ever return false from on_before_render, all executation is stopped at that point.  This is a great method to use for common security checks that would need to be called for each servable method.&lt;br /&gt;
&lt;br /&gt;
==render_view('/admin/login');==&lt;br /&gt;
This loads .view template e.g. /views/admin/login.view and returns the resulting contents.  The $this of the .view template is the Controller that called $this-&amp;gt;render_view('/admin/login);  For rendering a totally different request or overriding arguments of the Gateway::$request see [[Framework:Gateway#Gateway::render_request.28.29]]&lt;br /&gt;
&lt;br /&gt;
==not_found()==&lt;br /&gt;
This is fired when no there is no matching method or .view to handle the request.  The default is a 404 error page.  You can always redefine this.  You have access to the full request in this method if you want to do anything custom based on the request.c&lt;br /&gt;
&lt;br /&gt;
==__destruct==&lt;br /&gt;
Called when the Controller is destructed.  You could use this to disconnect from resources, log time/memory, etc&lt;br /&gt;
&lt;br /&gt;
==render()==&lt;br /&gt;
Renders the data based on the type of controller.  You do not usually call the method, however, you can redefine it to create different types of controllers.  The default action is to look for a method name that matches the request and if it is marked as @servable to return the result to the output buffer.  This method does not need to be called manually as it is called by the Gateway.  You could always redefine the render method for custom controllers.  See [[Framework:sb_Controller_REST]], [[Framework:sb_Controller_JSON_RPC2]] as examples of controllers who's render method changes the behavior of the controller.&lt;br /&gt;
&lt;br /&gt;
=Example=&lt;br /&gt;
The default render method of sb_Controller works this way.&lt;br /&gt;
It looks for a method that matches the request and is marked as @servable e.g. /car/drive would call the CarControllers drive method.  See example below.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
class CarController extends sb_Controller{&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * Test method to demonstrate servable methods&lt;br /&gt;
	 * @return string&lt;br /&gt;
	 * @servable true&lt;br /&gt;
	 */&lt;br /&gt;
	public function drive(){&lt;br /&gt;
		return 'is driving';&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/**&lt;br /&gt;
	 * fires when no servable method is found&lt;br /&gt;
	 */&lt;br /&gt;
	public function not_found(){&lt;br /&gt;
		//do something, then throw 404&lt;br /&gt;
		parent::not_found();&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Input and Method Properties=&lt;br /&gt;
Each public method has additional properties which can be defined in the phpdocs of the methods themselves.  These properties include:&lt;br /&gt;
&lt;br /&gt;
*'''@servable''' (true | false) Determines if the method is accessible via URL.  True by default&lt;br /&gt;
*'''@input_as_array''' (true | false) Determines if arguments are passed in order or as a named hash like GET and POST&lt;br /&gt;
*'''@http_method''' (get | post) Determines which type of data is passed to the method POST or GET&lt;br /&gt;
&lt;br /&gt;
==input_as_array==&lt;br /&gt;
For the following two examples we are assuming the url is /car/paint?color=ACACAC&amp;amp;detail=1&lt;br /&gt;
&lt;br /&gt;
A method that has input_as_array true would receive input like like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
* @servable true&lt;br /&gt;
* @http_method get&lt;br /&gt;
* @input_as_array true&lt;br /&gt;
*/&lt;br /&gt;
public function some_method($input){&lt;br /&gt;
	//$input['color'] = 'ACACAC';&lt;br /&gt;
	//$input['detail'] = '1';&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
While a method that has @input_as_array set to false would receive input values in the order they came with the keys.  In this case the order of the arguments is very important and should only be used when you can be sure of the order.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
/**&lt;br /&gt;
* @servable true&lt;br /&gt;
* @http_method get&lt;br /&gt;
* @input_as_array false&lt;br /&gt;
*/&lt;br /&gt;
public function some_method($color, $detail){&lt;br /&gt;
	//$color = 'ACACAC';&lt;br /&gt;
	//$detail = '1';&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Paul</name></author>	</entry>

	</feed>
