API documentation for Konstrukt
A factory for creating components on-the-fly.
A ComponentCreator can create new instances of k_Component.
If you use a DI container, you should write an adapter that implements this interface
methods
abstract,
public
setDebugger(k_DebugListener
$debugger)
: void
Sets the debugger to use.
abstract,
public
create(mixed
$class_name, k_Context
$context [ , mixed
$namespace ] )
: k_Component
Creates a new instance of the requested class.
A simple implementation, which doesn't handle any dependencies.
You can use this, for very simple applications or if you prefer a global
mechanism for dependencies (Such as Singleton).
properties
protected
$document
: k_Document
protected
$aliases
: array
methods
public
__construct( [ mixed
$document ] )
: void
public
setDebugger(k_DebugListener
$debugger)
: void
Sets the debugger to use.
public
setImplementation(mixed
$class_name, mixed
$implementing_class)
: mixed
When trying to instantiate $class_name, instead use $implementing_class
public
create(mixed
$class_name, k_Context
$context [ , mixed
$namespace ] )
: k_Component
Creates a new instance of the requested class.
protected
instantiate(mixed
$class_name)
: k_Component
A debuglistener is an object that can receive various events and send
them to some place for further inspection.
methods
abstract,
public
logRequestStart(k_Context
$context)
: void
abstract,
public
logException(Exception
$ex)
: void
abstract,
public
logDispatch(mixed
$component, mixed
$name, mixed
$next)
: void
abstract,
public
log(mixed
$mixed)
: void
Allows the debugger to change the k_Response before output.
This is used to inject a debugbar into the response. It is perhaps not the most elegant solution, but it works.
A dummy implementation of k_DebugListener, which does nothing.
methods
public
logRequestStart(k_Context
$context)
: mixed
public
logException(Exception
$ex)
: mixed
public
logDispatch(mixed
$component, mixed
$name, mixed
$next)
: mixed
public
log(mixed
$mixed)
: mixed
public
decorate(k_Response
$response)
: mixed
Decorator that allowsmultiple k_DebugListener objects to receive the same events.
properties
protected
$listeners
: mixed
methods
public
logRequestStart(k_Context
$context)
: mixed
public
logException(Exception
$ex)
: mixed
public
logDispatch(mixed
$component, mixed
$name, mixed
$next)
: void
public
log(mixed
$mixed)
: mixed
For registry-style component wiring.
You can use this for legacy applications, that are tied to k_Registry.
usage:
$registry = new k_Registry();
k_run('Root', new k_HttpRequest(), new k_RegistryComponentCreator($registry))->out();
properties
protected
$registry
: mixed
methods
public
__construct(mixed
$registry)
: mixed
protected
instantiate(mixed
$class_name)
: mixed
Adapter for using the Phemto dependency injection container for creating components.
This relies on the current (under development) implementation of Phemto, available from:
https://phemto.svn.sourceforge.net/svnroot/phemto/trunk
properties
methods
public
__construct(Phemto
$injector [ , mixed
$document ] )
: void
protected
instantiate(mixed
$class_name)
: k_Component
Representation of the applications' user
methods
abstract,
public
user()
: mixed
abstract,
public
anonymous()
: mixed
Return true if the user is anonymous (not authenticated)
A factory for recognising and loading the users identity
methods
Using the context as input, the identityloader should find and return a userobject.
A default implementation, which always returns k_Anonymous
methods
Baseclass for basic http authentication.
methods
public
load(k_Context
$context)
: mixed
public
selectUser(mixed
$username, mixed
$password)
: mixed
This should be overridden in subclass to select user from eg. a database or similar.
Default implementation of k_Identity ... doesn't do much
methods
public
user()
: mixed
public
anonymous()
: mixed
Basic implementation of k_Identity, used for authenticated users.
properties
protected
$user
: mixed
methods
public
__construct(mixed
$user)
: mixed
public
user()
: mixed
public
anonymous()
: mixed
A context provides a full encapsulation of global variables, for any sub-components
The most important direct implementations are k_HttpRequest and k_Component
methods
abstract,
public
query( [ mixed
$key [ , mixed
$default ] ] )
: mixed
abstract,
public
body( [ mixed
$key [ , mixed
$default ] ] )
: mixed
abstract,
public
cookie( [ mixed
$key [ , mixed
$default ] ] )
: mixed
abstract,
public
session( [ mixed
$key [ , mixed
$default ] ] )
: mixed
abstract,
public
file( [ mixed
$key [ , mixed
$default ] ] )
: mixed
abstract,
public
rawHttpRequestBody()
: mixed
abstract,
public
requestUri()
: mixed
abstract,
public
method()
: mixed
abstract,
public
serverName()
: mixed
abstract,
public
identity()
: mixed
abstract,
public
url( [ mixed
$path [ , mixed
$params ] ] )
: mixed
abstract,
public
subspace()
: mixed
abstract,
public
negotiateContentType( [ mixed
$candidates ] )
: mixed
Usually the top-level context ... provides access to the http-protocol
properties
protected
$href_base
: string
protected
$subspace
: string
protected
$query
: array
protected
$body
: array
protected
$rawHttpRequestBody
: string
protected
$request_uri
: string
protected
$server
: array
protected
$files
: array
protected
$identity
: k_Identity
methods
protected
lowerKeys(mixed
$input)
: array
public
query( [ mixed
$key [ , mixed
$default ] ] )
: string
public
body( [ mixed
$key [ , mixed
$default ] ] )
: string
public
rawHttpRequestBody()
: string
Returns the http-request body as-is. Note that you have to manually handle charset-issues for this.
public
cookie( [ mixed
$key [ , mixed
$default ] ] )
: mixed
public
session( [ mixed
$key [ , mixed
$default ] ] )
: string
public
file( [ mixed
$key [ , mixed
$default ] ] )
: mixed
public
method()
: string
Gives back the HTTP-method
public
requestUri()
: mixed
public
serverName()
: string
Gives back the server name
public
url( [ mixed
$path [ , mixed
$params ] ] )
: string
Generates a URL relative to this component
public
subspace()
: string
public
negotiateContentType( [ mixed
$candidates [ , mixed
$user_override ] ] )
: string
Encapsulates logic for comparing against the Accept HTTP-header
properties
protected
$types
: array
methods
public
__construct( [ mixed
$accept ] )
: oid
public
parse(mixed
$input)
: array
public
parseType(mixed
$tuple)
: array
public
_sortByQ(mixed
$a, mixed
$b)
: integer
public
compare(mixed
$a, mixed
$b)
: boolean
public
match( [ mixed
$candidates [ , mixed
$user_override ] ] )
: string
The document is a container for properties of the HTML-document.
The default implementation (this) is rather limited. If you have more specific needs,
you can add you own subclass and use that instead. In that case, you should follow the
same convention of explicit getters/setters, rather than using public properties etc.
properties
protected
$title
: string
protected
$scripts
: array
protected
$styles
: array
protected
$onload
: array
methods
public
title()
: mixed
public
setTitle(mixed
$title)
: mixed
public
scripts()
: mixed
public
addScript(mixed
$script)
: mixed
public
styles()
: mixed
public
addStyle(mixed
$style)
: mixed
public
onload()
: mixed
public
addOnload(mixed
$onload)
: mixed
public
__set(mixed
$name, mixed
$value)
: mixed
Exception is raised when trying to change an immutable property.
A component is the baseclass for all userland components
Each component should be completely isolated from its surrounding, only
depending on its parent context
properties
protected
$context
: k_Context
protected
$url_state
: k_UrlState
protected
$url_init
: array
UrlState, will be initialised with these values, upon creation.
protected
$document
: k_Document
methods
protected
debug(mixed
$mixed)
: mixed
Log something to the debugger.
public
setContext(k_Context
$context)
: void
public
setUrlState(k_UrlState
$url_state)
: void
public
setComponentCreator(k_ComponentCreator
$component_creator)
: void
public
setDocument(k_Document
$document)
: void
public
setDebugger(k_DebugListener
$debugger)
: void
public
query( [ mixed
$key [ , mixed
$default ] ] )
: string
public
body( [ mixed
$key [ , mixed
$default ] ] )
: string
public
rawHttpRequestBody()
: mixed
public
cookie( [ mixed
$key [ , mixed
$default ] ] )
: mixed
public
session( [ mixed
$key [ , mixed
$default ] ] )
: string
public
file( [ mixed
$key [ , mixed
$default ] ] )
: mixed
public
method()
: string
public
requestUri()
: mixed
public
serverName()
: string
public
identity()
: mixed
public
url( [ mixed
$path [ , mixed
$params ] ] )
: string
public
subspace()
: string
public
negotiateContentType( [ mixed
$candidates [ , mixed
$user_override ] ] )
: mixed
protected
contentTypeShortName()
: mixed
protected
segment()
: string
The full path segment for this components representation.
protected
name()
: string
The name part of the uri segment.
protected
subtype()
: string
protected
next()
: string
protected
forward(mixed
$class_name [ , mixed
$namespace ] )
: string
protected
createComponent(mixed
$class_name, mixed
$namespace)
: k_Component
public
dispatch()
: string
protected
map(mixed
$name)
: mixed
public
execute()
: string
public
HEAD()
: mixed
public
GET()
: mixed
public
POST()
: mixed
public
PUT()
: mixed
public
DELETE()
: mixed
public
render()
: mixed
Renders the components view.
This method delegates control to an appropriate handler, based on content-type negotiation.
The typical handler would be `renderHtml`. If no handler is present, an exception is raised.
public
wrap(mixed
$content)
: mixed
Used for persisting state over the query-string, and for namespacing query-string parameters
properties
protected
$context
: k_Context
protected
$namespace
: string
protected
$state
: array
protected
$default_values
: array
methods
public
__construct(k_Context
$context [ , mixed
$namespace ] )
: void
public
init(mixed
$key [ , mixed
$default ] )
: void
public
has(mixed
$key)
: mixed
public
get(mixed
$key [ , mixed
$default ] )
: string
public
set(mixed
$key, mixed
$value)
: void
public
merge( [ mixed
$params ] )
: array
A utility class. This is a very simple template engine - Essentially, it's just
a wrapper around include, using output buffering to grab and return the output.
properties
protected
$path
: string
methods
public
__construct(mixed
$path)
: void
public
output(mixed
$str)
: mixed
public
render(mixed
$context)
: string
static,
protected
SearchIncludePath(mixed
$filename)
: mixed
Searches the include-path for a filename.
Returns the absolute path (realpath) if found or FALSE
static,
protected
InstallGlobals()
: mixed
Installs global functions
A metaresponse represents an abstract event in the application, which needs alternate handling.
This would typically be an error-condition.
In the simplest invocation, a metaresponse maps directly to a component, which renders a generic error.
methods
Raise this if the user must be authorised to access the requested resource.
methods
public
componentName()
: mixed
Raise this if the user doesn't have access to the requested resource.
methods
public
componentName()
: mixed
Raise this if the requested resource couldn't be found.
methods
public
componentName()
: mixed
Raise this if resource doesn't support the requested HTTP method.
methods
public
componentName()
: mixed
Raise this if the request isn't yet implemented.
This is roughly the HTTP equivalent to a "todo"
methods
public
componentName()
: mixed
Raise this if the request can't be processed due to details of the request (Such as the Content-Type or other headers)
methods
public
componentName()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
methods
public
dispatch()
: mixed
public
renderHtml()
: mixed
properties
protected
$is_debug
: boolean
protected
$log_filename
: string
protected
$href_base
: string
methods
public
run(mixed
$root_class_name)
: k_Response
Serves a http request, given a root component name.
protected
dispatchRoot(mixed
$root_class_name)
: mixed
Sets the context to use. Usually, this is an instance of k_HttpRequest.
Sets the componentcreator to use.
public
setDebug( [ mixed
$is_debug ] )
: k_Bootstrap
Enable/disable the in-browser debug-bar.
public
setLog(mixed
$filename)
: k_Bootstrap
Specifies a filename to log debug information to.
public
setHrefBase(mixed
$href_base)
: k_Bootstrap
Sets the base href, if the application isn't mounted at the web root.
protected
context()
: k_Context
methods
abstract,
public
write(mixed
$bytes)
: mixed
abstract,
public
endSession()
: mixed
methods
public
write(mixed
$bytes)
: mixed
public
endSession()
: mixed
methods
abstract,
public
query()
: mixed
abstract,
public
body()
: mixed
abstract,
public
rawHttpRequestBody()
: mixed
abstract,
public
server()
: mixed
abstract,
public
files()
: mixed
abstract,
public
cookie()
: mixed
properties
protected
$magic_quotes_gpc
: boolean
methods
public
__construct(k_charset_CharsetStrategy
$charset [ , mixed
$magic_quotes_gpc ] )
: null
public
query()
: array
public
body()
: mixed
public
rawHttpRequestBody()
: mixed
public
server()
: mixed
public
files()
: mixed
public
normalizeFiles(mixed
$files)
: mixed
public
cookie()
: mixed
protected
unMagic(mixed
$input)
: array
methods
abstract,
public
__construct(mixed
$domain, mixed
$raw)
: mixed
abstract,
public
has(mixed
$key)
: mixed
abstract,
public
get(mixed
$key [ , mixed
$default ] )
: mixed
abstract,
public
set(mixed
$key, mixed
$value [ , mixed
$expire [ , mixed
$secure [ , mixed
$httponly ] ] ] )
: mixed
abstract,
public
all()
: mixed
properties
protected
$domain
: string
protected
$raw
: string
methods
public
__construct(mixed
$domain, mixed
$raw)
: null
public
has(mixed
$key)
: mixed
public
get(mixed
$key [ , mixed
$default ] )
: mixed
public
set(mixed
$key, mixed
$value [ , mixed
$expire [ , mixed
$secure [ , mixed
$httponly ] ] ] )
: mixed
public
all()
: mixed
methods
abstract,
public
has(mixed
$key)
: mixed
abstract,
public
get(mixed
$key [ , mixed
$default ] )
: mixed
abstract,
public
set(mixed
$key, mixed
$value)
: mixed
abstract,
public
close()
: mixed
abstract,
public
destroy()
: mixed
abstract,
public
sessionId()
: mixed
abstract,
public
regenerateId()
: mixed
properties
methods
protected
autoStart()
: mixed
public
has(mixed
$key)
: mixed
public
get(mixed
$key [ , mixed
$default ] )
: mixed
public
set(mixed
$key, mixed
$value)
: mixed
public
close()
: mixed
public
destroy()
: mixed
public
sessionId()
: mixed
public
regenerateId()
: mixed
properties
methods
public
__construct(k_adapter_CookieAccess
$cookie_access [ , mixed
$raw ] )
: null
public
has(mixed
$key)
: mixed
public
get(mixed
$key [ , mixed
$default ] )
: string
public
set(mixed
$key, mixed
$value)
: string
public
close()
: mixed
public
destroy()
: mixed
public
sessionId()
: mixed
public
regenerateId()
: mixed
properties
public
$query
: array
public
$body
: array
public
$rawHttpRequestBody
: string
public
$server
: array
public
$cookie
: array
public
$files
: array
methods
public
__construct( [ mixed
$query [ , mixed
$body [ , mixed
$server [ , mixed
$headers [ , mixed
$cookie [ , mixed
$files ] ] ] ] ] ] )
: mixed
public
query()
: array
public
body()
: array
public
rawHttpRequestBody()
: string
public
server()
: array
public
files()
: array
public
cookie()
: array
methods
public
set(mixed
$key, mixed
$value [ , mixed
$expire [ , mixed
$secure [ , mixed
$httponly ] ] ] )
: mixed
methods
abstract,
public
copy(mixed
$tmp_name, mixed
$path_destination)
: mixed
methods
public
copy(mixed
$tmp_name, mixed
$path_destination)
: mixed
protected
mkdir(mixed
$path)
: mixed
protected
ensureDirectory(mixed
$dir)
: mixed
properties
public
$actions
: mixed
methods
public
copy(mixed
$tmp_name, mixed
$path_destination)
: mixed
properties
protected
$key
: mixed
protected
$name
: mixed
protected
$tmp_name
: mixed
protected
$size
: mixed
protected
$type
: mixed
protected
$file_access
: mixed
methods
public
__construct(mixed
$file_data, mixed
$key, k_adapter_UploadedFileAccess
$file_access)
: mixed
public
__serialize()
: mixed
public
key()
: mixed
public
name()
: mixed
public
type()
: mixed
public
size()
: mixed
public
writeTo(mixed
$path_destination)
: mixed
A responsecharset governs how the response is sent back to the client.
the httpresponse holds the content as utf-8, so each responsecharset should be able to convert
from this base
methods
abstract,
public
name()
: mixed
abstract,
public
encode(mixed
$utf8_string)
: mixed
methods
public
name()
: string
public
encode(mixed
$utf8_string)
: string
methods
public
name()
: mixed
public
encode(mixed
$utf8_string)
: mixed
A strategy for encoding/decoding charsets
The strategy is a factory for the Responsecharset as well as a filter to convert input to UTF-8
methods
abstract,
public
responseCharset()
: mixed
UTF-8
This is the preferred configuration
If you're using PHP < 6
You should use the [mb-string extension](http://docs.php.net/manual/en/mbstring.overload.php) to replace the built-ins. This is not crucial, but a good idea none the less.
You also need to make sure that all files (php and templates) are utf-8 encoded
If you use a database, make sure that the transfer charset is utf-8 (on mysql use: SET NAMES = 'utf8')
methods
ISO-8859-1
While this is the native solution for PHP < 6, it isn't recommended for new Konstrukt applications.
methods
public
responseCharset()
: mixed