Esempio n. 1
0
 /**
  * Initializes a Stringy object and assigns both str and encoding properties
  * the supplied values. $str is cast to a string prior to assignment, and if
  * $encoding is not specified, it defaults to mb_internal_encoding(). Throws
  * an InvalidArgumentException if the first argument is an array or object
  * without a __toString method.
  *
  * @param  mixed  $str      Value to modify, after being cast to string
  * @param  string $encoding The character encoding
  *
  * @throws \InvalidArgumentException if an array or object without a
  *         __toString method is passed as the first argument
  */
 public function __construct($str = '', $encoding = null)
 {
     if (is_array($str)) {
         throw new \InvalidArgumentException('Passed value cannot be an array');
     } elseif (is_object($str) && !method_exists($str, '__toString')) {
         throw new \InvalidArgumentException('Passed object must have a __toString method');
     }
     // don't throw a notice on PHP 5.3
     if (!defined('ENT_SUBSTITUTE')) {
         define('ENT_SUBSTITUTE', 8);
     }
     // init
     UTF8::checkForSupport();
     $this->str = (string) $str;
     if ($encoding) {
         $this->encoding = $encoding;
     } else {
         UTF8::mbstring_loaded();
         $this->encoding = mb_internal_encoding();
     }
     if ($encoding) {
         $this->encoding = $encoding;
     } else {
         $this->encoding = mb_internal_encoding();
     }
 }