Code Monkey home page Code Monkey logo

libraryrewrite's Introduction

WARNING: THIS IS A DEPRECATED EXPERIMENT

Please consider using Danslo_Aop instead!

Danslo_LibraryRewrite

Why?

Please read this StackExchange post. In short: How magento is currently set up, we cannot change libraries and/or abstract classes without copying them entirely to an earlier loaded codepool (basically, include path) and editing them there. That really sucks when you need to make a bunch of changes to core libraries.

How does it work?

  1. We register an autoloader.
  2. While loading a class, the autoloader checks Magento configuration to see if you have any library rewrites configured.
  3. When you do, it will:
    • Wrap the class in a namespace.
    • Replace extends for that class to use the global namespace (to prevent the Magento autoloader from choking).
    • Do the same for static property or class constant lookups (damn that Magento autoloader).
    • Stick this class in a temporary folder (currently var/tmp/library_rewrite).
    • Include the (namespaced) class.
    • Include your (non-namespaced) class.
  4. You can now extend from the namespaced class and only change some of the functionality.

Installing

  1. If composer is not already installed, do so.
  2. Create a composer.json with the following (or similar) contents:
{
    "require": {
        "danslo/libraryrewrite": "~1.0.0"
    },
    "extra": {
        "magento-root-dir": "htdocs/"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/danslo/LibraryRewrite.git"
        }
    ]
}

Finally, issue the composer install command.

Registering rewrites

  • Create an ordinary Magento module that depends on Danslo_LibraryRewrite.
  • In your config.xml, add something like:
<?xml version="1.0"?>
<config>
    <global>
        <libraries>
            <rewrite>
                <The_Library_Class_To_Rewrite>YourNamespace_YourModule</The_Library_Class_To_Rewrite>
            </rewrite>
        </libraries>
    </global>
</config>
  • Create a file in app/code/<YourCodePool>/<YourNamespace>/<YourModule>/lib/<PathToTheLibrary>.
  • The contents of the class should itself live in global namespace and extend from the Magento namespace:
<?php

class The_Library_Class_To_Rewrite extends Magento\The_Library_Class_To_Rewrite
{
    // Rewrite any method in here.
}

License

The MIT License (MIT)

Copyright (c) 2014 Daniel Sloof

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

libraryrewrite's People

Contributors

danslo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

libraryrewrite's Issues

Trouble with Exceptions

Hi there,

Just coming across this because I'm trying to use the AoE_AmazonCdn exception, and am having trouble getting it working.

It seems to me there's a problem with this library..

The problem I'm having is I go to upload an image to a catalog product, and when I hit save I get this error:

Fatal error: Class 'Magento\Exception' not found in /var/www/web/var/tmp/library_rewrite/2934697358.php on line 414

That line contains the following code:

throw new Exception('Unable to list current working directory.');

So, it's trying to use Magento\Exception since we're in the namespace Magento for this file.

It seems your library_rewrite isn't escaping things to the global namespace when required. For instance it should probably be:

throw new \Exception('Unable to list current working directory.');

Or have a use statement at the beginning of the file.

Any ideas to solve this? It seems like the AoE_AmazonCdn plugin is popular, so I'm not quite sure why this doesn't work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.