Gems specific version of the snippet loader

Loads snippets like all other classes in gems first with project prefix, then gems, mutil and when all that fails it will try without prefix from the project\snippets and gems\snippets folders

package Gems
subpackage Snippets
copyright Copyright (c) 2011 Erasmus MC
license New BSD License
since Class available since version 1.5.5
inherited_from \Gems_Loader_TargetLoaderAbstract

 Methods

Sets the source of variables and the first directory for snippets

__construct(mixed $source = null, array $dirs = array()

Parameters

$source

mixed

Something that is or can be made into \MUtil_Registry_SourceInterface, otherwise \Zend_Registry is used.

$dirs

array

prefix => pathname The inital paths to load from

__construct()

__construct(mixed $container, array $dirs) 
Inherited

Parameters

$container

mixed

A container acting as source for \MUtil_Registry_Source

$dirs

array

The directories where to look for requested classes

__get()

__get($name) 
Inherited

Parameters

$name

Add prefixed paths to the registry of paths

addPrefixPath(string $prefix, string $path, boolean $prepend = true) : \MUtil_Snippets_SnippetLoaderInterface

Parameters

$prefix

string

$path

string

$prepend

boolean

Returns

\MUtil_Snippets_SnippetLoaderInterface

Add prefixed paths to the registry of paths

addPrefixPath(string $prefix, $path, boolean $prepend = true) : \Gems_Loader_LoaderAbstract
Inherited

Parameters

$prefix

string

$path

$prepend

boolean

Put path at the beginning of the stack (has no effect when prefix / dir already set)

Returns

\Gems_Loader_LoaderAbstract(continuation pattern)

Called after the check that all required registry values have been set correctly has run.

afterRegistry() : void
Inherited

Allows the loader to set resources.

answerRegistryRequest(string $name, mixed $resource) : boolean
Inherited

Parameters

$name

string

Name of resource to set

$resource

mixed

The resource.

Returns

booleanTrue if $resource was OK

Should be called after answering the request to allow the Target to check if all required registry values have been set correctly.

checkRegistryRequestsAnswers() : boolean
Inherited

Returns

booleanFalse if required values are missing.

Allows the loader to know the resources to set.

getRegistryRequests() : array
Inherited

Returns those object variables defined by the subclass but not at the level of this definition.

Can be overruled.

Returns

arrayof string names

Searches and loads a .php snippet file.

getSnippet(string $filename, array $extraSourceParameters = null) : \MUtil_Snippets_SnippetInterface

Parameters

$filename

string

The name of the snippet

$extraSourceParameters

array

name/value pairs to add to the source for this snippet

Returns

\MUtil_Snippets_SnippetInterfaceThe snippet

Returns a source of values for snippets.

getSource() : \MUtil_Registry_SourceInterface

Returns

\MUtil_Registry_SourceInterface

Remove a prefix (or prefixed-path) from the registry

removePrefixPath(string $prefix, string $path = null) : \MUtil_Snippets_SnippetLoaderInterface

Parameters

$prefix

string

$path

string

OPTIONAL

Returns

\MUtil_Snippets_SnippetLoaderInterface

Sets the source of variables for snippets

setSource(\MUtil_Registry_SourceInterface $source) : \MUtil_Snippets_SnippetLoader

Parameters

$source

\MUtil_Registry_SourceInterface

Returns

\MUtil_Snippets_SnippetLoader(continuation pattern)

Add a subdirectory / sub name to a list of class load paths

_cascadedDirs(array $dirs, string $cascade, boolean $fullClassnameFallback = true) : array
Inherited

Parameters

$dirs

array

prefix => path

$cascade

string

The sub directories to cascade to

$fullClassnameFallback

boolean

Allows full class name specification instead of just plugin name part

Returns

arrayprefix => path

Returns $this->$name, creating the item if it does not yet exist.

_getClass(string $name, string $className = null, array $arguments = array()) : mixed
Inherited

Parameters

$name

string

The $name of the variable to store this object in.

$className

string

Class name or null if the same as $name, prepending $this->_dirs.

$arguments

array

Class initialization arguments.

Returns

mixedInstance of $className

Create or loads the class. When only loading, this function returns a StaticCall object that can be invoked lazely.

_loadClass(string $name, boolean $create = false, array $arguments = array()) : mixed
Inherited
see
see

Parameters

$name

string

The class name, minus the part in $this->_dirs.

$create

boolean

Create the object, or only when an \MUtil_Registry_TargetInterface instance.

$arguments

array

Class initialization arguments.

Returns

mixedA class instance or a \MUtil_Lazy_StaticCall object

Filters the names that should not be requested.

filterRequestNames(string $name) : boolean
Inherited

Can be overriden.

Parameters

$name

string

Returns

boolean

 Properties

 

Static variable for debuggging purposes. Toggles the echoing of what snippets are requested and returned.

$verbose : boolean

Default

false
Static

Sometimes it is hard to find out what snippets will be loaded. Use the verbose option to see what snippets are requested and what the resulting snippet is including the full prefix (if any).

Use: \Gems_Snippets_SnippetLoader::$verbose = true; to enable.

 

The prefix/path location to look for classes.

$_dirs : array

Default

The standard value is

  • => application/classes
  • Gems => library/Gems/classes

But an alternative could be:

  • Demopulse => application/classes
  • Pulse => application/classes
  • Gems => library/Gems/classes
 

$_loader

$_loader : \MUtil_Loader_PluginLoader

Default

 

Allows sub classes of \Gems_Loader_LoaderAbstract to specify the subdirectory where to look for.

$cascade : string

Default

'Snippets'
 

Allows sub classes of \Gems_Loader_LoaderAbstract to specify the subdirectory where to look for.

$cascade : string

Default

null