Download the PHP package tivie/htaccess-parser without Composer

On this page you can find all versions of the php package tivie/htaccess-parser. 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 htaccess-parser

PHP Htaccess Parser

Build Status Latest Stable Version License

A lightweight PHP htaccess parser

Introduction

PHP Htaccess Parser is a small lightweight library that can parse (or tokenize, if you prefer) an apache .htaccess file. It was developed for personal use to safely read and manipulate .htaccess files.

Features

The parser supports:

Installation

You can install it by cloning the git repository or using composer.

Git clone

git clone https://github.com/tivie/php-htaccess-parser.git

Composer

Add these lines to your composer.json:

or run the following command:

php composer.phar require tivie/htaccess-parser

How it works

Each line of the file .htaccess file is parsed and then converted into one of the following tokens:

Each token implements TokenInterface provides a simple api to read and modify its properties.

Tokens are aggregated in an HtaccessContainer that can be used to add, modify or remove Token objects and dumping it as plain text or json.

Quick Usage guide

Using PHP Htaccess Parser is very simple.

You can then use $htaccess to manipulate .htaccess contents.

For instance, to print the first token of the file:

Casting a Token or an HtaccessContainer object to string returns a string representation of that element that can be used to recreate the .htaccess file.

Components

The Parser

The Parser class is the main component of the library. Since it's constructor doesn't require any mandatory argument, initializing a Parser object is very simple:

Parser Options

The parser's behavior can be changed through the following methods and/or options:

Setting the file

The parser uses \SplFileObject to access files. You can set the appropriate file in the constructor, by calling setFile() or as the first parameter of $parser->parse

Changing the container

By default, $parser->parse() returns an HtaccessContainer object (which extends ArrayObject) that contains the newly tokenized .htaccess file. You can change the returned object by calling setContainer()method:

$myContainer can be an array or an object that implements ArrayAccess.

Use arrays

Each Token is an object that implements the TokenInterface, which presents several useful methods. However, if you prefer, you can instruct the parser to use simple arrays instead by either:

Ignoring White and Comment Lines

You can instruct the parser to ignore WhiteLines, CommentLines or both by:

Rewind file

By default, prior to serialization, the Parser rewinds the file pointer to the beginning. You can override this by calling the rewindFile method.

Extending the Parser

The Parser class provides API points that developers can override. For more information, you can check the code at https://github.com/tivie/php-htaccess-parser/blob/master/src/Parser.php


HtaccessContainer Object

The default returned object (HtaccessContainer) implements ArrayAccess, so you can access the definitions as you would with an array. The keys of this array are numeric and ordered by their appearance in the original file.

Retrieving a Token

Since the Parser returns an array or an array like object, you can retrieve a specific token by its index:

You can also use the search method to find a specific token by its name:

You can constrain the search to a specific token type.

Modifying a Token

TokenInterface provides a common API that you can use to manipulate the tokens.

Keep in mind, however, that with some tokens, an array of arguments doesn't make much sense. For instance, Comments Tokens only expect 1 argument (the actual text of the comment) while WhiteLine Tokens expect none so extra arguments will be silently ignored.

Adding a Token

You can add a token by simply creating and appending it.

You can also insert a Token into a specific index using insertAt:

Outputting htaccess

In order to output an .htaccess txt file, you can cast the HtaccessContainer to string and write the resulting string to a file:

You can also use the method txtSerialize to control how the output should be formatted:

NOTE: Keep in mind that ignored elements in the parser won't be available to HtaccessContainer serialize methods.

Contribute

Feel free to contribute by forking or making suggestions.

Issue tracker: https://github.com/tivie/php-htaccess-parser/issues

Source code: https://github.com/tivie/php-htaccess-parser

License

PHP Htaccess Parser is released under Apache 2.0 license. For more information, please consult the LICENSE file in this repository or http://www.apache.org/licenses/LICENSE-2.0.txt.


All versions of htaccess-parser with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0.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 tivie/htaccess-parser contains the following files

Loading the files please wait ....