Download the PHP package ergnuor/sphinx-config without Composer
On this page you can find all versions of the php package ergnuor/sphinx-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sphinx-config
SphinxConfig
About
This is the Sphinx configuration helper, which extends block inheritance and allows you to integrate configuration into your application through the possibility of using placeholders.
Usage
Standalone
For that case you may use common console command:
And /path/to/sphinx/config/preciousConfig.conf
file should contents something like this:
Application integrated
You may integrate SphinxConfig into your application and create script that generates configuration file and runs desired Sphinx command. So script may looks like this:
In any case you need to describe a source configuration.
Prerequisites
SphinxConfig has no dependencies except for PHP 5.6+
Structure
Configuration structure
At this moment configuration is described by PHP arrays (more formats are planned). Here is a simple example of configuration structure:
Source
and index
sections consist of blocks. Blocks, as well as indexer
, searchd
and common
sections, contain parameters.
File structure convention
Here is a typical full file structure of configuration:
├── preciousConfig
│ ├── sectionType
│ │ └── blockName.php # Block is located in a separate file
│ └── sectionType.php # Section is located in a separate file
└── preciousConfig.php # Whole configuration is located in one file
You don't have to describe a structure of configuration as comprehensively as shown above. You can choose one of the following options or combine them at your own discretion:
- An entire configuration is located in one file.
For example:/path/to/configs/preciousConfig.php
, - Section is located in a separate file.
For example:/path/to/configs/preciousConfig/sectionType.php
, - Block is located in a separate file.
For example:/path/to/configs/preciousConfig/sectionType/blockName.php
. This option may be useful for storing common parameters used by different configurations. For more information see inheritance between configurations section.
Inheritance
To inherit blocks you should use 'extends'
parameter with the name of parent block as a value.
For example:
Inheritance of multi-value parameters
Values of a multi-value parameter are appended to values of a parent block parameter by default. To ignore values of the parent block, you must use :clear
modifier.
For example:
You can also specify an alias for the value of the multi-value parameter. So, you can refer to the value in child blocks and override it.
For example:
And get the following configuration as a result:
With this approach you don’t need to copy all values of the multi-value parameter from the parent block. This example can be made even shorter by using placeholders.
Inheritance between configurations
You can refer to the blocks from other configurations. For that you need to specify the configuration name and separate it from the block name with @
symbol. Note that configurations should be located in the same directory.
The example of usage is storing database connection settings in /path/to/configs/common/source/connection.php
block and referring to it from other configurations via 'extends' => 'common@connection'
parameter.
Note that in internal representation indexer
, searchd
and common
sections are converted into sections containing self-titled blocks. This allows them to be used in the same way as source
and index
sections. So, as in the last example, you can store common settings for indexer
, searchd
and common
sections in separate blocks and inherit from them.
Placeholders
Each value of Sphinx parameter may contain a placeholder in ::path.to.value:
: format. Placeholder uses dot notation, so it is possible to extract values from multidimensional arrays. The replacement values themselves can contain placeholders. So placeholders are dereferenced recursively.
There are two ways of passing values:
- You can pass global values for entire configuration using
setPlaceholderValues()
method.
This may be useful for passing values from your application, for example such as database connection parameters. - Values could be specified locally for each block using
'placeholderValues'
parameter,
Using this feature we can simplify the example from inheritance of multi-value parameters section:
And get the following configuration as a result:
Parameter values
Multiline values are automatically padded with a trailing slash. This is useful when formatting queries.
Custom parameters
Parameter will be ignored if its name starts with an underscore. This allows you to add parameters for internal use, for example, if the configuration is being pre-processed and you want to be able to configure this process.
Configuration parameters list
-
Specifies the name of the parent block. Can refer to a block from another configuration located in the same directory. For that you must specify the configuration name separated from the block name with
@
symbol.
'extends' => 'blockName'
'extends' => 'otherConfig@blockName'
-
Values for placeholders,
-
Marks the block as a pseudo block. Pseudo blocks don`t get into the resulting configuration. This may be useful for inheritance purposes if you want to create a container-block just for storing parameters that are common to other blocks.
License
This project is licensed under the Apache 2.0 - see the LICENSE file for details