This repository has been archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from PackageFactory/feature/addClassNamesHelper
FEATURE: add `AtomicFusion.classNames` eel-helper
- Loading branch information
Showing
3 changed files
with
118 additions
and
10 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
Classes/PackageFactory/AtomicFusion/Eel/AtomicFusionHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
namespace PackageFactory\AtomicFusion\Eel; | ||
|
||
/** | ||
* This file is part of the PackageFactory.AtomicFusion package | ||
* | ||
* (c) 2016 | ||
* Wilhelm Behncke <[email protected]> | ||
* Martin Ficzel <[email protected]> | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Eel\ProtectedContextAwareInterface; | ||
|
||
/** | ||
* AtomicFusion EEl-Helper | ||
* | ||
* @api | ||
*/ | ||
class AtomicFusionHelper implements ProtectedContextAwareInterface | ||
{ | ||
/** | ||
* Render the arguments as class-names after applying some rules | ||
* | ||
* @param mixed $arguments [optional] class-name rules | ||
* argument rules: | ||
* - falsy: (null, '', [], {}) -> not rendered | ||
* - array: all items that are scalar and truthy are rendered as class-name | ||
* - object: keys that have a truthy values are rendered as class-name | ||
* - scalar: is cast to string and rendered as class-name | ||
*/ | ||
public function classNames(...$arguments) | ||
{ | ||
$classNames = []; | ||
foreach ($arguments as $argument) { | ||
if ((bool)$argument === true) { | ||
if (is_array($argument)) { | ||
$keys = array_keys($argument); | ||
$isAssoc = array_keys($keys) !== $keys; | ||
if ($isAssoc) { | ||
foreach ($argument as $className => $condition) { | ||
if ((bool)$condition === true) { | ||
$classNames[] = (string)$className; | ||
} | ||
} | ||
} else { | ||
foreach ($argument as $className) { | ||
if (is_scalar($className) && !!is_bool($condition) && (bool)$className === true) { | ||
$classNames[] = (string)$className; | ||
} | ||
} | ||
} | ||
} elseif (is_scalar($argument) && !is_bool($argument)) { | ||
$classNames[] = (string)$argument; | ||
} | ||
} | ||
} | ||
return implode(' ', $classNames); | ||
} | ||
|
||
public function allowsCallOfMethod($methodName) | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters