Releases: TimeToogo/Pinq
PINQ V3.0.0
-
Query functions are passed each value with their associated key as the second parameter while
maintaining support for single parameter internal functions. -
Proper support for non scalar keys:
- Non scalar keys will be automatically converted to integers when foreach'd or converted to an array.
- Added
ITraversable::iterateto iterate all unaltered values and keys - Added
ITraversable::keysselect the keys andITraversable::reindexto reindex the values by their 0-based position - Added
ITraversable::getTrueIteratorto get the iterator for all values and unaltered keys.
-
Refactored iterator structure:
- Abstracted iterator implementations under
Iterators\IIteratorScheme. - Now supports generators for performance improvement and reduced memory usage for >= PHP 5.5.0
- Will fall back to iterators for <= PHP 5.5.0
- Native iterators have also been improved with regards to performance.
- Abstracted iterator implementations under
-
Implemented new
ITraversablesource semantics:-
A source
ITraversableis the instance containing the original underlying elements. -
Added
ITraversable::isSource, returns whether the instance is the sourceITraversable.$elements = Traversable::from(range(1, 100)); $elements->isSource(); //true $someElements = $elements->where(function ($i) { return $i > 50; }); $someElements->isSource(); //false
-
Added
ITraversable::getSource, returns the sourceITraversableor itself if it is the source. -
Removed unnecessary caching in
Traversablequeries.Traversablecan be used with nondeterministic/mutable sources and query parameters.Traversableclasses can longer be serialized when queried with closures.- Because of this combined with covariant return types,
ICollectionhas new and improved mutable query API:
$collection = Collection::from(range(1, 10)); $collection ->where(function ($i) { return $i >= 5; }) ->apply(function (&$i) { $i *= 10; }); $collection->asArray();//[1, 2, 3, 4, 50, 60, 70, 80, 90, 100] $collection /* ... */ ->clear(); //Is equivalent to: $collection ->removeRange(/* ... */);
-
-
Removed
ITraversable::asQueryable,ITraversable::asRepository, updated interfaces annotations
with covariant return types.ITraversable,ICollection,IQueryable,IRepositoryshould all return
their respective types for each query method. -
Moved/Implemented Necessary interfaces (
IOrdered*,IJoiningOn*,IJoiningTo*) with covariant
return types underInterfacesnamespace. -
Removed
IGroupedTraversable, useITraversable::groupByreturning an array instead. -
ITraversable::groupByimplicitly indexes each group by the group key. -
Changed
ITraversable::existsin favour ofITraversable::isEmpty. -
Traversable/Collectionare now extendable. -
IJoiningOnTraversable::onEqualitywill not matchnulls as equal as in C#. -
Implemented optional default value for
ITraversable::join/ITraversable::groupJoin:- The following join query:
Traversable::from(range(1, 6)) ->join(range(1, 20)) ->on(function ($outer, $inner) { return $outer % 2 === 0 && $outer * 2 === $inner; }) ->withDefault('<Odd>') ->to(function ($outer, $inner) { return $outer . ':' . $inner; });
Will produce:
['1:<Odd>', '2:4', '3:<Odd>', '4:8', '5:<Odd>', '6:12'] -
Added
join(...)->apply(...)operation forICollection/IRepository -
Added
ICollection::removeto remove all occurrences of the supplied value from the collection. -
Made order by
Directionconstants interchangeable with nativeSORT_ASC/SORT_DESC. -
Shorten expression getter names by removing redundant
...Expression. -
Restructured and improved function parsing
- New function reflection API
- Correctly handle resolving magic constants (
__DIR__...) and scopes (self::...). - Largely improved signature matching using all reflection data to resolve to the correct function.
Functions now have to be defined on the same line with identical signatures to cause an ambiguity. - Fixed fully qualified namespace detection in AST parsing.
- Upgraded to
nikic/php-parserV1.0.0 with compatibility for 5.6 syntax features. - Updated namespace:
Parsing\PHPParsertoParsing\PhpParser.
-
Improved query representations (
Queriesnamespace)- New builder API (under
Builders) to build query objects from expression trees.
Queryable/Repositorynow only construct the query expression tree.
These classes parse the expression tree into the equivalent query structure. - Query parameters are now externalized from the query object. Under a
IParameterRegistryinstance. - New common
ISourceinterface for a another sequence inside a query:->intersect(...) - Removed
FunctionExpressionTreein favour of dedicated function types (underQueries\Functionsnamespace)
for all types of functions in a query:ElementProjection:->select(function ($value, $key) { return ... })ElementMutator:->apply(function (&$value, $key) { ... })ConnectorProjection:->join(...)->to(function ($outerValue, $innerValue, $outerKey, $innerKey) { return ... })ConnectorMutator:->join(...)->apply(function (&$outerValue, $innerValue, $outerKey, $innerKey) { ... })Aggregator:->aggregate(function ($aggregate, $value) { return ... })
- New
ISourceInfoto store source information of aIQueryable. - Refactored
Segments\OrderByquery segment by representing each
function and direction as anQueries\Segments\OrderFunctionclass. - Renamed
Segments\Operation::getTraversabletogetValues - Refactored
Joinquery segments / operations.- Refactored inheritance to composition, extracted join filtering to interface
Queries\Common\Join\IFilter. - Created class containing common join options:
Queries\Common\Join\Options.
- Refactored inheritance to composition, extracted join filtering to interface
- Extracted interfaces from
Request/Operation/Segmentvisitor classes.
- New builder API (under
-
Removed obsolete query providers (
Loadable,Caching) in favour of a new integrated helperProviders\Utilities\IQueryResultCollection -
Implemented new DSL query provider under
Providers\DSL. -
Implemented new static analysis tools and infrastructure for expression trees under the
Analysisnamespace. -
New structure of query providers
RepositoryProviderdecorates theQueryProvider- New configuration classes (under
Providers\Configurationnamespace) - Integrated with
Caching\IQueryCacheandQueries\Builders\*.
-
New expression classes:
UnsetExpression,StaticFieldExpression,ConstantExpression,ClassConstantExpression -
Refactored
ArrayExpressionby creatingArrayItemExpressionrepresenting each element. -
Refactored
ClosureExpressionby creatingClosureUsedVariableExpressionrepresenting each used variable and supports references. -
Updated expression simplification to use compilation +
evalwith anIEvaluationContext, integrated into reflection and query API. -
Ensure PSR-2 code guidelines adherence.
-
Fixed binary operation
instanceofcompilation bug with literal class names. -
Refactored caching implementation:
Caching\Providerrenamed toCaching\CacheProviderCaching\IQueryCachenow acts as a wrapper toCaching\ICacheAdapter.- Any type of value can be cached and retrieved through the cache adapter.
- Implemented cache namespacing API.
-
Fixed issue with
ITraversable::unionnot reindexing keys. -
Fixed issue with
Iterators\Common\Setnot detecting null values.