
Object-oriented PHP

Under the cut - a short description, a link to Google code, a description of goals and plans.
I must say many thanks to greedykid , who helped me catch a huge number of bugs and cover unit tests by 80%. I think if you liked the library, it deserved karma no less than I did.
Thinking out loud
With all my love for php, I never understood the slightly disregard and rude attitude of his developers towards design.
In one place, they spit on backward compatibility and make it incomprehensible that, in another, they don’t even try to introduce some kind of coding standards (well, for example, why you wouldn’t enter \ array \ * and \ string \ * functions with namespaces, but declare the old ones to be deprecated over time?)
Another example of a disregarding attitude is the Array_Object class, which simply amazes with its meagerness. Well, if you already undertook to do, then why not do it seriously and gracefully?
Goals
The goals of this wrapper, unlike most wrappers of this type, are not a demonstration of capabilities, but full use in working projects, using all the advantages that this approach gives us - full TypeHinting, inheritance, etc.
Also, the goal was to maximize the dreadful names of functions and inconsistency of methods. There was an attempt to introduce a naming style and order of method arguments.
Some methods, in my opinion, have become much easier to use (more obvious), most methods are subjectively more pleasant to use than the built-in functions.
I just wanted to add grace to the crude php-core. And basically, where the language did not become an obstacle, it worked out perfectly
Nuances
Unlike most of these libraries - this library works fine with itself. That is, for example, Map will consider as one value that new String ("abc"), that "abc". That is, $ map ["key"] and $ map [new String ("key")] are equivalent.
Since these are objects, all values are passed by reference. With all the consequences.
In some places we ran into php restrictions. For example, when using foreach ($ map as $ key => $ value) $ key is returned as a primitive value and not as an object, therefore it is recommended to use an alternative, no less beautiful syntax: while ($ map-> each ($ key, $ value) ) {} or $ map-> loop (function ($ key, $ value) {}), which can be used without leaving the call chain.
Plans and hopes
I hope that many will like this library. Someone wants to be just a user, someone wants to be a user + an active bug reporter.
And, of course, I hope that there are those who wish to participate in the development of the project. I hope for a speedy release of a more or less stable version.
After that, I would like to see an extension in C corresponding to the interfaces of this lib. It will be generally excellent. On small projects, you can use the php code, knowing that if the project grows and becomes large it will be enough to install this extension and there will be no performance loss from this wrapper. IMHO, this will be a good push.
And there, as you know, maybe eight years later the first interplanetary chess congress in the history of the universe will take place in Vasyuki!
Code example
$map
->clear(function ($key, $val) {
// Удалим все элементы, где ключ равен значению
return !$key->equals($val);
})
->join(' ') // String
->replace(',', 'зпт')
->pregReplace('/([0-9]+)/', function ($m) {
return "!$m[0]!"; // Some string with number(e.g. !12345!), is here
})
->changeCase(Str::TITLE, Str::UP_FORCED)
->insert('[вставлено]', 5)
->length() // Number
->multiply(4)
->add(6, 9, new Number(15))
->divided(5)
->sum(Number::EVEN)
->dump() // (Number) 1062.51
->root(4)
->round(3) // Just 3 symbols after dot
->dump() // (Number) 5.709
->round(Number::UP) // round to up (ceil)
->hex('15abbf')
->toString() // String ('1420223')
->hash() // 'md5' as default
->dump(); // (String) '0d1b1558224c8f3b125cd905c378c9f7'
// Смотрите «KurrencyKonverter.php» в примерах
$uah = new KurrencyKonverter (500); // KurrencyKonverter extends Number
// Сколько долларов у нас будет, если мы купим их в Украине за 500 гривень
echo $uah
->copy()
->convert('Currency.Ua.Sell', 'UAH', 'USD')
->toString(2); // 63,02
// Сколько долларов у нас будет, если мы купим в Украине за 500 гривень рубли, а потом в России за эти же рубли - доллары
echo $uah
->convert('Currency.Ua.Sell', 'UAH', 'RUR')
->convert('Currency.Ru' , 'RUR', 'USD')
->toString(2); // 44,77
More details on Google code. I recommend to look at examples - there you can find a lot of interesting things)
Warning
Predskazueumye and dull willing to shout "Why reinvent the wheel?", "The PLO for the PLO" and "KG / AM" pre-sent mat
fans to shout about match optimize sent to study Assembler
accept rave reviews and constructive criticism :)
References
Discussion of the first alpha version on php.ru
Google code project
Notes
Both bug reports and offers are accepted. I recommend reading the topic with discussion on the php.ru forum - there you can find out a lot of interesting things about the library features. There you can see that interesting applications quickly come to life.
The desire to help in writing code is welcome)
Naturally, while bugs are possible. But for that it is the alpha version)
License - LGPL
ps. In the course of the article I can edit, add new thoughts