Download the PHP package kamranahmedse/smasher without Composer
On this page you can find all versions of the php package kamranahmedse/smasher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kamranahmedse/smasher
More information about kamranahmedse/smasher
Files in kamranahmedse/smasher
Package smasher
Short Description A PHP package to easily smash directories and convert them to JSON
License MIT
Homepage https://github.com/kamranahmedse/smasher
Informations about the package smasher
Smasher - Smash your directories
Easily turn your directory structure to JSON or Array and vice versa
Introduction
Smasher is a php utility that lets you get a JSON or array~~ representation from your directory structure, or use the specified representations to create the directory structure
When you smash a directory, all the subdirectories, files, symlinks are converted to the representation that you specify and when you build, the representaion is processed to create the specified structure i.e. directories, files and symlinks are automatically created.
..all the subdirectories, files, symlinks are converted to the representation that you need ...and back
Where to Use?
Originally it was written for a friend to let him use it in the cloud formation scripts. However you can use it wherever you want.
Here are some of the ideas to get you started. For example, you can use it:
- Where you need some sort of virtual filesystem.
- When parsing several directories, accessing filesystem directly and iterating through the directories means more memory usage and consumption of resources.
- To index your directories and easily locate the place you are looking for.
- Or may be you can use it to search files or folders based on some keywords.
I would love to know how you end up using it.
Requirements
php >= 5.4.0 is required
Installation
The recommended way of installation is using composer. Update your project's composer.json
file and add the following:
And run composer install
or simply run
Getting Started
Currently json
and array
are the only supported representations however you can easily extend it to add support for other formats such as XML or YML etc, I will show you how easy it is to do that in a moment.
Let's stick to the topic, how to use, for now.
Introducing the classes First things first, introduce the classes that we are going to use, in your scope.
Smashing a directory Generating JSON representation from the directory
..back to directory structure Turning the JSON representation back to directory structure
Example
Assuming the following directory structure.
If I want to generate the JSON representation for the sample-path
and save it inside output
directory
This will create the json file in output/sample-path.json
with the representation similar to the following:
Also note that: @
symbol in the beginning of a key represents the property and the keys without the @
symbol represents a directory. If you'd like to look at the full JSON representation, have a look at this file
Extending to support other formats
In order to extend smasher
for other formats, all you have to do is create a response class by implementing the KamranAhmed\Smasher\Contracts\ResponseContract
and pass the instance of that class to the Scanner
object
Contributing
- Report any bugs
- Suggestions for improvement and any additional functionality
- Add support for additional formats and open a pull request
- Enhancing or improve the available functionality
Feedback
I'd love to hear what you have to say. Please open an issue for any feature requests that you may want or the bugs that you notice. Also you can contact me at [email protected] or you can also find me at twitter @kamranahmed_se