API documentation for Konstrukt

interface k_ComponentCreator

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.

class k_DefaultComponentCreator

implements k_ComponentCreator

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 $debugger : k_DebugListener

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

interface k_DebugListener

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

abstract, public decorate(k_Response $response) : k_Response

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.

class k_VoidDebugListener

implements k_DebugListener

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

class k_MultiDebugListener

implements k_DebugListener

Decorator that allowsmultiple k_DebugListener objects to receive the same events.

properties

protected $listeners : mixed

methods

public add(k_DebugListener $listener) : mixed

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

public decorate(k_Response $response) : k_Response

class k_RegistryComponentCreator extends k_DefaultComponentCreator

implements k_ComponentCreator

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

class k_PhemtoAdapter extends k_DefaultComponentCreator

implements k_ComponentCreator

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

protected $injector : Phemto

methods

public __construct(Phemto $injector [ , mixed $document ] ) : void

protected instantiate(mixed $class_name) : k_Component

interface k_Identity

Representation of the applications' user

methods

abstract, public user() : mixed

Return the username

abstract, public anonymous() : mixed

Return true if the user is anonymous (not authenticated)

interface k_IdentityLoader

A factory for recognising and loading the users identity

methods

abstract, public load(k_Context $context) : k_Identity

Using the context as input, the identityloader should find and return a userobject.

class k_DefaultIdentityLoader

implements k_IdentityLoader

A default implementation, which always returns k_Anonymous

methods

public load(k_Context $context) : mixed

class k_BasicHttpIdentityLoader

implements k_IdentityLoader

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.

class k_Anonymous

implements k_Identity

Default implementation of k_Identity ... doesn't do much

methods

public user() : mixed

public anonymous() : mixed

class k_AuthenticatedUser

implements k_Identity

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

