Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dannydamsky/dev-tools-magento-2-module
A collection of utilities meant to improve the experience of developing modules for Magento without breaking existing functionality.
https://github.com/dannydamsky/dev-tools-magento-2-module
decoding-jsons developer-tools framework framework-php imagemagick json log-rotations magento magento2 magento2-extension magento2-extension-free magento2-module magento2-module-free php php-extension php7 phtml-template twig-templates utilities-meant
Last synced: about 2 months ago
JSON representation
A collection of utilities meant to improve the experience of developing modules for Magento without breaking existing functionality.
- Host: GitHub
- URL: https://github.com/dannydamsky/dev-tools-magento-2-module
- Owner: dannydamsky
- Created: 2020-04-09T18:56:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-04-09T19:23:16.000Z (over 4 years ago)
- Last Synced: 2024-11-02T00:32:27.663Z (2 months ago)
- Topics: decoding-jsons, developer-tools, framework, framework-php, imagemagick, json, log-rotations, magento, magento2, magento2-extension, magento2-extension-free, magento2-module, magento2-module-free, php, php-extension, php7, phtml-template, twig-templates, utilities-meant
- Language: PHP
- Size: 64.5 KB
- Stars: 20
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
DannyDamsky DevTools Extension
=====================
A collection of utilities meant to improve the experience of developing modules for Magento
without breaking existing functionality.-----
- version: 1.0.0
- extension key: DannyDamsky_DevToolsRequirements
------------
- PHP >= 7.3.0
- Magento_Config
- Magento_Eav
- Magento_Cron
- PHP Extension - JSON
- PHP Extension - Imagick
- PHP Extension - SimpleXML
- PHP Extension - ZLibSuggestions
------------
- Twig: Version 2.0 and above, enables the use of twig templates in Magento.Compatibility
-------------
- Magento >= 2.3.3How To Install
-------------
The recommended way to install this module
is with composer.Make sure you have this data in your composer.json file.
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dannydamsky/Dev-Tools-Magento-2-Module"
}
],
"require": {
"dannydamsky/module-devtools": "1.0.0"
}Features
-----------------This module adds useful functionality to Magento 2
without the breaking backwards compatibility or reducing
performance in any way that is significant.This module's features include:
1. Twig Template Support - Include the "twig/twig" package in your composer.json
and you can start writing all of your templates using Twig, with support for
most (if not all) of the functions you normally use in Magento 2 PHTML templates,
and including access to template variables such as "block".2. An extension to the Magento frontend and backend template (block) classes.
This extension enables the use of callable variables in your PHTML template,
so for example instead of typing:escapeHtml("YOUR_STRING_HERE") ?>
You can now use the following in your code:
Usable variables include: $escapeHtml, $escapeHtmlAttr, $escapeJs, $escapeCss, $escapeUrl, and $trans (For translations).
For a full list please take a look at:
DannyDamsky\DevTools\Traits\BlockTrait::_beforeToHtml()
To enable this functionality your block class must extend either of the two classes:
Backend:
DannyDamsky\DevTools\App\Backend\Block\Template
Frontend:
DannyDamsky\DevTools\View\Element\Template
These blocks also include helper methods for generating the x-magento-init scripts.
3. A slight (but important) improvement to the Magento 2 ImageMagick adapter.
The default Magento 2 implementation does not configure ImageMagick to generate
[progressive JPEGs](https://www.liquidweb.com/kb/what-is-a-progressive-jpeg/),
this module enables this behaviour.4. Improvements to Magento 2's JSON serializer. PHP's json_decode function isn't
good at decoding JSONs with lots of unicode and special characters.
This module adds an override to the following function:Magento\Framework\Serialize\Serializer\Json::unserialize
The override attempts to run the above function, but in case of failure
relies on an that algorithm has proven to decode more complicated JSON strings.
5. You no longer have to include registration.php in your modules.
This module is configured to automatically load any module that does
not include this file.
Modules found in the vendor and app/code folders are supported.6. Helper LESS mixins included in the _module.less file of this module
for adding CSS properties with prefixes for browsers.
Prefixes include:- lib-dannydamsky-devtools-prefix-align-items,
- lib-dannydamsky-devtools-prefix-align-content,
- lib-dannydamsky-devtools-prefix-align-self,
- lib-dannydamsky-devtools-prefix-justify-content,
- lib-dannydamsky-devtools-prefix-justify-self
- lib-dannydamsky-devtools-prefix-user-select
For a full list please take a look at:
view/base/web/css/source/_module.less
7. Facade classes supportTo create a facade, you must extend the following class:
DannyDamsky\DevTools\Model\FacadeBy default, this class expects you to put your facade class in:
VendorName\ModuleName\Facade\NAMESPACE_RELATIVE_TO_HELPER\YourFacadeWhere NAMESPACE_RELATIVE_TO_HELPER is the relative namespace
of the helper class that you want to bind the Facade to.
For example, if you want to create a facade for:
DannyDamsky\PlayGround\Helper\Person
Your facade class needs to have the namespace:
DannyDamsky\PlayGround\Facade\Person
And then, any public methods that are accessible from your helper method,
will be automatically accessible in your Facade class as static methods.
In order to override the namespacing behaviour of a Facade class,
you may add a constant that equals that class name of the helper that you wish to bind
the Facade to.
For Example:
execute()
This method takes no arguments, the $setup and $context arguments you are used to
still exist as protected class properties $_setup and $_context.
The $_connection class property also exists, and is equal to the return value
from $setup->getConnection().
If you are used to running:
$setup->startSetup()
And:
$setup->endSetup()
There is no longer a need to do that, these methods are run before and after
the execute() method respectively.
Class Specific Features:
Install/Upgrade Schema Classes:
- Access to the $_schema class property,
which is used for writing Laravel-Like database migration operations.
- Built-in version-control support.Install/Upgrade Data Classes:
- Built-in version-control support.
Uninstall Class:
- Accessible dropTable() class method.
The Schema Class Property:
This property is used for writing Laravel-Like database migration operations.
It is worth mentioning that while the code syntax is similar to Laravel,
the definitions used are completely Magento-specific and if you've
worked with Magento 2 Install/Upgrade Schema classes
you should be able to recognize the methods available
here quite easily.
To create a table you can run $this->_schema->newTable(...)
To alter a table you can run $this->_schema->alterTable(...)
Or you can just run $this->_schema->table(...) and let the schema
property decide if the table should be altered or created
(by checking if the table exists in the first place).
Either of the 3 functions mentioned above accept the same arguments,
the first one is the table name, and the second one is a callable
that accepts a $blueprint as an argument.
Below is a code sample showing how to use this property:
$this->_schema->table('dannydamsky_playground_random_table',
function (\DannyDamsky\DevTools\Api\BlueprintInterface $blueprint) {
$blueprint->bigint('entity_id', true)
->setIdentity(true)
->setNullable(false)
->setPrimary(true)
->setComment('Entity ID');
$blueprint->text('some_text', 255)
->setNullable(true);
}
);
$this->_schema->addIndex('dannydamsky_playground_random_table', 'some_text');This code creates a table called "dannydamsky_playground_random_table",
with an "entity_id" column and a "some_text" column. It also sets an index
on the "some_text" column after the table has been created.
For further information please take a look at these interfaces:
The $_schema property:
DannyDamsky\DevTools\Api\SchemaInterface
The $blueprint argument:
DannyDamsky\DevTools\Api\BlueprintInterface
The return value from column function calls of the $blueprint argument:
DannyDamsky\DevTools\Api\ColumnDefinitionInterface
The Built-In Version-Control Support:
The Install/Upgrade Data/Schema classes provide version control support.
Which means that you are not required to use the abstract execute()
method, instead you can leave it empty and create methods for every version of the
module (or you can use them both), by creating methods with the following naming scheme:
public function __vMODULE_VERSION_WITH_UNDERSCORES_INSTEAD_OF_DOTS()
{
// Your Migration Here
}
The code in the abstract Install/Upgrade Data/Schema class' install() and upgrade()
will know to run these methods, and will know to compare their versions to your current module version.
Here's an example of such a method:
public function __v1_0_4()
{
$this->_schema->table('dannydamsky_playground_random_table',
function (\DannyDamsky\PlayGround\Api\BlueprintInterface $blueprint) {
$blueprint->text('some_text')
->setNullable(false)
->setDefault('')
->setComment('Some Text');
}
);
}
Here is sample UpgradeData class from the DannyDamsky\PlayGround sample module:
_schema->table('dannydamsky_playground_random_table', static function (BlueprintInterface $blueprint): void {
$blueprint->bigint('entity_id', true)
->setIdentity(true)
->setNullable(false)
->setPrimary(true)
->setComment('Entity ID');
$blueprint->text('some_text', 255)
->setNullable(true);
});
}
/**
* @throws Throwable
*/
public function __v1_0_4(): void
{
$this->_schema->table('dannydamsky_playground_random_table', static function (BlueprintInterface $blueprint): void {
$blueprint->text('some_text')
->setNullable(false)
->setDefault('')
->setComment('Some Text');
});
}
}10. Log rotation support (Configurable in admin)
Enables [log rotation](https://en.wikipedia.org/wiki/Log_rotation) functionality from inside Magento 2,
with support for features such as moving log each day to a separate
directory with a timestamp as its name, compressing log files with GZIP, and
deleting the log files after a configured number of days.
This feature must be enabled in the admin configuration. (See the configuration section for more details)11. JS polyfills support (Configurable in admin)
Enables loading a JS polyfills script to your website,
which enables the use of the most-used ES5, ES6 and ES7
functions for all browsers.
In order to do that, it uses the [Polyfill.IO](https://polyfill.io) API, which
can be changed to something else in the admin configurations.
Polyfill.IO is particularly good because it gives different results to different browsers, so
newer browser versions will not have a noticeable performance impact from loading the polyfills.
This feature must be enabled in the admin configuration. (See the configuration section for more details)Configurations
---------------All of this module's configurations are located in the Magento 2 admin page
in the route:Stores -> Configurations -> Advanced -> Developer
(These configurations only show up when you're in developer mode)The configurations in this route that belong to this module include:
1. Debug - Enable Printing of Twig Generated Templates
2. Template Settings - Auto-Recompile Twig Templates
3. Template Settings - Twig Strict Variables
4. Template Settings - Twig Template Charset
5. JavaScript Settings - Enable JS Polyfills
6. JavaScript Settings - Polyfill API URL (Depends on JS polyfills being enabled)
7. Caching Settings - Cache Twig Templates
8. Log Rotation Settings - Enabled
9. Log Rotation Settings - Compress (Depends on log rotations being enabled)
10. Log Rotation Settings - Days (Depends on log rotations being enabled)Sample Module
-------------[Click Here To Download](https://github.com/dannydamsky/Dev-Tools-Magento-2-Module/releases/download/1.0.0/DannyDamsky_PlayGround.tar.gz)
Developer
---------
Danny DamskyLicence
-------
Copyright (c) 2020 Danny DamskyRedistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the author nor the names of its contributors may
be used to endorse or promote products derived from this softwareTHIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.