Git Product home page Git Product logo

json's Introduction

trophy

Summary

Open-source enthusiast, advocate and developer. PHP programmer and follower. Interested in low-level programming. C++ and Rust lover. Having Git and Linux vital organs. Shell addict. Active on Git*b. And finally... thirsty for team work. :)

Skills

Technology

PHP Git Linux Bash C++ Fedora Docker Python JavaScript HTML5 CSS3

Eager to Learn (More)

Rust Symfony

Soft Skills

Teaching Object Oriented Programming Unit-Testing Writing Documentation CI/CD

Eager to Learn (More)

Team Work Code Reading

More About Me...

A developer wanting (maybe trying?) to shift his focus to open-source. The title may shout at you: "I want my bucket to be empty"! No, it's lying. Look at Red Hat and Nextcloud. Even without them, there's a huge hidden opportunity in open-source.

In my ideal world, all of science and all technologies are open. By keeping things closed, most likely it is you (being a person or a group) that matter the most. In an open environment, however, you think further: Advancing the world as a whole is much more important.

I tend to use PHP a lot. It has a great ecosystem. Breaking changes are minimal, not even in the language itself, but in the libraries as well. Not even that means the language is holding back, but it looks shinier with each release. Composer is fundamentally better and faster than anything else I tried. And so on... (oh, did I mention its good performance?)

Living without Linux for me is like living with one hand (well, the remaining one is, obviously, Git). Well, I have to mention I use Fedora Linux, and I love it: Stability while being up-to-date. I've been running it for nearly three years without even thinking a re-installation is needed.

Last but not least, I'm proudly an Iranian and a Muslim. I'm also interested in Islamic topics, especially Islamic philosophy.

Q&A From Myself!

  • What are the things I refuse to work with and why?

    Windows first and foremost. Privacy matters.

    NVIDIA next. Please don't ask an obvious question. ;)

Find Me

You should find me just anywhere with the help of @machitgarha identifier.

GitLab LinkedIn Twitter LinkedIn

In Persian

LinkedIn LinkedIn

json's People

Contributors

machitgarha avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

nasstya

json's Issues

Allow passing an array as an index

Currently, it's only possible to pass a string or an integer as index in the methods. However, it's a good idea to allow arrays to be passed (but not objects, because of its overhead). In this case, all array elements must be checked to be either a string or an integer. A possible improve in this case would be directly passing the array to Json::findElementRecursive() without checking it and iterating it twice in Json::extractIndex().

Remove return type of Json::*Option*() methods

Removing the return types of Json::*Option*() methods (e.g. Json::setOptions()) causes extending the class to be easier, because of redeclaring these methods in the child class will be more suitable. Currently, sometimes it causes incompatibility with the parent class. Instead of setting return value type hint to self, it should be commented.

Call other method within Json::do() method's callback

Calling other methods inside Json class from the callable of Json::do() should be considered. Currently, it is now possible to do that. As an example:

$json = new Json();

$json->do(function () use ($json) {
    // $json->something();
});

However, this could be improved; maybe using Closure::bind() or Closure::bindTo(). Also, undefined behaviours might happen:

$json = new Json([
    "something" => 10
]);

$json->do(function (&$value) use ($json) {
    // Change data completely, set it to a string
    $json->set("Something");

    // Nothing happens here!
    $value = 3;
}, "something");

I don't know if it is fault of PHP itself or Json class, however, this behaviour must be considered.

Add an options parameter for Json::get()

An $options parameter after $index in Json::get() and all its variants (i.e. Json::getAs*()) and an option in either JsonOpt or a new GetOpt class should be added, which:

  • GetOpt::STRICT: Throws an exception when the index does not exists.

This is the only option for now, but it may be added more options later.

Add JSON_* constants

Add PHP's JSON_* constants to the class, and make the possibility to add or remove them. For example, add the options before calling Json::getAsJson(), instead of passing options as arguments.

Make almost all return self to return static in PHPDoc

Using of child class methods after calling a parent class method using fluent interface is a bit bad. For example:

class Json2 extends MAChitgarha\Component\Json
{
    public function copy() {}
}

$json = new Json2();
$json->set([""])->copy();

Calling Json2::copy() after Json::set() is valid, but IDEs will not show it because of the self return type. Using static would fix this issue.

Accepting bad indexes

When a bad index (e.g. an index as an array) passed to a method, instead of checking it to be either a string or an integer, a TypeError is thrown. Instead, a custom exception should be thrown.

Define new methods on the fly

Currently, flexibility to do custom operations on the data is enough:

  1. Extending Json class and add some custom methods to it;
  2. Using anonymous classes to define methods on-the-fly;
  3. Using Json::do() method.

However, it would be a good feature to add some methods on the fly, like the following:

$json = new MAChitgarha\Component\Json();

$json->customMethod = function ($args) {
    // Doing something interesting here
};
$json->customMethod("arg", "uments");

Things to note:

  1. The on-the-fly method definition uses __set() to set a new method, and calling a defined method uses __call().
  2. Defining static methods is hard to implement, so it should be ignored. However, it should be considered.
  3. Trying to override an existing class method must try an exception (or error), and trying to call a non-existence method should try an error (i.e. should not be an exception).
  4. It should be a way of accessing other methods inside the closure. The instance of the class may be passed through an argument to the closure, or it may be bound inside the closure.
  5. It should be a way of accessing an element in data using an index. The element should be extracted and be passed as an argument to the closure.

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.