Download the PHP package topshelfcraft/walk without Composer

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

Walk

_Provides a Craft-aware array_walk() method, plus some super-convenient console commands, allowing you to easily call Craft service methods on a collection of elements or values._

by Michael Rog

TL;DR.

You want to perform some action, in bulk, on a bunch of elements.

Maybe you want to do it ad-hoc with an easy console command.

Or, maybe you want to do it in one line of PHP, in a custom component.

And you want to do this with several different sets of elements, and with several different bulk actions, without needing to write new code every time.

Walk gives you a special Craft-aware array_walk method to apply a Craft component method to each element in a list.


Installation

Install with Composer by running composer require topshelfcraft/walk from your project directory.

Then, visit the Settings > Plugins page of the CP, and click to Install the Walk plugin.

Walk a what?

Applying a method to every item in a list is known as "walking" an array. In fact, PHP provides a method — array_walk() — to do just that.

However, PHP's array_walk method isn't aware of how Craft's components are set up, and it doesn't know anything about Elements.

So, where PHP's array_walk is useful for applying a PHP method to each item in an array, this plugin provides a Craft-aware walk function — craftyArrayWalk() — to run a Craft component method on each item in a list.

Yes! This will save me minutes! How do I start?

First, you need to have a callable in mind. A callable is the method that will be run on each item in the list.

A callable is specified by its name as a string. With this plugin, a callable can be:

Second, you need a list of stuff (an array).

Then, just call the craftyArrayWalk() method, like this:

It works pretty much just like the native array_walk method:

_Technically, you can supply any valid PHP callable object to the craftyArrayWalk method. But if you already have a callable object in-hand, you probably don't have much need for this plugin. The advantage that this plugin's method provides over the native array_walk is that it recognizes those special callable strings, which represent methods in Craft._

You can also provide extra some custom data if needed, by adding a third parameter, like this:

The $userdata will be passed as the third parameter to the callable method on each step.

So, in technical terms, a callable method has the following signature:

I need an example.

Let's start with an example of PHP's native array_walk:

You could do this:

But this is way prettier:

These two examples accomplish the same thing: Afterwards, each string item in the array will have been transformed to lowercase.

Now let's look at a Crafty example.

You could do this:

But this is tighter:

In both examples, each Entry in the query will be re-saved.

Nifty... but I don't want to write any PHP. What about some console commands?

That's actually why I wrote this plugin: I needed a fast, convenient way to do a bunch of indexing/re-saving, preferably from the CLI, without having to write a new custom command for each job/criteria combo.

So, without further ado, I give you... the walk CLI command.

So, let's break that down:

If you want to re-save all your blog entries...

If you have a custom service method, and you want to run it once on each user:

What if your custom method takes an element ID rather than an element object?

Tada!

Or, perhaps you want to get a count of elements in a criteria, without actually doing anything to them?

Command options

The following Element Criteria attributes can be set via CLI option:

(...plus, for Commerce Orders...)

Does it work with custom element types?

The Walk CLI command provides easy shorthands for Craft's built-in element types. However, you can use Walk with any element type by supplying its [fully-qualified] class name, along with the [fully-qualified] class name of the associated element query.

Oh, and you said something about Jobs...?

Say you have a lot of elements... or your callable methods are performance-intensive... or you need things to keep running even if your CLI connection is closed... or you just prefer to schedule things one-at-a-time using the Craft queue...

There are a couple ways Walk might help.

1. Schedule callables as Jobs using the CLI

You can use the special --asJob command option to schedule each walk step as a Job:

This will still invoke the callable once for each element or ID in the criteria, but it will do so from inside a Job — i.e. one request per element/step.

This is nice if you want to keep track of the queue progress, or if you want to be able to conveniently re-run any steps that fail due to an error.

In the Control Panel sidebar these show up as CallOnElement and CallOnValue jobs.

2. Use a Job as a callable via the PHP methods

The spawnJobs method can be used to schedule one instance of a specified job per element or ID in the provided set.

The job is specified by full class name, just as if you were using Craft::$app->queue->push().

You can supply an array of extra settings in the $settings argument, which will be applied to each job.

The specified job should expect to receive an elementId setting containing the element ID. Alternatively, you can also change the name of the setting that will receive the ID of the element, using the $valParam argument.

Can I use this stuff with any array? Does it have to be elements/IDs?

The console commands are designed to perform bulk actions on sets of Elements or IDs.

However, if you're feeling clever, you can use the craftyArrayWalk() helper method with any array.

For example, if you have an array of email addresses, and a processEmailAddress service method that takes an email address as its first argument...

If you want to make your own console command that walks through some other set (i.e. not Elements or Element IDs), just check out the source code of the WalkController. You'll find it pretty easy to copy/paste your way to success!

This is great! I still have questions.

Ask a question on StackExchange, and ping me with a URL via email or Discord.

What are the system requirements?

Craft 3.0+ and PHP 7.0+

I found a bug.

Please open a GitHub Issue, submit a PR to the 3.x.dev branch, or just email me.


Contributors:


All versions of walk with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^4.0
topshelfcraft/base Version ^4.0.1
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 topshelfcraft/walk contains the following files

Loading the files please wait ....