/** * Split the given input into tokens using whitespace as splitter * * The input can be a string or a tokenRegistry. If the input is a * TokenRegistry, each item will be tokenized. * * @param string|\Org\Heigl\Hyphenator\Tokenizer\TokenRegistry $input The * input to be tokenized * * @return \Org\Heigl\Hyphenator\Tokenizer\TokenRegistry */ public function run($input) { if ($input instanceof TokenRegistry) { // Tokenize a TokenRegistry foreach ($input as $token) { if ($token instanceof WhitespaceToken) { continue; } $newTokens = $this->_tokenize($token->get()); if ($newTokens == array($token)) { continue; } $input->replace($token, $newTokens); } return $input; } // Tokenize a simple string. $array = $this->_tokenize($input); $registry = new TokenRegistry(); foreach ($array as $item) { $registry->add($item); } return $registry; }