Giter Site home page Giter Site logo

data-manager's People

Contributors

electricjones avatar scrutinizer-auto-fixer avatar smolinari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

skooppaos smpso

data-manager's Issues

Add Collections

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.

Error when nesting under scalar values

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.

Hydrate Manager from json

It should be possible to hydrate an instance from json. Maybe one of:

$manager->fromJson($json);
$manager->resetFromJson($json);
$manager->initFromJson($json);

Add CollectionTrait

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.

Tests to snake case

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.

Namespacing data loaded from files

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.

Possible Fixes

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'
   ]
]
*/

Things to be aware of

  • Filenames can have really bad practices, and so should be sanitized/slugified. We can borrow from Stringy.
  • If two files have the same filename, the problem doesn't correct itself. That's fine with me. The user should know what they are loading and be aware of how it works. If we provide them an namespace option, they should use it.
  • The override namespace api for this is incompatible with the proposed api for #34

From here

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.

Add ability to push element onto array

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);

Reproduce the `Arrayzy` api inside Manager

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.

IoC Manager Compatability with ContainerInterface

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.

Off-topic - Aurelia

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

Convert filenames to SplFileInfo objects

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.

Roadmap to v1.0

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()
  • Allow for Hydration from various non-native types (yaml, etc) using decoders
  • Basic Collections

For v0.8.8

  • Finish FileLoader #36, #35
  • Reproduce the Arrayzy api inside Manager #37

For v0.9.0(Feature Frozen for 1.0)

  • More Manager classes and interfaces
  • Testing cleanup: remove unneeded stubs, consistency, etc.

For v1.0

  • Test coverage to 100%
  • Review and split documentation
  • Scrutinizer to 9+
  • Insight platinum
  • Marketing site

Protect items in Manager

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

Cascading File Loading

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

Related to #36 and #35

Handle Trait dependency

Right now CollectionsTrait and ChainsNestedItemsTrait depend on ManagesItemsTrait. They should not extend that trait. What is the best way to handle trait dependencies?

Hydrate from various non-native data types

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

Documentation and Marketing

The initial structure for a marketing site, cookbook documentation, and api documentation has been created.

Left ToDo:

  • Check over Documentation in /docs/
  • Tie Documentation and API documentation together through links more cleanly
  • Integrate into a build/deploy process
  • Finish marketing site

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.