setUserStyles() public method

public setUserStyles ( array $userStyles )
$userStyles array
Example #1
0
 public function testGivenInvalidUserStyleNameShouldThrowAnException()
 {
     $color = new Color();
     try {
         $color->setUserStyles(array('foo-bar' => 'red'));
         $this->fail('must throw an InvalidArgumentException');
     } catch (InvalidStyleNameException $e) {
         assertInstanceOf('InvalidArgumentException', $e);
         assertSame('foo-bar is not a valid style name', $e->getMessage());
     }
 }
Example #2
0
#!/usr/bin/env php
<?php 
require_once __DIR__ . '/vendor/autoload.php';
use Colors\Color;
$c = new Color();
// highlight('green') === bg('green') === bg_green()
// white() === fg('white')
echo $c('Hello World!')->white()->bold()->highlight('green') . PHP_EOL;
// using some magic
echo $c('Hello World!')->white->bold->bg_green . PHP_EOL;
// create your own styles
$c->setUserStyles(array('welcome' => array('white', 'bg_green'), 'bye' => 'blue'));
echo $c('Hello World!')->welcome->bold . PHP_EOL;
echo $c('Bye!')->bye . PHP_EOL;
// use style tags
$text = <<<EOF
1 : <welcome>Hello <bold>World!</bold></welcome>
2 : <bye>Bye!</bye>
EOF;
echo $c($text)->colorize() . PHP_EOL;
// center text
$text = 'hello' . PHP_EOL . '✩' . PHP_EOL . 'world';
echo $c($text)->center() . PHP_EOL;
// use standard API
$message = $c->apply('bold', $c->white('Hello World!'));
echo $message . PHP_EOL;
echo $c->clean($message) . PHP_EOL;