Download the PHP package dakin/stubborn without Composer

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

Stubborn for PHP

Introduction

The Stubborn package enhances the PHP development workflow by providing a set of customizable stubs. Stubs are templates used to scaffold code snippets for various components like models, controllers, and migrations. With Stubborn, developers can easily tailor these stubs to match their project's coding standards and conventions. This package aims to streamline the code generation process, fostering consistency and efficiency in PHP projects. Explore the customization options and boost your development speed with Stubborn.

Generating new files from stubs can be as simple as this:

Requirements


Installation

You can install the package with Composer, but make sure to add this repository (as type git) in your composer.json. When this package is available on packagist, you can skip this step (and it won't be mentioned here). Once the repository is added, run:

You don't need to publish anything.

Usage

Note that for many of these examples, especially those towards the bottom, I've omitted the ->generate() call for the sake of brevity. If you want your stubs to actually generate, don't forget to add ->generate()!

Create a stub file

First of all, create a stub file called model.stub:

Add some code to that, like this:

How to Use Stubborn

In order to use Stubborn, you need to import the Stubborn\Stub class:

from

First thing, you need to use the from method to give the stub path:

to

Next, you'll want to specify the destination directory of the stub file:

name

You can set the stub file with this, but make sure to leave out the stub extension:

ext

You can determine the stub extension:

replace

The replace method takes two parameters, the first one is the key (variable) and the second one is the value. The value will be replaced with the variable:

replaces

The replaces method takes an array. If you want to replace multiple variables you can use this method:

generate

To generate the stub file, you need to use the generate method at the end of the chain to generate stub file:

If you're following along, the final file should be named new-model.php and look something like this:

Modifiers

Stubborn adds support for modifiers. Modifiers let you use a single replace string in multiple forms. Here's an example... Let's say you have a class stub that can introduce itself:

This is fine, but maybe I want the class to shout its name in ALL CAPS. Instead of declaring that behavior from my Stub generation code, I can put that intention directly in the stub file.

Mind you, this particular use case would benefit more from not having the class name statically declared twice, but for demo purposes...

Great, now I can pass class name or Class Name to Stubborn a single time, and still get that token presented in the proper way.

There's a new Str class that's been adopted from the Laravel framework to offer several helpers as modifiers. Most of the single parameter methods from that class can be used as modifiers by adding ::methodName after the variable name. These modifiers can also be chained together: {{ NAME::upper::trim }}.

In addition, you can add your own modifiers by editing the Stub::modFunctions associative array. You can pass in the modifier name as the key and a function accepting a string as the value:

Now, stubs with {{ VAR_NAME::repeat }} will repeat the replace value once.

Setting a Stub Folder

It's likely you'll have a single place where you want to keep all of your stubs ({project_path}/stubs, for example). It can be a pain to keep providing that folder path as context when generating stubs.

Instead, you may set the stub folder a single time using the static setStubFolder method.

A couple notes about this:

Setting a Context Folder

Similar to the Stub Folder option, Stubborn provides a Context Folder option. If you have something like a src directory where all of your stubs tend to go, you may provide the path to that directory as a parameter to Stubborn::setContextFolder. By doing so, you can remove that part of the path when you call Stub::to.

Before Stub and Context folder:

After:

Implicit Target Dir and Extensions

An additional benefit to setting up the Stub and Context folders is being able to omit some of these chained calls from your Stub generation.

Imagine a stub folder structure that matches the src folder. Basic Stub generation with this structure may look something like this:

Fine, but a bit redundant. When you provide the context folder, Stubborn will try to infer your Stub::$to and your Stub::$ext based on the path provided to Stub::from.

Great, this still creates the same file, but with a much slimmer set of calls.

Contributors

The crew at Binafy did most of the heavy lifting for the core stub features with their Laravel-embedded version of this package.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


All versions of stubborn with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
voku/portable-ascii Version ^2.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 dakin/stubborn contains the following files

Loading the files please wait ....