Last active
April 12, 2017 01:26
-
-
Save solleer/0e447db42d92662838ab to your computer and use it in GitHub Desktop.
Transphporm Readable Formatter
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
<?php | |
namespace Config\Transphporm\Readable; | |
class Readable { | |
private function camelCase($val) { | |
$words = preg_split('/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/', $val); | |
return implode(' ', $words); | |
} | |
public function readable($val, $splitOnDashes = false) { | |
$val = $this->camelCase($val); | |
$val = str_replace('_', ' ', $val); | |
if ($splitOnDashes) $val = str_replace('-', ' ', $val); | |
$val = ucwords($val); | |
return $val; | |
} | |
} |
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
<?php | |
namespace Config\Transphporm\Readable; | |
class Module implements \Transphporm\Module { | |
public function load(\Transphporm\Config $config) { | |
$config->registerFormatter(new Readable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment