electricjones / data-manager Goto Github PK
View Code? Open in Web Editor NEWSimple data manager for nested data and dot notation access, plus optional extras
License: MIT License
Simple data manager for nested data and dot notation access, plus optional extras
License: MIT License
extend Illuminate/Support/Collections for more access features.
The best way to do this is to make things like namespace and fallback traits so we can use multiple composition.
ManagesItemsTrait::getIfExists()
should only return not found message if the item has not been set at all. null
is a valid datatype.
Break up Manager
into another ArrayableTrait.
In the following scenario:
$manager = new Manager(['one' => 1]);
$manager->add("one.two", "two-value");
An error is fired because we are trying to nest under an already existing "one" which is scalar and not an array. There should be a check and a more helpful exception thrown instead.
It should be possible to hydrate an instance from json. Maybe one of:
$manager->fromJson($json);
$manager->resetFromJson($json);
$manager->initFromJson($json);
A CollectionTrait
extends ManagesItemsTrait
and adds several helper methods:
There is no need to recreate the wheel, though. Import Stringy and some Array helper and user Illuminate\Support\Collection
to fill in the rest of the holes
Wish list
flatten()
Get a flattened array of the items in the collection.flip()
Flip the items in the collection.diff(mixed $items)
Diff the collection with the given items.each(callable $callback)
Execute a callback over each item.filter(callable $callback = null)
Run a filter over each of the items.groupBy(callable|string $groupBy, bool $preserveKeys = false)
Group an associative array by a field or using a callback.keyBy(callable|string $keyBy)
Key an associative array by a field or using a callback.implode(string $value, string $glue = null)
Concatenate values of a given key as a string.intersect(mixed $items)
Intersect the collection with the given items.keys()
Get the keys of the collection items.last(callable $callback = null, mixed $default = null)
Get the last item from the collection.pluck(string $value, string $key = null)
Get an array with the values of a given key.map(callable $callback)
Run a map over each of the items.max(string|null $key = null)
Get the max value of a given key.merge(mixed $items)
Merge the collection with the given items.min(string|null $key = null)
Get the min value of a given key.pop()
Get and remove the last item from the collection.prepend(mixed $value)
Push an item onto the beginning of the collection.push(mixed $value)
Push an item onto the end of the collection.pull(mixed $key, mixed $default = null)
Pulls an item from the collection.reject(callable|mixed $callback)
Create a collection of all elements that do not pass a given truth test.reverse()
Reverse items order.search(mixed $value, bool $strict = false)
Search the collection for a given value and return the corresponding key if successful.shift()
Get and remove the first item from the collection.shuffle()
Shuffle the items in the collection.slice(int $offset, int $length = null, bool $preserveKeys = false)
Slice the underlying collection array.sort(callable $callback = null)
Sort through each item with a callback.sum(callable|string|null $callback = null)
Get the sum of the given values.transform(callable $callback)
Transform each item in the collection using a callback.unique(string|callable|null $key = null)
Return only unique items from the collection array.count()
Count the number of items in the collection.I have decided that I hate the convention of test method names beingInCamelCase
and will convert the test method names to all snake_case
because its so much easier to read in my CLI. I will find a utility (or use my IDE) to do this for 0.8.7. Just wanted to give a heads up.
See http://github.com/excellentingenuity/Configurator as an example
Hydrate Manager
instances from lists of config files
This will be optional and will use suggests
inside composer
Go through scrutinizer and sensio labs. I can do better ๐
There is a potential flaw in the way the FileLoader
constructs its array data atm. If two files are loaded and share some key, whichever is loaded last overwrites the first. There should be a way around this, and it should probably not do this by default.
To be clear, this is not the same as #34.
This is what I mean.
hello.json
{
"one": 1
}
world.php
return [
'one' => 'one'
]
In this case, world.php overwrites hello.json.
There are a couple options to correct this.
1 Auto namespace items based on (sanitized) filename
hello.json
{
"one": 1
}
world.php
return [
'one' => 'one'
]
$manager->getAll();
/*
[
'hello' => [
'one' => 1
],
'world' => [
'one' => 'one'
]
]
*/
2 Give the user the ability to decide a namespace
$manager->addFiles([
[SplFileInfo, 'someCustomNamespace'],
[SplFileInfo, 'someOtherNamespace'],
]);
Which would namespace each file under that particular namespace.
3 A combination of both would probably be best
hello.json
{
"one": 1
}
world.php
return [
'one' => 'one'
]
$manager->addFiles([
[SplFileInfo('hello.json'), 'myNs'],
SplFileInfo('world.php'),
]);
$manager->getAll();
/*
[
'myNs' => [
'one' => 1
],
'world' => [
'one' => 'one'
]
]
*/
I'd like to do some research into Laravel, Symfony, and Yii. I know they all do this and have used all three, but never noticed how they handle this little issue. Any other thoughts are welcome.
Scenario:
$manager = new Manager();
$manager->set('one.two', []);
$manager->push('one.two', 'three');
$manager->get('one.two'); // ['three']
// Currently would have to do something like, and only from inside class
array_push($this->items['meta']['templates'], $destination);
As of now, you may only retrieve a value using magic methods. Should we explore the CUD of CRUD?
It is currently possible to retrieve collections when using the CollectionTrait
, but it would be nice to use the api (at least some of it) directly inside manager to modify the values in the container.
$manager->set(['one' => ['two' => ['a', 'b']]]);
$manager->walk('one.two', function(){});
// or
$manger->one->two->walk(function(){});
Not sure the best api to use, but it should be simple enough to use Arrayzy to do the actual work and just have methods in CollectionTrait
pass along to the external dependency.
Refactor in ManagesItemsTrait so $items is not concrete and any extending class can use their own itemsStore
As it stands now, the IoC Manager is not fully compliant with the ContainerInterface
because the ManagesIocTrait
uses fetch()
instead of get.
We should add a Manager class that remedies this and implements the delagate lookup
feature for full compliance with all aspects of data manager.
In the twenty minutes I played around with this, I discovered it's a little more complicated because the IoC Manager saves its data inside the items manifest.
Hey Chris.
Hope all is well with you. (And, sorry this doesn't really belong here, as I didn't know how to contact you through other channels.)
I just ran into a thread in the Aurelia Github repo which you started and said, wow, what a coincidence. I've been evaluating Aurelia (at a distance, because I am even less of a front-end dev), but have been seriously thinking of making Aurelia our core front-end framework too. I noticed you mentioned you were also evaluating it.
How have you found it? Are you completely convinced it is a good framework? Are you also convinced of its modularity being an core and big advantage?
I personally like how it pushes the front-end framework envelope and I've only read good things about it too. I am very interested in your views of Aurelia.
Scott
As it stands, the user MUST pass an instance of SplFileInfo
into the FileLoader
. This is good, but it should be easy enough to add a little magic to this:
$manager->loadFiles([
__DIR__ . '/my/file.json',
__DIR__ . '/my/file.php',
]);
This would apply to the LoadsFilesTrait
and the FileLoader
itself, though it may be best to do the actual work in FileBag
and just pass values down to that.
There are only a few more features I would like to add before hitting 1.0.
v0.9.0 will be a feature freeze for 1.0. That is, no new features before 1.0, only bugfixes and refactoring.
For v0.8.6
initFromJson()
For v0.8.8
For v0.9.0(Feature Frozen for 1.0)
Manager
classes and interfacesFor v1.0
There should be a way to protect certain items from being modified:
new Manager([
'some' => [
'data' => [
'here' => 'value'
]
]
]);
$manager->protect('some.data.here');
//or
$manager->protect('some.data'); // protects all further nests
// So now
$manager->set('some.data.here', 'new-value');
// Would throw a ModifyingProtectedValueException
Now that the File Loader is up, the next milestone for that feature is to allow for cascading fileloading:
$manager->addFiles([
['some/file1.php', 'some/other/file1.php'],
['some/file2.php', 'some/other/file2.php'],
]);
This would mean that it first loads some/file1.php
and then loads some/other/file1.php
, overwriting any values from the first. This is useful for users who want to have defaults in one file and then load precedence over them.
They should be allowed to load as many cascades as they like.
It may also be worth looking at using the native loadDefaults()
that is in ManagesItemsTrait
Right now CollectionsTrait
and ChainsNestedItemsTrait
depend on ManagesItemsTrait
. They should not extend that trait. What is the best way to handle trait dependencies?
Now that hydrateFrom()
has landed, the next step is to add a system for users to register Decoders
that allow for hydrating and appending from any kind of non-native datatype.
This would also mean a JsonDecoder
and probably a YamlDecoder
standard
The initial structure for a marketing site, cookbook documentation, and api documentation has been created.
Left ToDo:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.