Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Jan 4, 2024
0 parents commit 3ef69c3
Show file tree
Hide file tree
Showing 16 changed files with 881 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .docker/php/php81/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ----------------------
# The FPM base container
# ----------------------
FROM php:8.1-cli-alpine AS dev

RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS

# Cleanup apk cache and temp files
RUN rm -rf /var/cache/apk/* /tmp/*

# ----------------------
# Composer install step
# ----------------------

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# ----------------------
# The FPM production container
# ----------------------
FROM dev
22 changes: 22 additions & 0 deletions .docker/php/php82/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ----------------------
# The FPM base container
# ----------------------
FROM php:8.2-cli-alpine AS dev

RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS

# Cleanup apk cache and temp files
RUN rm -rf /var/cache/apk/* /tmp/*

# ----------------------
# Composer install step
# ----------------------

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# ----------------------
# The FPM production container
# ----------------------
FROM dev
22 changes: 22 additions & 0 deletions .docker/php/php83/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ----------------------
# The FPM base container
# ----------------------
FROM php:8.3-cli-alpine AS dev

RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS

# Cleanup apk cache and temp files
RUN rm -rf /var/cache/apk/* /tmp/*

# ----------------------
# Composer install step
# ----------------------

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# ----------------------
# The FPM production container
# ----------------------
FROM dev
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto

/.docker export-ignore
/.github export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
/docker-compose.yaml export-ignore
/phpunit.xml.dist export-ignore
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: tests

on: [ push, pull_request ]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.1, 8.2, 8.3 ]
dependency-version: [ prefer-lowest, prefer-stable ]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer install --no-interaction
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit --testdox
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.idea/
/vendor/
.phpunit.result.cache
composer.lock
phpunit.xml
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023, Anton Komarev <anton@komarev.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# PHP Unicode

<p align="center">
<a href="https://github.com/cybercog/php-unicode/releases"><img src="https://img.shields.io/github/release/cybercog/php-unicode.svg?style=flat-square" alt="Releases"></a>
<a href="https://github.com/cybercog/php-unicode/actions/workflows/tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/cybercog/php-unicode/tests.yml?style=flat-square" alt="Build"></a>
<a href="https://github.com/cybercog/php-unicode/blob/master/LICENSE"><img src="https://img.shields.io/github/license/cybercog/php-unicode.svg?style=flat-square" alt="License"></a>
</p>

## Introduction

Streamline Unicode strings and characters (code points) manipulations. Object oriented implementation.

## Installation

Pull in the package through Composer.

```shell
composer require cybercog/php-unicode
```

## Usage

### Instantiate Unicode String

```php
$compositeCharacter = \Cog\Unicode\UnicodeString::of('Hello');
```

`UnicodeString` object will contain a list of Unicode characters.

For example, the Unicode string "Hello" is represented by the code points:
- U+0048 (H)
- U+0065 (e)
- U+006C (l)
- U+006C (l)
- U+006F (o)

### Represent Unicode String

```php
$compositeCharacter = \Cog\Unicode\UnicodeString::of('Hello');

echo strval($compositeCharacter); // (string) "Hello"
```

### Instantiate Unicode Character

```php
$character = \Cog\Unicode\Character::of('ÿ');

$character = \Cog\Unicode\Character::ofDecimal(255);

$character = \Cog\Unicode\Character::ofHexadecimal('U+00FF');

$character = \Cog\Unicode\Character::ofHtmlEntity('&yuml;');

$character = \Cog\Unicode\Character::ofXmlEntity('&#xff;');
```

### Represent Unicode Character in any format

```php
$character = \Cog\Unicode\Character::of('ÿ');

echo strval($character); // (string) "ÿ"

echo $character->toDecimal(); // (int) 255

echo $character->toHexadecimal(); // (string) "U+00FF"

echo $character->toHtmlEntity(); // (string) "&yuml;"

echo $character->toXmlEntity(); // (string) "&#xff;"
```

## License

- `PHP Unicode` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev].

## About CyberCog

[CyberCog] is a Social Unity of enthusiasts. Research the best solutions in product & software development is our passion.

- [Follow us on Twitter](https://twitter.com/cybercog)

<a href="https://cybercog.su"><img src="https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png" alt="CyberCog"></a>

[Anton Komarev]: https://komarev.com
[CyberCog]: https://cybercog.su
47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "cybercog/php-unicode",
"description": "PHP Unicode library",
"type": "library",
"license": "MIT",
"keywords": [
"cog",
"unicode",
"code-point",
"character",
"composite-character",
"symbol",
"emoji",
"html-entity",
"xml-entity"
],
"authors": [
{
"name": "Anton Komarev",
"email": "anton@komarev.com",
"homepage": "https://komarev.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Cog\\Unicode\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\Unit\\Cog\\Unicode\\": "test/"
}
},
"require": {
"php": "^8.1",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.5"
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable" : true
}
34 changes: 34 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.9"
services:
php81:
container_name: php-unicode-lib-81
image: php-unicode-lib
build:
context: ./
dockerfile: ./.docker/php/php81/Dockerfile
tty: true
working_dir: /app
volumes:
- ./:/app

php82:
container_name: php-unicode-lib-82
image: php-unicode-lib
build:
context: ./
dockerfile: ./.docker/php/php81/Dockerfile
tty: true
working_dir: /app
volumes:
- ./:/app

php83:
container_name: php-unicode-lib-82
image: php-unicode-lib
build:
context: ./
dockerfile: ./.docker/php/php81/Dockerfile
tty: true
working_dir: /app
volumes:
- ./:/app
13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./test/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
Loading

0 comments on commit 3ef69c3

Please sign in to comment.