Permalink
Browse files

Integrated a new method callTool() to Factory and State, which allows…

… you to call system specific functions such as filesystem cleaner or to get an index of files. More tools will be added in the future. The additional JavaScript and PHP loading now targets /scripts/ folder and not /libraries/ folder. Added the option to load external JS and CSS based on sitemap URL. File handler can also use overrides now, if a file is in resources folder. Moved '/resources/autoload.php' to '/resources/scripts/script.php'.
  • Loading branch information...
kristovaher committed Oct 22, 2012
1 parent 2d3b066 commit a1c6713299821676f198f2275f991f334073452f
View
@@ -1,2 +1,2 @@
-www:3.4.1
+www:3.4.2
system:1.0.0
View
@@ -26,7 +26,7 @@
; @license GNU Lesser General Public License Version 3
; @tutorial /doc/pages/configuration.htm
; @since 1.0.0
-; @version 3.4.1
+; @version 3.4.2
; HTTP AUTHENTICATION
@@ -87,6 +87,8 @@
; database-name=""
; database-username=""
; database-password=""
+ ; database-persistent=0
+ ; database-errors=1
; These are database credentials for the Test Suite that is run by the test script and tests stored
; at /tools/ subfolder. It is recommended that the test database is identical in structure to
@@ -96,6 +98,8 @@
; test-database-name=""
; test-database-username=""
; test-database-password=""
+ ; test-database-persistent=0
+ ; test-database-errors=1
; SERVER
@@ -31,15 +31,171 @@ class WWW_controller_example extends WWW_Factory {
* @output [key] This is an output value that might exist in the output array
* @response [500] Data returned
*/
- public function get($input){
- // New objects can be created through Factory easily
- $example=$this->getModel('example');
- // This 'loads' model with ID of 1. Note that the function call here can be anything you need, this is just used as an example
- $example->load(1);
- // Getting the data from the model
- $data=$example->get();
- // Returning the result of controller call
- return $this->resultTrue('Data returned',$data);
+ public function get($configuration){
+
+ // This is only set for demonstration purposes, remove it when using this class as template
+ $configuration['id']=1;
+
+ // ID needs to be set
+ if(isset($configuration['id'])){
+ // Loading the model and data to the model
+ $data=$this->getModel('example');
+ if($data->load($configuration['id'])){
+ // Returning an array representation of the model data
+ return $this->resultTrue('Entry found',$data->get());
+ } else {
+ // Action failed because entry was not found
+ return $this->resultFalse('Entry not found');
+ }
+ } else {
+ // Action failed because incorrect request was made to the controller
+ return $this->resultError('ID not defined');
+ }
+
+ }
+
+ /**
+ * Simple example call to get multiple database rows
+ *
+ * @param array $input input data sent to controller
+ * @input [key] This key is one of the accepted input values
+ * @return array
+ * @output [key] This is an output value that might exist in the output array
+ * @response [500] Data returned
+ */
+ public function all($configuration){
+
+ // Loading the model and sending input data to the request
+ $data=$this->getModel('example');
+ $data=$data->all($configuration);
+
+ // This returns empty array if none were found
+ if($data){
+ return $this->resultTrue('Request complete',$data);
+ } else {
+ return $this->resultFalse('Search failed');
+ }
+
+ }
+
+ /**
+ * Simple example call to add rows to database
+ *
+ * @param array $input input data sent to controller
+ * @input [key] This key is one of the accepted input values
+ * @return array
+ * @output [key] This is an output value that might exist in the output array
+ * @response [500] Data returned
+ */
+ public function add($input){
+
+ // This flag checks if error has been encountered during form validation
+ $errorsEncountered=array();
+ $errorFields=array();
+
+ // Validating input
+ if(isset($input['name']) && trim($input['name'])!=''){
+ $input['name']=trim($input['name']);
+ } else {
+ $errorFields['name']=true;
+ $errorsEncountered[]='name-incorrect';
+ }
+
+ // Data is only added if no errors were encountered
+ if(empty($errorsEncountered)){
+ // Getting model and setting the parameters
+ $data=$this->getModel('example');
+ $data->name=$input['name'];
+ // Attempting to save
+ if($data->save()){
+ return $this->resultTrue('Entry added');
+ } else {
+ return $this->resultError('Failed to add entry');
+ }
+ } else {
+ return $this->resultFalse('Input data incorrect');
+ }
+
+ }
+
+ /**
+ * Simple example call to edit rows to database
+ *
+ * @param array $input input data sent to controller
+ * @input [key] This key is one of the accepted input values
+ * @return array
+ * @output [key] This is an output value that might exist in the output array
+ * @response [500] Data returned
+ */
+ public function edit($input){
+
+ // ID has to be set when editing
+ if(isset($input['id'])){
+
+ // This flag checks if error has been encountered during form validation
+ $errorsEncountered=array();
+ $errorFields=array();
+
+ // Validating input
+ if(isset($input['name']) && trim($input['name'])!=''){
+ $input['name']=trim($input['name']);
+ } else {
+ $errorFields['name']=true;
+ $errorsEncountered[]='name-incorrect';
+ }
+
+ // Data is only edited if no errors were encountered
+ if(empty($errorsEncountered)){
+ // Getting model
+ $data=$this->getModel('example');
+ // Data loading has to work based on the provided ID
+ if($data->load($input['id'])){
+ // Setting the changed input parameters
+ $data->name=$input['name'];
+ // Attempting to save
+ if($data->save()){
+ return $this->resultTrue('Entry edited');
+ } else {
+ return $this->resultError('Failed to edit entry');
+ }
+ } else {
+ return $this->resultFalse('Entry ID not found');
+ }
+ } else {
+ return $this->resultFalse('Input data incorrect');
+ }
+
+ } else {
+ return $this->resultFalse('Entry ID is missing');
+ }
+
+ }
+
+ /**
+ * Simple example call to delete a row from database
+ *
+ * @param array $input input data sent to controller
+ * @input [key] This key is one of the accepted input values
+ * @return array
+ * @output [key] This is an output value that might exist in the output array
+ * @response [500] Data returned
+ */
+ public function delete($input){
+
+ // ID has to be set when deleting
+ if(isset($input['id'])){
+ // Getting model
+ $data=$this->getModel('example');
+ // Attempting to delete
+ if($data->delete($input['id'])){
+ return $this->resultTrue('Entry deleted');
+ } else {
+ return $this->resultError('Failed to delete entry');
+ }
+ } else {
+ return $this->resultFalse('Entry ID is missing');
+ }
+
}
}
@@ -15,7 +15,7 @@
* @license GNU Lesser General Public License Version 3
* @tutorial /doc/pages/guide_view.htm
* @since 1.0.0
- * @version 3.4.1
+ * @version 3.4.2
*/
class WWW_controller_view extends WWW_Factory {
@@ -34,16 +34,21 @@ public function load($input){
unset($input['www-command'],$input['www-return-type'],$input['www-cache-timeout'],$input['www-request'],$input['www-session'],$input['www-cache-tags']);
// Getting view information
- $view=$this->getState('view');
+ $view=$this->viewData();
$systemRoot=$this->getState('system-root');
// If PHP libraries are set to be loaded, then loading them through Factory
if(isset($view['additional-php']) && $view['additional-php']!=''){
// Libraries are in a comma-separated list
$libraries=explode(',',$view['additional-php']);
foreach($libraries as $l){
- // This will throw an error, if the library is not found
- $this->loadLibrary($l);
+ if(file_exists($systemRoot.'overrides'.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.$l.'.php')){
+ // Requiring override file
+ require($systemRoot.'overrides'.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.$l.'.php');
+ } else {
+ // Requiring original file
+ require($systemRoot.'resources'.DIRECTORY_SEPARATOR.'scripts'.DIRECTORY_SEPARATOR.$l.'.php');
+ }
}
}
@@ -95,6 +100,11 @@ public function load($input){
$coreStyleSheet[]='reset.css';
$coreStyleSheet[]='style.css';
+ // If Sitemap file has defined additional external CSS stylesheets
+ if(isset($view['external-css']) && $view['external-css']!=''){
+ $externalStylesheet=explode(',',$view['external-css']);
+ }
+
// If Sitemap file has defined additional CSS files
if(isset($view['additional-css']) && $view['additional-css']!=''){
$additionalStylesheet=explode(',',$view['additional-css']);
@@ -117,6 +127,11 @@ public function load($input){
$coreJavaScript[]='class.www-wrapper.js';
$coreJavaScript[]='class.www-factory.js';
+ // If Sitemap file has defined additional external JavaScript libraries
+ if(isset($view['external-js']) && $view['external-js']!=''){
+ $externalJavaScript=explode(',',$view['external-js']);
+ }
+
// If Sitemap file has defined additional JavaScript libraries
if(isset($view['additional-js']) && $view['additional-js']!=''){
$additionalJavaScript=explode(',',$view['additional-js']);
@@ -161,6 +176,11 @@ public function load($input){
<?php } ?>
<!-- Stylesheets -->
<link type="text/css" href="resources/styles/<?=implode('&',$coreStyleSheet)?>" rel="stylesheet" media="all"/>
+ <?php if(isset($externalStylesheet)){ ?>
+ <?php foreach($externalStylesheet as $style){ ?>
+ <link type="text/css" href="<?=implode('&',$style)?>" rel="stylesheet" media="all"/>
+ <?php } ?>
+ <?php } ?>
<?php if(isset($additionalStylesheet)){ ?>
<link type="text/css" href="resources/styles/<?=implode('&',$additionalStylesheet)?>" rel="stylesheet" media="all"/>
<?php } ?>
@@ -172,8 +192,13 @@ public function load($input){
<link rel="icon" href="favicon.ico" type="image/vnd.microsoft.icon"/>
<!-- JavaScript -->
<script type="text/javascript" src="resources/scripts/<?=implode('&',$coreJavaScript)?>"></script>
+ <?php if(isset($externalJavaScript)){ ?>
+ <?php foreach($externalJavaScript as $script){ ?>
+ <script type="text/javascript" src="<?=$script?>"></script>
+ <?php } ?>
+ <?php } ?>
<?php if(isset($additionalJavaScript)){ ?>
- <script type="text/javascript" src="resources/libraries/<?=implode('&',$additionalJavaScript)?>"></script>
+ <script type="text/javascript" src="resources/scripts/<?=implode('&',$additionalJavaScript)?>"></script>
<?php } ?>
<?php if(isset($moduleJavaScript)){ ?>
<script type="text/javascript" src="resources/scripts/<?=$moduleJavaScript?>"></script>
View
@@ -48,7 +48,8 @@ <h2>Feature Guides</h2>
<p>This section covers feature guides and is meant to be a supplement to Tutorials. This covers all the features of Wave Framework and gives detailed overview of functionality when building Wave Framework MVC classes and functionality, especially when creating websites.</p>
<ul>
- <li><a href="pages/guide_website.htm">Website Workflow</a> - Brief overview about how Wave Framework handles URL requests</li>
+ <li><a href="pages/guide_project.htm">Project Setup</a> - Brief overview about how to set up a project</li>
+ <li><a href="pages/guide_website.htm">Website Workflow</a> - How URL requests are handled by default controllers</li>
<li><a href="pages/guide_url.htm">URL Controller and Sitemap</a> - URL routing through URL controller and sitemap</li>
<li><a href="pages/guide_view.htm">View Controller and Translations</a> - Details about default view controller, translations and view-loading</li>
<li><a href="pages/guide_mvc.htm">MVC Pattern</a> - Good practices when building models, views and controllers with Wave Framework</li>
@@ -61,7 +62,7 @@ <h2>Feature Guides</h2>
<li><a href="pages/guide_messenger.htm">State Messenger</a> - Using state messenger</li>
<li><a href="pages/guide_logger.htm">Internal Logger</a> - Using internal logger</li>
<li><a href="pages/guide_cache.htm">Cache</a> - Cache and buffer functionality</li>
- <li><a href="pages/guide_autoload.htm">Autoload</a> - Autoload script</li>
+ <li><a href="pages/guide_autoload.htm">Autoload</a> - Automatically loaded scripts</li>
<li><a href="pages/guide_security.htm">Security</a> - Cross-site requests and general web security</li>
<li><a href="pages/guide_crypto.htm">Cryptography</a> - Encryption and decryption options</li>
<li><a href="pages/guide_performance.htm">Performance</a> - Performance testing options</li>
View
@@ -113,6 +113,10 @@ <h3>www-cache-timeout</h3>
<p>This allows for a lot of flexibility as it is an on-demand cache-control that can be used to speed up requests or the same Controller in some parts of the system based on their importance.</p>
+ <h3>www-cache-load-timestamp</h3>
+
+ <p>This tells the API to accept cache with different timestamp based age than the 'www-cache-timeout' value. This means that you can make a request that only allows 'www-cache-load-timestamp' aged cache, but writes a different cache age to headers and for other methods.</p>
+
<h3>www-profile</h3>
<p>This is the API profile name that should also be defined in '/resources/api.profiles.ini' file. This tells API what API profile (and thus what profile settings) the API will use when validating the API request.</p>
@@ -56,7 +56,9 @@ <h2>Database</h2>
database-host<br/>
database-name<br/>
database-username<br/>
- database-password</p>
+ database-password<br/>
+ database-errors<br/>
+ database-persistent</b></p>
<p>Wave Framework can connect to multiple <a href="guide_database.htm">Database</a> types, database-type values can be 'mysql', 'postgresql', 'sqlite', 'mssql' and 'oracle'. If database values are not set, then system won't attempt to connect to database. Persistent connections are allowed by using database-persistent flag, in which case same connection handle will be shared across requests from different user agents, but note that this flag is not recommended and can cause additional performance issues. If you need to add port information for host, add it after host name, like 'www.example.com:3306'.</p>
View
@@ -84,6 +84,18 @@ <h3>final protected function applyMinifier($data,$type)</h3>
<p>This method is used to apply static Minifier class method to a text string. $data should be the data string to be modified and $type should be the format type (either xml, html, js or css). This method returns modified string that is minified by Minifier class.</p>
+ <h3>final protected viewData($variable=false)</h3>
+
+ <p>This is just a wrapper function for getting state data for view. This method returns $variable from the current view settings or the entire view data array, if this is not set.</p>
+
+ <h3>final protected getStorage($key=false)</h3>
+
+ <p>This is just a wrapper function for getting state from global state storage. This method returns $variable from the storage or the whole storage at once if this is not set.</p>
+
+ <h3>final protected setStorage($key,$value)</h3>
+
+ <p>This is just a wrapper function for getting state from global state storage. This method returns $variable from the storage or the whole storage at once if this is not set.</p>
+
<h3>final protected function resultError($message='Error',$customData=false,$responseCode=300)</h3>
<p>Wave Framework <a href="guide_mvc.htm">MVC</a> object method calls can return their data in whatever format developer finds necessary, but it is recommended to return data in a standardized form. This method returns an array in the format of an error. $message should be the verbose message returned, $customData should be an array of data returned as part of the result and $responseCode should be an response code in 3XX namespace, which is used for errors in Wave Framework.</p>
@@ -140,6 +152,8 @@ <h3>final protected function setMessengerData($key,$value=false)</h3>
<p>This method stores data $value under key of $key. It also turns off caching of the current <a href="guide_api.htm">API</a> call as a result, since <a href="guide_messenger.htm">State Messenger</a> is outside the scope of caching. Additionally using this function also turns off caching of the page which uses it.</p>
+ <h3>final protected function callTool($type,$arg1=false,$arg2=false)</h3>
+
<h3>final protected function unsetMessengerData($key=false)</h3>
<h3>final protected function getMessengerData($key=false,$remove=true)</h3>
View
@@ -115,7 +115,7 @@ <h3>How Can I Implement My Own Session Handler?</h3>
<p>Wave Framework uses PHP's own session handling to manipulate with user sessions and detect if sessions are used and what data is stored in $_SESSION. But sometimes it is important to use your own session handling, especially if sessions are stored on another server or through another system.</p>
- <p>While there is no way to specify how Wave Framework handles sessions directly, it is possible in PHP to rewrite session handling functions that PHP natively uses (the same ones that Wave Framework implements). PHP function that defines all the functions used for session handling is the session_set_save_handler(). You can get more information about this function from PHP's own documentation. You should define the sessions you need in in the <a href="guide_autoload.htm">Autoload</a> script in '/resources/autoload.php' file. Read more about <a href="guide_autoload.htm">Autoload</a> script in its own documentation.</p>
+ <p>While there is no way to specify how Wave Framework handles sessions directly, it is possible in PHP to rewrite session handling functions that PHP natively uses (the same ones that Wave Framework implements). PHP function that defines all the functions used for session handling is the session_set_save_handler(). You can get more information about this function from PHP's own documentation. You should define the sessions you need in in the <a href="guide_autoload.htm">Autoload</a> script in '/resources/scripts/script.php' file. Read more about <a href="guide_autoload.htm">Autoload</a> scripts in its own documentation.</p>
<h3>My Requests Fail and Decompression Error is Returned By the Browser?</h3>
Oops, something went wrong.

0 comments on commit a1c6713

Please sign in to comment.