Download the PHP package morningtrain/laravel-context without Composer

On this page you can find all versions of the php package morningtrain/laravel-context. 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 laravel-context

Context

Installation

The Laravel Context package can be installed from packagist using the follow command

composer require morningtrain/laravel-context

Facade setup

There is a facade helper for accessing the current context. Add it as an alias to config/app.php using the following snippet.

'Context' => MorningTrain\Laravel\Context\Context::class,

Service provider

Contexts are configured in a service provider. Add a service provider in app/Providers that extends MorningTrain\Laravel\Context\ContextServiceProvider

This could be a typical starter ContextServiceProvider which also should be registered in the config/app.php config file in Laravel.

It contains 3 properties that should be configured.

Plugins are extra functionality that can be added which extends the normal behaviour of the context system.

The plugins displayed above are the typically used plugins - they are all shipped with the context package. Is is possible to develop project-specific plugins and hook them up here.

The contexts property defines and array of all contexts available in the system. They will be referenced by the configured name. There will be a definition of the context classsed later.

load defines the contexts that should be automatically loaded. Contexts need to be defined here or loaded manually in order to provide any functionality.

Context class

This is an example of a basic AppContext class.

Anything in the array returned by the closure added to the env method will be merged into the env variable for that context. It can be used to provide a set of variables to for instance JavaScript.

Note the last call to Context::load(Asset::class). The Asset class is a simple class containing a load method. It is not essentially needed but is a way to split the context loading into multiple smaller and more maintainable classes.

This is a basic example of an Asset class.

This is where stylesheets and JavaScripts are configured and made available to the HTML blade view. This allows for more dynamic loading of scripts and keeps the base HTML templates clean.

Context provider

ContextProviders were added in version 2.5.0 and is an updated approach to structuring the context class.

New features include the ability to register plugins directly from any ContextProvider, meaning that plugins can be removed from the ContextServiceProvider. This shift away from registering the plugins in the service provider will leave plugin dependency to the classes actually implementing them.

The Asset example above and similar classes are now called partials and can be automatically loaded from any ContextProvider.

It is recommended that these partials also extends the ContextProvider base class to have support for plugins.

Note that it is encouraged to split the context class up into partials instead of having custom logic inside the context class itself.

The AppContext example will the look like this (without the app name example).

And the Assets class like this

Middleware

Remember to add the context middleware to app\Http\Kernel.php.

The following snippet should be added as a route middleware.

'context' => \MorningTrain\Laravel\Context\Middleware\LoadFeatures::class,

To work with ContextProviders, the updated version should be used instead:

'context' => \MorningTrain\Laravel\Context\Middleware\LoadContexts::class,

To keep backward compatibility, the old middleware is kept for now.

Loading contexts

Beside from loading contexts in the service provider, one would use the context middleware to load a context.

Add this middleware to any route group to load the app context during the load of those routes.

'context:app'

This way, any route under the group will gain access to any information added to the app context.

Including scripts and stylesheets

Add {!! Context::stylesheets() !!} to the document header in order to generate HTML tags for all enqueued stylesheets.

Add {!! Context::scripts() !!} to the HTML body footer in order to generate script tags for all enqueued JavaScript files.

Providing ENV to JavaScript

Use the following script in your blade HTML template in order to automatically generate a JavaScript object class env.

It will be an object representing the entire environment built in the loaded context.

{!! Context::env() !!}

Credits

This package is developed and actively maintained by Morningtrain.

 _- _ -__ - -- _ _ - --- __ ----- _ --_  
(         Morningtrain, Denmark         )
 `---__- --__ _ --- _ -- ___ - - _ --_ ´ 
     o                                   
    .  ____                              
  _||__|  |  ______   ______   ______ 
 (        | |      | |      | |      |
 /-()---() ~ ()--() ~ ()--() ~ ()--() 
--------------------------------------

All versions of laravel-context with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0|^8.1
illuminate/routing Version ^8.0|^9.0
illuminate/support Version ^8.0|^9.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 morningtrain/laravel-context contains the following files

Loading the files please wait ....