Factory Class

Files

/engine/class.www-factory.php

Introduction

Factory class is the base class for a lot of Wave Framework dynamically loaded model, view and controller objects. It is not required to build your MVC objects by extending Factory class, but doing so can make the development of these objects easier, as Factory also has wrappers to State, Wave Framework API and other functionality.

Factory class includes methods that dynamically load MVC objects as well as other classes that have been defined in the system. This includes internal Wave Framework classes such as Imager, Minifier and Database classes.

A lot of the methods defined in Factory class are wrappers. These wrapper methods are documented further in their own class-specific documentation files and are listed in this documentation here only for reference.

Using Factory class

Factory class is an internal Wave Framework class and should not be used outside the context of Wave Framework.

Factory Class Parameters

private $WWW_API=false

This variable holds the API object that is currently used by Wave Framework and Factory. API object is the core engine of Wave Framework.

private $WWW_API_callIndex=0

This is an internal variable that holds a counter of how many times the API has been called. It is possible to call API calls within other API calls, so this is used to keep track of how deep the current API call is, which is used to calculate buffering layers and other internal functionality in API Class.

Factory Class Methods

final public function __construct($api=false,$callIndex=0)

Construction method of Factory class initializes currently used API and API call index settings within the new object that is extended from Factory. This method will also call __initialize() method, if such a method is set in the class that is extended from Factory, as it is not allowed to overwrite __construct class itself.

final protected function api($command,$inputData=array(),$useBuffer=true)

This method is used by objects, that have been extended from Factory class, to make new API calls to Wave Framework. It takes a 'www-command' value in $command variable and an array of key and value pairs in $inputData variable that is used as input data. If $useBuffer is set to true, then API is told that it can use an internal API buffer call, which means that if API has already gotten the same exact API call with the same exact input variables, then it returns the result from buffer directly rather than execute it again.

final protected function apiConnection($address)

This method is used to initialize PHP API Wrapper object. This object can be used to send API calls to other API systems, that have been built on Wave Framework, over HTTP. $address is the API address URL that Wave Framework connects with. This method returns a new API Wrapper object.

final protected function getModel($model,$methodName=false,$methodData=array())

This is one of the core methods of Factory class. This method is used to return a new Wave Framework model. Model name is $model and it should exist as a file in /models/ or /overrides/models/ subfolder as model.[$model].php file. If $methodName is set, then this method will also automatically call that method and return result of that method instead of the model object itself. If $methodData is also set, then this is the input variable sent to $methodName.

final protected function getController($controller,$methodName=false,$methodData=array())

This is one of the core methods of Factory class. This method is used to return a new Wave Framework controller. Controller name is $controller and it should exist as a file in /models/ or /overrides/models/ subfolder as controller.[$controller].php file. If $methodName is set, then this method will also automatically call that method and return result of that method instead of the controller object itself. If $methodData is also set, then this is the input variable sent to $methodName.

final protected function getView($view,$methodName=false,$methodData=array())

This is one of the core methods of Factory class. This method is used to return a new Wave Framework view. View name is $view and it should exist as a file in /models/ or /overrides/models/ subfolder as view.[$view].php file. If $methodName is set, then this method will also automatically call that method and return result of that method instead of the view object itself. If $methodData is also set, then this is the input variable sent to $methodName.

final private function getMVC($type,$mvc,$methodName=false,$methodData=false)

This is one of the core methods of Factory class. This method is used to return a new Wave Framework MVC object. Object name is $mvc and it should exist as a file in /models/, /views/ or /controllers/ subfolders (or the /overrides/ folders). If $methodName is set, then this method will also automatically call that method and return result of that method instead of the object itself. If $methodData is also set, then this is the input variable sent to $methodName.

final protected function getObject($className,$methodName=false,$methodData=array())

This method loads and returns a new object for a class $className. Factory attempts to load this class definition from a file in /resources/classes/ or /overrides/resources/classes/ folder and file name should be written in format class.[$className].php in that folder. If $methodName is set, then this method will also automatically call that method and return result of that method instead of the view object itself. If $methodData is also set, then this is the input variable sent to $methodName.

final protected function loadLibrary($libraryName,$functionName=false,$methodData=false)

This method is used to dynamically load a library in /resources/libaries/ subfolder. If additional parameters are set, then this method can also automatically call one of the methods in the file.

final protected function getImager($source=false)

This method loads Imager class that is used for image editing. If $source is set, then it also automatically assigns a source image file for that Imager.

final protected function applyImager($source,$parameters,$target=false)

This is a wrapper method for Imager class method commands(). This method allows to load a file, edit a file and store a file in Filesystem in just a single method call. $source should be the image file in Filesystem, $parameters is the Wave Framework styled Image Handler accepted parameter string, like '320x240&filter(grayscale)' and $target should be the destination address for the file. If $target is missing then result is pushed to output buffer.

final protected function applyMinifier($data,$type)

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.

final protected viewData($variable=false)

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.

final protected getStorage($key=false)

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.

final protected setStorage($key,$value)

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.

final protected function viewHeader($content,$type='other')

