예제 #1
0
 /**
  * Initializes a new instance of that class.
  *
  * @param string $path The path of the file.
  * @param string $mode The mode
  *
  * @throws IOException File could not be opened.
  */
 public function __construct($path, $mode = 'r+')
 {
     $path = ClrString::asString($path);
     $res = \fopen((string) $path, ClrString::valueToString($mode, false));
     if (false === $res) {
         $this->throwIOException('Could not open file!');
     }
     $this->_file = $path;
     parent::__construct($res, true);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public final function joinToStringCallback($separatorFactory = null, $defValue = '')
 {
     if (null === $separatorFactory) {
         $separatorFactory = function () {
             return '';
         };
     }
     $separatorFactory = static::asCallable($separatorFactory);
     $result = $this->iterateWithItemContext(function ($x, IEachItemContext $ctx) use(&$hasItems, $separatorFactory) {
         $hasItems = true;
         $str = $ctx->result();
         if (!$ctx->isFirst()) {
             $str .= $separatorFactory($x, $ctx);
         } else {
             $str = '';
         }
         $str .= ClrString::valueToString($x);
         $ctx->result($str);
     }, $defValue);
     return ClrString::asString($result, false);
 }