Download the PHP package sven/file-config without Composer

On this page you can find all versions of the php package sven/file-config. 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 file-config

file-config

File Config

Latest Version on Packagist Total Downloads Build Status StyleCI

This package provides a persistent config store as flat files with an easy to use and understand API. This is perfect if the config file should be stored in userland, or somewhere the user is allowed to edit it manually.

Installation

You'll have to follow a couple of simple steps to install this package.

Downloading

Via composer:

Or add the package to your dependencies in composer.json and run composer update sven/file-config on the command line to download the package:

Available drivers

You can also write your own driver to use in your own applications. To write your own, read writing your own driver in this document.

Usage

To get started, construct a new instance of \Sven\FileConfig\Store, providing it with a \Sven\FileConfig\File object, and an implementation of the \Sven\FileConfig\Drivers\Driver interface. We'll use the pre-installed Json driver in the examples.

You can interact with your newly created $config object via the get, set, and delete methods.

Examples

Let's take a look at some examples.

Getting a value from the file

To retrieve a value from the configuration file, use the get method. Let's assume our (prettified) JSON configuration file looks like this:

We can get the entire database array:

... or get only the database.host property using dot-notation:

If the given key can not be found, null is returned by default. You may override this by passing a second argument to get:

Setting a value in the file

To add or change a value in the configuration file, you may use the set method. Note that you have to call the persist method to write the changes you made to the file. You may also use the fresh method to retrieve a "fresh" instance of the Store, where the values will be read from the file again.

The file will end up looking like this after you've called the persist method:

Deleting an entry from the file

To remove one of the configuration options from the file, use the delete method. Again, don't forget to call persist to write the new contents to the file!

Writing your own driver

You may want to use a file format for your configuration that's not (yet) included in this package. Thankfully, writing a driver is as straightforward as turning your file's contents into a PHP array.

To create a driver, create a class that implements the \Sven\FileConfig\Drivers\Driver interface. Then add 2 methods to your class: import and export. The import method will receive the contents of the file as an argument, and expects a PHP array to be returned.

The export method is the exact reverse: it receives a PHP array, and expects the new contents of the file to be returned (as a string). To see how this works in more detail, take a look at the pre-installed json driver.

Contributing

All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the CONTRIBUTING.md first, though. See the contributors page for all contributors.

License

sven/file-config is licensed under the MIT License (MIT). Please see the license file for more information.


All versions of file-config with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-json Version *
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 sven/file-config contains the following files

Loading the files please wait ....