This method allows you to send View Controller additional headers. This means that your views, models and controllers can all affect additional files that are loaded when View is returned to the browser. This allows for an extensive flexibility when building a dynamic back-end-front-end relations. $type can be 'script', 'library' or 'style' and they are loaded from '/resources/scripts/', '/resources/libraries/' or '/resources/styles/' folders. If type is not assigned or set to 'other', then the entire $content string will be added to the end of the HTML header.

final protected function resultError($message='Error',$customData=false,$responseCode=300)

Wave Framework MVC 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.

final protected function resultFalse($message='OK',$customData=false,$responseCode=400)

Wave Framework MVC 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 a false result, which should be used when an action failed but is not considered 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 a response code in 4XX namespace, which is used for false results in Wave Framework.

final protected function resultTrue($message='OK',$customData=false,$responseCode=500)

Wave Framework MVC 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 a successful result. $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 5XX namespace, which is used for successful results in Wave Framework.

final protected function checkTrueFalse($data)

This method is used to check for standardized API call result and determine if the API call was successful or not. It essentially checks for response codes in the array. $data is the result data array that is checked.

final protected function checkError($data)

This method is used to check for standardized API call result and determine if the API call had an error. It essentially checks for response codes in the array. $data is the result data array that is checked.

final protected function disableCache($state=true)

This method will tell Wave Framework API not to cache current API call, no matter what. This means that while current API call may be loaded from cache, but in case the cache does not exist the result will not be written to cache.

final protected function getReturnType()

This returns the www-return-type of currently known API request. This can be used to modify the request response based on what data is requested, if this is needed.

final protected function getVersion($type='api')

This method returns the currently used version numbers for API, system and Wave Framework itself.

final protected function dbNew($type,$host,$database,$username,$password,$showErrors=false,$persistentConnection=false)

This method can be used to dynamically create a new database connection object from Database class. $type is the database type, $host, $database, $username, $password are database connection credentials. And $showErrors defines whether errors should be thrown if encountered and $persistentConnection sets whether connection should be reused, if such already exists.

final protected function dbPDO()

This method returns the PDO class that API is currently using, if one is active.

final protected function isDeveloper()

This checks whether developer IP and user agent access the system. This is a light check that can be used to test out features for developers while other IP's and user agents are not affected. It returns true if developer browser and IP is detected.

Factory Class Wrapper Methods for State Class

Descriptions of these methods are detailed in State Class documentation.

final protected function getState(*)

final protected function setState(*)

final protected function getTranslations($language=false,$keyword=false,$subkeyword=false)

final public function getContent($name,$language=false)

final protected function getSitemap($language=false,$keyword=false)

final protected function getSitemapRaw($language=false,$keyword=false)

final protected function stateMessenger($address,$overwrite=false)

final protected function setMessengerData($key,$value=false)

This method stores data $value under key of $key. It also turns off caching of the current API call as a result, since State Messenger is outside the scope of caching. Additionally using this function also turns off caching of the page which uses it.

final protected function callTool($type,$arg1=false,$arg2=false)

final protected function unsetMessengerData($key=false)

final protected function getMessengerData($key=false,$remove=true)

This method returns data from State messenger. It either returns all the data from initialized state messenger, or just a $key from it. If $remove is set, then data is also set for deletion after it has been accessed. Additionally using this function also turns off caching of the page which uses it.

final protected function startSession($configuration=false)

final protected function regenerateSession($deleteOld=true)

final protected function setSession($key,$value)

final protected function getSession($key=false)

final protected function unsetSession($key=false)

final protected function setCookie($key,$value,$configuration=array())

final protected function getCookie($key)

final protected function unsetCookie($key)

final public function setUser($data)

final public function getUser($key=false)

final public function unsetUser()

final protected function checkPermissions($check)

final protected function getPermissions()

final protected function setPermissions($permissions)

final public function unsetPermissions()

final public function getPublicToken($regenerate=false,$forced=false)

final public function checkPublicToken()

final public function setHeader($header,$replace=true)

final public function unsetHeader($header)

final protected function terminal($command)

Factory Class Wrapper Methods for API Class

Descriptions of these methods are detailed in API class documentation.

final protected function clearBuffer()

final protected function unsetTaggedCache($tags)

final protected function getExistingCache()

final protected function getExistingCacheTime()

final protected function setCache($key,$value,$tags=false)

final protected function getCache($key)

final protected function cacheTime($key)

final protected function unsetCache($key)

final protected function encryptData($data,$key,$secretKey=false)

final protected function decryptData($data,$key,$secretKey=false)

final protected function logEntry($key,$data=false)

final protected function splitTime($key='api')

final protected function filter($string,$type,$exceptions=false)

final protected function resultStream($stream)

final protected function resultFile($location,$name=false,$contentType=false)

Factory Class Wrapper Methods for Database Class

Descriptions of these methods are detailed in Database class documentation.

final protected function dbSingle($query,$variables=array())

final protected function dbMultiple($query,$variables=array())

final protected function dbCommand($query,$variables=array())

final protected function dbLastId()

final protected function dbTransaction()

final protected function dbRollback()

final protected function dbCommit()

final protected function dbQuote($value,$type='escape',$stripQuotes=false)

public function dbArray($array,$key,$unique=true)

public function dbDebug($query,$variables=array())