• This repository has been archived on 02/Nov/2018
  • Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    PHP
  • Created about 11 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fixing the gaps in PHP's OO approach

Syngr Build Status Coverage Status

Syngr : SYNtactic suGaR

This project is an effort to consolidate PHP's wildly varying functions, and provide some sort of Standard Library for it.

Usage

The idea is to make programming in PHP simpler, and force it to behave in a more predictable manner. Most, if not all, methods for these types all operate on the object itself, which gives us a nice side-benefit of being able to chain multiple methods on an object.

String methods

$string = new String('hello world');
echo $string->uppercase()       // HELLO WORLD
            ->substring(0, 6)   // HELLO
            ->replace(' ', '?') // HELLO?
            ->trim('?');        // HELLO

Array conversion

join()
split()

Comparison

match()

Encoding

Hashing

hash($algorithm_name)
    where $algorithm_name can be anything from [here](http://www.php.net/manual/en/function.hash.php).

bcrypt($cost)
    where $cost is an integer between 4 and 31

HTML

Searching

String Formatting

Substring

substring($start, $length)
    where $start is the index to start the substring and $length is the length of the substring.

Text Formatting

trim()
uppercase()
lowercase()
pad()
length()
reverse()
replace()

Number methods

$number = new Number(6.9);
echo $number->ceiling()              // 7
            ->max(array(5, 9, 49.1)) // 49.1
            ->floor()                // 49
            ->sqrt()                 // Value
            ->value();               // Get raw value rather than string

Algebraic functions

absolute()
ceiling()
floor()
round()
max()
min()
sqrt()

Conversions

convert()

Random

random()

Transcendental functions

exp()
log()
pow()

Trigonometric

cos()
sin()
tan()

Project Setup

Clone the project somewhere, cd to the directory and type in composer install.

Syngr's dependencies are listed in the composer.json file, but if you're installing as a user then it has no extra dependencies (whoop!).

The best way to see Syngr in action is to look at the test code // Add an examples folder.

Testing

Unit Tests

Run phpunit from the terminal in the project folder to run unit tests.

Integration Tests

  1. Run other local services / provide credentials for external services.
  2. rake spec:integration

Documentation

From the project folder, type in php vendor/bin/sami.php update gen-docs.php. The documentation will be generated in a folder called 'docs'.

Troubleshooting & Useful Tools

Examples of common tasks

e.g.

  • How to make curl requests while authenticated via oauth.
  • How to monitor background jobs.
  • How to run the app through a proxy.

Contributing changes

  • Internal git workflow
  • Pull request guidelines
  • Tracker project
  • irc channel
  • Please open issues on the repo tracker for any incorrect behaviour, or better yet, make a pull request with a failing test case 😄

License

This project is licensed under the MIT License.