Download the PHP package abivia/penknife without Composer

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

Abivia\Penknife

Penknife: a small blade

Penknife is a tiny but powerful template engine implemented in PHP 8.4. Change log below.

Penknife supports:

The format() method takes template text and a variable resolution callback as arguments.

Example:

Output:

Variables can have a default value: {{somevar, none}} will emit "none" if the resolution function returns a null value for somevar.

The type argument to the callback is either PenKnife::RESOLVE_DIRECTIVE or PenKnife::RESOLVE_EXPRESSION. Directives allow extension of the command structure and are described below.

Conditionals

Penknife supports if-then-else statements.

If the resolution callback returns a value that evaluates as empty() then the condition is false, otherwise it is true.

Loops

A loop is indicated with an ampersand followed by the name of an array. Elements of the array can be accessed by the loop variable loop. Nested loops are accessed by their nesting level, loop2, loop3, etc. for ease of use, loop is the same as loop1. The current index of the array can be obtained by using a # with an optional bias, which is useful for numbering from 1. If the array is associative, this will return the current key. An associative array with a numerical bias will return the numerical position.

Output:

Nested Loops

Loops can be nested:

Output:

Named loops

Since keeping track of loop variables like loop1, loop2, etc. can be tedious, it is possible to give a loop a name:

Empty loops

You can use !@ before the end of a loop to handle empty loops

System directives

System directives have the form {{:name [arguments]}}.

Name Use Description
export {{:export export_list}} Exports one or more variables to a parent template.
include {{:include file_path}} Includes the named template file, if it exists.
inject {{:inject section_name}} Specifies the start of a parent injection section.
parent {{:parent file_path}} Names a parent template file.

All other directives are passed to the resolver callback with the type set to RESOLVE_DIRECTIVE. New directives may be added in the future. Penknife will never use an internal directive name starting with an underscore.

Export directive

The value of variables in the current environment can be exported to the parent by listing them, separated by spaces. It is possible to rename a variable by prefixing it with the exported name and a colon. For example {{:export banner:title dated}} will put the value of "title" into the "banner" variable, the value of "dated" into the "dated" variable, and the text following the inject directive into the "header" variable. These will then be passed to the parent template.

Include directive

This will read the included file into the template. Use the includePath() method to set a base directory for template includes.

Inject directive

Defines the beginning of text that will be stored into the named section and passed to the parent template. The output will be passed as the named variable to the parent template. For example, {{:inject header}} will pass the variable "header" into the parent template. If no parent is specified then the contents of the inject block are not output anywhere.

Parent directive

If a parent template is specified, then the values of any slots defined by an inject directive, along with any exported variables, will be passed to that template. Only one parent can be specified. Parent directives after the first one are ignored.

Example of the inject/parent mechanism:

Template

Parent template stored in some-file

Resulting output:

Alternate Syntax

All tokens in Penknife can be modified via the setToken() and setTokens() methods. The default tokens are:

Name Value Usage
args , Separate arguments inside a command
close }} Closes a command
else ! Else operator
end / End operator, terminates an if or loop
if ? Conditional operator
index # Current loop index
loop @ Starts a loop
open {{ Opens a command
scope . Scope operator
system : System directive

Changelog

1.3.0 2025-10-08

1.2.2 2025-09-26

1.2.1 2025-09-25

1.2.0 2025-09-25

1.1.2 2025-09-23

1.1.1 2025-09-23

1.1.0 2025-09-22

1.0.0 Initial release


All versions of penknife with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
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 abivia/penknife contains the following files

Loading the files please wait ...