
Hello. I want to present the alpha version of the new open-source PHP library for working with primitives (string, integer, float and array) as an object for the habrasoobshchestvo.
Under the cut - a short description, a link to Google code, a description of goals and plans.
I
must say a huge thank you to
greedykid , who helped me in catching a huge number of bugs and covering unit tests by 80%. I think if you liked the library, he deserved karma no less than I did.
')
Thinking out loud
With all my love for PCh, I never understood his devilry and rude attitude of his developers to design.
In one place, they spit on backward compatibility and make it incomprehensible that, in the other, they don’t even try to introduce some coding standards (well, for example, why wouldn’t enter the \ array \ * and \ string \ * functions together with namespaces, but old with time to declare as deprecated?)
Another example of disregard is the Array_Object class, which is simply striking in its scarcity. Well, if you have already begun to do something, 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 possibilities, but full use in work projects, using all the advantages that this approach gives us - full TypeHinting, inheritance, etc.
Also, the goal was to maximize the terrible 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 (more obvious) to use; most methods are subjectively more pleasant to use than inline functions.
I wanted to add a grace to the coarse php-core. And basically, where the language did not become an obstacle, it turned out perfectly
Nuances
Unlike most of these libraries - this library works fine with itself. That is, for example, the 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 that it implies.
In some places we have rested against the limitations of php. For example, when using foreach ($ map as $ key => $ value), the $ key is returned as a primitive value, and not as an object, so an alternative, equally beautiful syntax is recommended: 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 - a user + active bug reporter.
And, of course, I hope that there will be willing to take part in the development of the project. I hope for an early 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 enough to install this extension and there will be no loss of performance from this wrapper. IMHO, it will be a good push.
And there, who knows, maybe eight years later, in Vasyuki, the first interplanetary chess congress in the history of the universe will take place!
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(eg !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
Read more - on Google code. I recommend to see examples - there you can find a lot of interesting things)
A warning
Those who are predictable and sad want to shout “Why reinvent the wheel?”, “OOP for OOP” and “KG / AM” were sent in advance
Fans shout about match optimization sent to learn Assembler
I accept rave reviews and
constructive criticism :)
Links
Discussion of the first alpha version on php.ruNotes
Both bug reports and offers are accepted. I recommend to read the topic with the discussion on the forum php.ru - there you can learn a lot of interesting things about the possibilities of the library. In the same place it is possible to notice that interesting applications quickly enough are realized.
The desire to help in writing code is welcome)
Naturally, while bugs are possible. But then she and the alpha version)
License - LGPL
ps In the course of the article I can edit, add new thoughts.