PHP Classes

File: hawkphp/stringObj.php

Recommend this page to a friend!
  Classes of tianfan  >  Hawk PHP Extended Object  >  hawkphp/stringObj.php  >  Download  
File: hawkphp/stringObj.php
Role: Class source
Content type: text/plain
Description: class for STRING type
Class: Hawk PHP Extended Object
Manipulating basic data types as objects
Author: By
Last change:
Date: 9 months ago
Size: 3,197 bytes
 

Contents

Class file image Download
<?php
/**
 *@package extendObj
 *@author Tianfan<arrbo@hotmail.com>
 *@license Apache License 2.0
 *@varsion 0.0.2
 *@description this package is a part of hawkphp framework v2(haven't released)
 */
namespace hawkphp;

class
stringObj {

    private
$_string;

    public function
__toString(): string {
        return
$this->_string;
    }

    public function
__construct(string $string) {
       
$this->_string = $string;
    }

    public function
addCslashes(string $charList): stringObj {
        return new
stringObj(\addcslashes($this->_string, $charList));
    }

    public function
addslashes(string $charList): stringObj {
        return new
stringObj(\addslashes($this->_string, $charList));
    }

    public function
bin2hex(): stringObj {
        return new
stringObj(\bin2hex($this->_string));
    }

    public function
length(): intObj {
        return new
intObj(\strlen($this->_string));
    }

    public function
md5(bool $output = false): stringObj {
        return new
stringObj(\md5($this->_string, $output));
    }

    public function
substr(): stringObj {
       
$params = \func_get_args();
        return new
stringObj(\substr($this->_string, ...$params));
    }

    public function
sha1(bool $output = false): stringObj {
        return new
stringObj(\sha1($this->_string, $output));
    }

    public function
chunkSplit(): stringObj {
       
$params = \func_get_args();
        return new
stringObj(chunk_split($this->_string, ...$params));
    }

    public function
crc32(): intObj {
        return new
intObj(\crc32($this->_string));
    }

    public function
crypt(): stringObj {
       
$params = \func_get_args();
        return new
stringObj(\crypt($this->_string, ...$params));
    }

    public function echo():
void {
        echo
$this->_string;
    }

    public function
explode($delimiter): arrayObj {
        return new
arrayObj(\explode($delimiter, $this->_string));
    }

    public function
rtrim(): stringObj {
       
//todo
   
}

    public function
trim(): stringObj {
       
//todo
   
}

    public function
ord(): intObj {
        return new
intObj(ord($this->_string));
    }

    public function
replace(string $repacement, string $replace, int $count = 1): stringObj {
        return new
stringObj(\str_replace($repacement, $replace, $this->_string, $count));
    }

    public function
isEmpty(): bool {
        return empty(
$this->_string) ? true : false;
    }

    public function
test(string $regexp): bool {
        return \
preg_match($regexp, $this->_string);
    }

    public function
match(string $regexp, bool $matchAll = false): ?arrayObj {
       
$match = "";
        if (
$matchAll == false) {
            if (\
preg_match($regexp, $this->_string, $match)) {
                return new
arrayObj($match);
            } else {
                return
false;
            }
        } elseif (
$matchAll == true) {
            if (\
preg_match_all($regexp, $this->_string, $match) != 0) {
                return new
arrayObj($match);
            } else {
                return
false;
            }
        }
    }

    public function
jsonDecode(): object {
        return \
json_decode($this->_string, false);
    }

}

For more information send a message to info at phpclasses dot org.