Over time - as the importance of multibyte encoding support grew - a variety of extensions appeared. While each achieves its goal somewhat differently and might be preferred over the other, they still all do that one thing. What can a framework provide, those extensions aren't? It can provide abstractions that allow portable code. While this might not be a requirement for application code, it's a definite must for the framework's core code. As previously mentioned extensions appeared in a semi-evolutionary way. This leaves us with the situation where extensions are heterogeneously spread out over environments. There certainly is no clear winner and we're left with the situation of "supporting them all". Technically this class does very little in terms of abstraction. Its main purpose is to allow adapting to changing environments: virtually creating something you can rely on, something that's always there while it actually is there only in one way or the other. And - yes - some convenience methods are also on board.
Inheritance: extends lithium\core\Adaptable
 public function apply($testable, array $config = array())
 {
     extract($config += $this->config);
     foreach ($testable->lines() as $i => $line) {
         $tabBounty = substr_count($line, "\t") * ($tabWidth - 1);
         $strlen = Multibyte::strlen($line, array('name' => 'li3_quality'));
         $totalLength = $length = $tabBounty + $strlen;
         if ($totalLength > $hardLimit) {
             $this->addViolation(array('message' => "Maximum line length of {$hardLimit} exceeded", 'line' => $i + 1, 'position' => $length));
         } elseif ($softLimit && $totalLength > $softLimit) {
             $this->addWarning(array('message' => "Soft line length of {$softLimit} exceeded", 'line' => $i + 1, 'position' => $length));
         }
     }
 }
 public function apply($testable, array $config = array())
 {
     $message = "Trailing whitespace found";
     $lines = $testable->lines();
     foreach ($lines as $i => $line) {
         $name = 'li3_quality';
         $length = Multibyte::strlen($line, compact('name'));
         $lengthTrimmed = Multibyte::strlen(rtrim($line), compact('name'));
         if ($length !== $lengthTrimmed) {
             $this->addViolation(array('message' => $message, 'line' => $i + 1, 'position' => $length));
         }
     }
     if (empty($line)) {
         $this->addViolation(array('message' => $message, 'line' => count($lines)));
     }
 }
Esempio n. 3
0
 * Adds locale specific rules through the `Catalog` class. You can load more
 * locale dependent rules into the by specifying them manually or retrieving
 * them with the `Catalog` class.
 *
 * Enables support for multibyte strings through the `Multibyte` class by
 * overwriting rules (currently just `lengthBetween`).
 *
 * @see lithium\g11n\Catalog
 * @see lithium\g11n\Multibyte
 * @see lithium\util\Validator
 */
foreach (array('phone', 'postalCode', 'ssn') as $name) {
    Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
Validator::add('lengthBetween', function ($value, $format, $options) {
    $length = Multibyte::strlen($value);
    $options += array('min' => 1, 'max' => 255);
    return $length >= $options['min'] && $length <= $options['max'];
});
/**
 * In-View Translation
 *
 * Integration with `View`. Embeds message translation aliases into the `View`
 * class (or other content handler, if specified) when content is rendered. This
 * enables translation functions, i.e. `<?=$t("Translated content"); ?>`.
 *
 * @see lithium\g11n\Message::aliases()
 * @see lithium\net\http\Media
 */
Media::applyFilter('_handle', function ($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
 public function testSubstr()
 {
     Multibyte::substr('abcab', 1);
     $result = $this->adapter->testSubstrArgs;
     $expected = array('abcab', 1, null);
     $this->assertEqual($expected, $result);
     Multibyte::substr('abcab', 1, 2);
     $result = $this->adapter->testSubstrArgs;
     $expected = array('abcab', 1, 2);
     $this->assertEqual($expected, $result);
 }
Esempio n. 5
0
<?php

/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2011, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */
use lithium\core\Libraries;
use lithium\g11n\Multibyte;
Libraries::paths(array('rules' => array('{:library}\\extensions\\qa\\rules\\{:class}\\{:name}', '{:library}\\qa\\rules\\{:class}\\{:name}' => array('libraries' => 'li3_quality'))));
Multibyte::config(array('li3_quality' => array('adapter' => 'Mbstring')));