2010-01-11 11:24:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-01-11 11:24:08 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-01-11 11:24:08 +00:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-01-11 11:24:08 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Console\Helper;
|
|
|
|
|
2010-01-11 11:24:08 +00:00
|
|
|
/**
|
|
|
|
* Helper is the base class for all helper classes.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2010-01-11 11:24:08 +00:00
|
|
|
*/
|
|
|
|
abstract class Helper implements HelperInterface
|
|
|
|
{
|
2010-05-19 14:27:53 +01:00
|
|
|
protected $helperSet = null;
|
2010-01-11 11:24:08 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sets the helper set associated with this helper.
|
|
|
|
*
|
|
|
|
* @param HelperSet $helperSet A HelperSet instance
|
|
|
|
*/
|
|
|
|
public function setHelperSet(HelperSet $helperSet = null)
|
|
|
|
{
|
|
|
|
$this->helperSet = $helperSet;
|
|
|
|
}
|
2010-01-11 11:24:08 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Gets the helper set associated with this helper.
|
|
|
|
*
|
|
|
|
* @return HelperSet A HelperSet instance
|
|
|
|
*/
|
|
|
|
public function getHelperSet()
|
|
|
|
{
|
|
|
|
return $this->helperSet;
|
|
|
|
}
|
2012-12-15 15:08:23 +00:00
|
|
|
|
|
|
|
/**
|
2014-12-05 08:50:33 +00:00
|
|
|
* Returns the length of a string, using mb_strwidth if it is available.
|
2012-12-15 15:08:23 +00:00
|
|
|
*
|
|
|
|
* @param string $string The string to check its length
|
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @return int The length of the string
|
2012-12-15 15:08:23 +00:00
|
|
|
*/
|
|
|
|
protected function strlen($string)
|
|
|
|
{
|
2014-04-15 11:04:31 +01:00
|
|
|
if (!function_exists('mb_strwidth')) {
|
2012-12-15 15:08:23 +00:00
|
|
|
return strlen($string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false === $encoding = mb_detect_encoding($string)) {
|
|
|
|
return strlen($string);
|
|
|
|
}
|
|
|
|
|
2014-04-15 11:04:31 +01:00
|
|
|
return mb_strwidth($string, $encoding);
|
2012-12-15 15:08:23 +00:00
|
|
|
}
|
2010-01-11 11:24:08 +00:00
|
|
|
}
|