PHP Classes

File: src/Create.php

Recommend this page to a friend!
  Classes of Lars Moelleken   Stringy   src/Create.php   Download  
File: src/Create.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Stringy
Manipulate strings encoded using Unicode
Author: By
Last change:
Date: 3 years ago
Size: 1,422 bytes
 

Contents

Class file image Download
<?php

namespace Stringy;

if (!\
function_exists('Stringy\create')) {
   
/**
     * Creates a Stringy object and returns it on success.
     *
     * @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
     *
     * @return Stringy A Stringy object
     */
   
function create($str, string $encoding = null)
    {
        return new
Stringy($str, $encoding);
    }
}

if (!\
function_exists('Stringy\collection')) {
   
/**
     * @param string[]|Stringy[]|null $input
     *
     * @throws \TypeError
     *
     * @return CollectionStringy<int,Stringy>
     */
   
function collection($input = null)
    {
       
// init
       
$newCollection = new CollectionStringy();

        if (
$input === null) {
            return
$newCollection;
        }

       
/**
         * @psalm-suppress DocblockTypeContradiction
         */
       
if (!\is_array($input)) {
           
$input = [$input];
        }

        foreach (
$input as &$stringOrStringy) {
            if (\
is_string($stringOrStringy)) {
               
$stringOrStringy = new Stringy($stringOrStringy);
            }

           
$newCollection[] = $stringOrStringy;
        }

        return
$newCollection;
    }
}