Download the PHP package dogancelik/slim-json without Composer

On this page you can find all versions of the php package dogancelik/slim-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slim-json

SlimJson Latest Stable Version

SlimJson is an easy-to-use and advanced JSON middleware for Slim PHP framework. SlimJson helps you write web apps that return JSON output.

How to install

You can install SlimJson with Composer by:

or adding this line to your composer.json file:

How to use

If you go to localhost/, you will get: {"Hello": "World", "_status": 200}

If you go to localhost/error: {"error": "This is an error", "_status": 500}

If you go to localhost/notfound: {"error": "'/notfound' is not found.", "_status": 404}

Rendering JSON

If you haven't noticed, I didn't add a JSON view to our Slim app. It's because when you add the middleware, we add the JSON view for you so you don't have to.

You should see that we are using a different $app->render() method here.

Rendering parameters are these: function render(status, data)

Configuration

You can initialize the Middleware with these configuration options.

Example:

All options are disabled (false) by default. Set them to true to enable.

json.override_error

Configures $app->error to return JSON response with HTTP return code 500. Only works if you add the middleware globally

json.override_notfound

Configures $app->notFound to return JSON response with HTTP return code 404. Only works if you add the middleware globally

json.protect

Adds while(1); to every JSON response. What's this?

json.status

Adds an integer _status field to your JSON response.

json.debug

If you enable this option, SlimJson will add additional debugging info (named as _debug) on error. Exception properties (like message, stacktrace, line, etc.) will be added to JSON response.

json.cors

Enables CORS.

If you set this to true, it will set CORS to * (allow all domains). If you set a string, it will set CORS to that string

json.clear_data

You should read this if you don't use the middleware globally. Read why I added this option.

json.json_encode_options

Passes an $options argument to json_encode.

Visit PHP.net page for available constants for json_encode.

Advanced

Use SlimJson for individual routes

If you don't need JSON for your whole application and want to return JSON for individual routes:

Instead of adding the middleware globally, put $app->add inside the routers you want:

Use inject() for handiness and happiness :smile:

I created a static method under the middleware called inject($app, $config), it is basically same as calling $app->add(); but good for a clean and shorter code. Passing the arguments $app and $config is both optional.

Replace this:

With this:

Set your own $app->error or $app->notFound message

If you add the middleware globally and enable json.override_error or json.override_notfound, SlimJson will use its own message format for each handler. But you can change that too!

Using config

Using Middleware method


Edge case option: json.clear_data

Read this option if you don't use the middleware globally. You may encounter this error.

Let's say you have a GET router (/foobar) and an error handler:

What happens if you take out inject() from the GET router? So it would be like this:

Then if you go to /foobar you will get an error like this:

Notice you both have foo and error keys. It's because Slim uses $app->view->appendData().

Why did this happen? Because we forgot to add \SlimJson\Middleware::inject(); to the GET router; So don't forget to add this.

If you enable this option, it will remove all data. It may remove other middlewares' data (like Flash (Session) middleware) but I haven't tested it.

But if you really want to use this then add inject(array('json_clear_data' => true)) to your error handler:


All versions of slim-json with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dogancelik/slim-json contains the following files

Loading the files please wait ....