Core Function ClassList
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> ClassList( <expression> ) </pre> === Description === Return an array of all user defined classes (Or just ones fitting a given pattern). ==== expression ==== Optional; ...") |
|||
(3 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | ClassList( <expression> ) | + | ClassList( <expression>, <inherits> ) |
</pre> | </pre> | ||
Line 10: | Line 10: | ||
Optional; Text to find contained in the class names or a regex to match against the class names. | Optional; Text to find contained in the class names or a regex to match against the class names. | ||
+ | |||
+ | ==== inherits ==== | ||
+ | |||
+ | Optional; Checks the inheritance of the classes as well for matches given here (must be a complete class name) | ||
=== Return Value === | === Return Value === | ||
Line 24: | Line 28: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | // Define a few user | + | // Define a few user classes |
− | + | Class moo { }; | |
− | + | Class cat { }; | |
− | + | Class dog { }; | |
− | + | Class fox9 { }; | |
− | + | ||
− | // All | + | // All classes |
− | foreach( | + | foreach(ClassList() as $c) |
{ | { | ||
println("F: " . $c); | println("F: " . $c); | ||
} | } | ||
println("Loop complete\n"); | println("Loop complete\n"); | ||
− | + | ||
− | // All | + | // All classes that contain "at" |
− | foreach( | + | foreach(ClassList("at") as $c) |
{ | { | ||
println("F: " . $c); | println("F: " . $c); | ||
} | } | ||
println("Loop complete\n"); | println("Loop complete\n"); | ||
− | + | ||
− | // All | + | // All classes that match the regex pattern \w+\d |
− | foreach( | + | foreach(ClassList(m/\w+\d/) as $c) |
{ | { | ||
println("F: " . $c); | println("F: " . $c); |
Latest revision as of 09:25, 19 June 2015
ClassList( <expression>, <inherits> )
Contents |
Description
Return an array of all user defined classes (Or just ones fitting a given pattern).
expression
Optional; Text to find contained in the class names or a regex to match against the class names.
inherits
Optional; Checks the inheritance of the classes as well for matches given here (must be a complete class name)
Return Value
Success: Returns an array of the found classes.
Failure: Returns an empty array.
Remarks
None.
Example
// Define a few user classes Class moo { }; Class cat { }; Class dog { }; Class fox9 { }; // All classes foreach(ClassList() as $c) { println("F: " . $c); } println("Loop complete\n"); // All classes that contain "at" foreach(ClassList("at") as $c) { println("F: " . $c); } println("Loop complete\n"); // All classes that match the regex pattern \w+\d foreach(ClassList(m/\w+\d/) as $c) { println("F: " . $c); } println("Loop complete\n");