interface k_Context

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 header( [ 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

class k_HttpRequest

implements k_Context

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 $headers : array

protected $session_access : k_adapter_SessionAccess

protected $identity_loader : k_IdentityLoader

protected $identity : k_Identity

protected $content_type_negotiator : k_ContentTypeNegotiator

methods

public __construct( [ mixed $href_base [ , mixed $request_uri [ , k_IdentityLoader $identity_loader [ , k_adapter_GlobalsAccess $superglobals [ , k_adapter_CookieAccess $cookie_access [ , k_adapter_SessionAccess $session_access [ , k_adapter_UploadedFileAccess $file_access ] ] ] ] ] ] ] ) : mixed

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 header( [ mixed $key [ , mixed $default ] ] ) : string

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 identity() : k_Identity

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

class k_ContentTypeNegotiator

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

class k_Document

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

class k_PropertyImmutableException extends Exception

Exception is raised when trying to change an immutable property.

abstract class k_Component

implements k_Context

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 $component_creator : k_ComponentCreator

protected $document : k_Document

protected $debugger : k_DebugListener

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 header( [ 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

class k_UrlState

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

class k_Template

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

abstract class k_MetaResponse extends Exception

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

abstract, public componentName() : mixed

class k_NotAuthorized extends k_MetaResponse

Raise this if the user must be authorised to access the requested resource.

methods

public componentName() : mixed

class k_Forbidden extends k_MetaResponse

Raise this if the user doesn't have access to the requested resource.

methods

public componentName() : mixed

class k_PageNotFound extends k_MetaResponse

Raise this if the requested resource couldn't be found.

methods

public componentName() : mixed

class k_MethodNotAllowed extends k_MetaResponse

Raise this if resource doesn't support the requested HTTP method.

methods

public componentName() : mixed

class k_NotImplemented extends k_MetaResponse

Raise this if the request isn't yet implemented. This is roughly the HTTP equivalent to a "todo"

methods

public componentName() : mixed

class k_NotAcceptable extends k_MetaResponse

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

class k_DefaultNotAuthorizedComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_DefaultForbiddenComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_DefaultPageNotFoundComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_DefaultMethodNotAllowedComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_DefaultNotNotAcceptableComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_DefaultNotImplementedComponent extends k_Component

implements k_Context

methods

public dispatch() : mixed

public renderHtml() : mixed

class k_Bootstrap

Application bootstrap.

properties

protected $http_request : k_HttpRequest

protected $components : k_ComponentCreator

protected $charset_strategy : k_charset_CharsetStrategy

protected $is_debug : boolean

protected $log_filename : string

protected $href_base : string

protected $identity_loader : k_IdentityLoader

protected $globals_access : k_adapter_GlobalsAccess

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

public setContext(k_Context $http_request) : k_Bootstrap

Sets the context to use. Usually, this is an instance of k_HttpRequest.

public setComponentCreator(k_ComponentCreator $components) : k_Bootstrap

Sets the componentcreator to use.

public setCharsetStrategy(k_charset_CharsetStrategy $charset_strategy) : k_Bootstrap

Set the charsetstrategy.

public setIdentityLoader(k_IdentityLoader $identity_loader) : k_Bootstrap

Set the identity loader.

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

protected components() : k_ComponentCreator

protected charsetStrategy() : k_charset_CharsetStrategy

protected identityLoader() : k_IdentityLoader

protected globalsAccess() : k_adapter_GlobalsAccess

interface k_adapter_OutputAccess

methods

abstract, public header(mixed $string [ , mixed $replace [ , mixed $http_response_code ] ] ) : mixed

abstract, public write(mixed $bytes) : mixed

abstract, public endSession() : mixed

class k_adapter_DefaultOutputAccess

implements k_adapter_OutputAccess

methods

public header(mixed $string [ , mixed $replace [ , mixed $http_response_code ] ] ) : mixed

public write(mixed $bytes) : mixed

public endSession() : mixed

interface k_adapter_GlobalsAccess

methods

abstract, public query() : mixed

abstract, public body() : mixed

abstract, public rawHttpRequestBody() : mixed

abstract, public server() : mixed

abstract, public files() : mixed

abstract, public headers() : mixed

class k_adapter_SafeGlobalsAccess

implements k_adapter_GlobalsAccess

properties

protected $charset : k_charset_CharsetStrategy

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 headers() : mixed

protected unMagic(mixed $input) : array

interface k_adapter_CookieAccess

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

class k_adapter_DefaultCookieAccess

implements k_adapter_CookieAccess

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

interface k_adapter_SessionAccess

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

class k_adapter_DefaultSessionAccess

implements k_adapter_SessionAccess

properties

methods

public __construct(k_adapter_CookieAccess $cookie_access) : null

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

class k_adapter_MockSessionAccess

implements k_adapter_SessionAccess

properties

protected $raw : array

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

class k_adapter_MockGlobalsAccess

implements k_adapter_GlobalsAccess

properties

public $query : array

public $body : array

public $rawHttpRequestBody : string

public $server : array

public $headers : 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 headers() : array

public files() : array

class k_adapter_MockCookieAccess extends k_adapter_DefaultCookieAccess

implements k_adapter_CookieAccess

methods

public set(mixed $key, mixed $value [ , mixed $expire [ , mixed $secure [ , mixed $httponly ] ] ] ) : mixed

interface k_adapter_UploadedFileAccess

methods

abstract, public copy(mixed $tmp_name, mixed $path_destination) : mixed

class k_adapter_DefaultUploadedFileAccess

implements k_adapter_UploadedFileAccess

methods

public copy(mixed $tmp_name, mixed $path_destination) : mixed

protected mkdir(mixed $path) : mixed

protected ensureDirectory(mixed $dir) : mixed

class k_adapter_MockUploadedFileAccess

implements k_adapter_UploadedFileAccess

properties

public $actions : mixed

methods

public copy(mixed $tmp_name, mixed $path_destination) : mixed

class k_adapter_UploadedFile

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

interface k_charset_ResponseCharset

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

class k_charset_Utf8

implements k_charset_ResponseCharset

methods

public name() : string

public encode(mixed $utf8_string) : string

class k_charset_Latin1

implements k_charset_ResponseCharset

methods

public name() : mixed

public encode(mixed $utf8_string) : mixed

interface k_charset_CharsetStrategy

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 decodeInput(mixed $input) : mixed

abstract, public responseCharset() : mixed

class k_charset_Utf8CharsetStrategy

implements k_charset_CharsetStrategy

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

public decodeInput(mixed $input) : mixed

public responseCharset() : k_charset_Utf8

class k_charset_Latin1CharsetStrategy

implements k_charset_CharsetStrategy

ISO-8859-1 While this is the native solution for PHP < 6, it isn't recommended for new Konstrukt applications.

methods

public decodeInput(mixed $input) : mixed

public responseCharset() : mixed