SORT_ASC
SORT_ASC
Sort files in alphabetical ascending order
Pico
Pico is a stupidly simple, blazing fast, flat file CMS.
__construct(string $rootDir, string $configDir, string $pluginsDir, string $themesDir)
Constructs a new Pico instance
To carry out all the processing in Pico, call Pico::run().
string | $rootDir | root directory of this Pico instance |
string | $configDir | config directory of this Pico instance |
string | $pluginsDir | plugins directory of this Pico instance |
string | $themesDir | themes directory of this Pico instance |
run() : string
Runs this Pico instance
Loads plugins, evaluates the config file, does URL routing, parses meta headers, processes Markdown, does Twig processing and returns the rendered contents.
thrown when a not recoverable error occurs
rendered Pico contents
getPlugin(string $pluginName) : object
Returns the instance of a named plugin
Plugins SHOULD implement PicoPluginInterface, but you MUST NOT rely on it. For more information see PicoPluginInterface.
string | $pluginName | name of the plugin |
thrown when the plugin wasn't found
instance of the plugin
setConfig(array<mixed,mixed> $config) : void
Sets Pico's config before calling Pico::run()
This method allows you to modify Pico's config without creating a {@path "config/config.php"} or changing some of its variables before Pico starts processing.
You can call this method between Pico::__construct() and Pico::run() only. Options set with this method cannot be overwritten by {@path "config/config.php"}.
array<mixed,mixed> | $config | array with config variables |
thrown if Pico already started processing
getConfig(string $configName = null) : mixed
Returns either the value of the specified config variable or the config array
string | $configName | optional name of a config variable |
returns either the value of the named config variable, null if the config variable doesn't exist or the config array if no config name was supplied
load404Content(string $file) : string
Returns the raw contents of the first found 404 file when traversing up from the directory the requested file is in
string | $file | path to requested (but not existing) file |
thrown when no suitable 404 file is found
raw contents of the 404 file
getMetaHeaders() : array<mixed,string>
Returns known meta headers and triggers the onMetaHeaders event
Heads up! Calling this method triggers the onMetaHeaders
event.
Keep this in mind to prevent a infinite loop!
known meta headers; the array value specifies the YAML key to search for, the array key is later used to access the found value
parseFileMeta(string $rawContent, array<mixed,string> $headers) : array
Parses the file meta from raw file contents
Meta data MUST start on the first line of the file, either opened and
closed by ---
or C-style block comments (deprecated). The headers are
parsed by the YAML component of the Symfony project, keys are lowered.
If you're a plugin developer, you MUST register new headers during the
onMetaHeaders
event first. The implicit availability of headers is
for users and pure (!) theme developers ONLY.
string | $rawContent | the raw file contents |
array<mixed,string> | $headers | known meta headers |
thrown when the meta data is invalid
parsed meta data
prepareFileContent(string $rawContent, array $meta) : string
Applies some static preparations to the raw contents of a page, e.g. removing the meta header and replacing %base_url%
string | $rawContent | raw contents of a page |
array | $meta | meta data to use for %meta.*% replacement |
contents prepared for parsing
getPageUrl(string $page, array|string $queryData = null) : string
Returns the URL to a given page
string | $page | identifier of the page to link to |
array|string | $queryData | either an array containing properties to create a URL-encoded query string from, or a already encoded string |
URL
loadPlugins() : void
Loads plugins from Pico::$pluginsDir in alphabetical order
Plugin files MAY be prefixed by a number (e.g. 00-PicoDeprecated.php) to indicate their processing order. Plugins without a prefix will be loaded last. If you want to use a prefix, you MUST consider the following directives:
onPageRendered
eventthrown when a plugin couldn't be loaded
evaluateRequestUrl() : void
Evaluates the requested URL
Pico 1.0 uses the QUERY_STRING
routing method (e.g. /pico/?sub/page
)
to support SEO-like URLs out-of-the-box with any webserver. You can
still setup URL rewriting (e.g. using mod_rewrite
on Apache) to
basically remove the ?
from URLs, but your rewritten URLs must follow
the new QUERY_STRING
principles. URL rewriting requires some special
configuration on your webserver, but this should be "basic work" for
any webmaster...
Pico 0.9 and older required Apache with mod_rewrite
enabled, thus old
plugins, templates and contents may require you to enable URL rewriting
to work. If you're upgrading from Pico 0.9, you will probably have to
update your rewriting rules.
We recommend you to use the link
filter in templates to create
internal links, e.g. {{ "sub/page"|link }}
is equivalent to
{{ base_url }}/sub/page
and {{ base_url }}?sub/page
, depending on
enabled URL rewriting. In content files you can use the %base_url%
variable; e.g. %base_url%?sub/page
will be replaced accordingly.
readPages() : void
Reads the data of all pages known to Pico
The page data will be an array containing the following values:
Array key | Type | Description |
---|---|---|
id | string | relative path to the content file |
url | string | URL to the page |
title | string | title of the page (YAML header) |
description | string | description of the page (YAML header) |
author | string | author of the page (YAML header) |
time | string | timestamp derived from the Date header |
date | string | date of the page (YAML header) |
date_formatted | string | formatted date of the page |
raw_content | string | raw, not yet parsed contents of the page |
meta | string | parsed meta data of the page |
registerTwig() : void
Registers the twig template engine
This method also registers Picos core Twig filters link
and content
as well as Picos PicoTwigExtension Twig extension.
getFiles(string $directory, string $fileExtension = '', integer $order = self::SORT_ASC) : array
Recursively walks through a directory and returns all containing files matching the specified file extension
string | $directory | start directory |
string | $fileExtension | return files with the given file extension only (optional) |
integer | $order | specify whether and how files should be sorted; use Pico::SORT_ASC for a alphabetical ascending order (this is the default behaviour), Pico::SORT_DESC for a descending order or Pico::SORT_NONE to leave the result unsorted |
list of found files
triggerEvent(string $eventName, array $params = array()) : void
Triggers events on plugins which implement PicoPluginInterface
Deprecated events (as used by plugins not implementing \IPocPlugin) are triggered by \PicoDeprecated.
string | $eventName | name of the event to trigger |
array | $params | optional parameters to pass |