Skip to content

Commit 9aa6e03

Browse files
author
Andreas Sandberg
committed
Add ability to retrieve single list of class selectors
1 parent 8a7d32a commit 9aa6e03

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

lib/CSSList.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,38 @@ public function getAllDeclarationBlocks() {
206206
public function getAllSelectors() {
207207
return $this->getAllDeclarationBlocks();
208208
}
209-
209+
210+
/**
211+
* Return a list of single class selectors
212+
*
213+
* @return array
214+
*/
215+
public function getSingleClassSelectorList() {
216+
$results = array();
217+
$blocks = $this->getAllDeclarationBlocks();
218+
foreach($blocks as $block)
219+
{
220+
$selectors = $block->getSelectors();
221+
222+
foreach($selectors as $sel)
223+
{
224+
$selctorParts = explode(" ", $sel);
225+
if(count($selctorParts) > 1)
226+
{
227+
continue;
228+
}
229+
230+
//Only accept class selectors
231+
if(preg_match('/^\./', $sel))
232+
{
233+
$results[] = (string)$sel;
234+
}
235+
}
236+
}
237+
return $results;
238+
}
239+
240+
210241
/**
211242
* Returns all CSSRuleSet objects found recursively in the tree.
212243
*/

0 commit comments

Comments
 (0)