Skip to content

Instantly share code, notes, and snippets.

@solleer
Last active April 12, 2017 01:26
Show Gist options
  • Save solleer/0e447db42d92662838ab to your computer and use it in GitHub Desktop.
Save solleer/0e447db42d92662838ab to your computer and use it in GitHub Desktop.
Transphporm Readable Formatter
<?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;
}
}
<?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