Giter Club home page Giter Club logo

Comments (10)

speller avatar speller commented on July 28, 2024

I guess the issue is in the absence of the autoload section in the composer.json file.

from cm_redissession.

colinmollenhour avatar colinmollenhour commented on July 28, 2024

Thanks @speller - @justinbeaty do you have any additional insight on this, it does appear that an autoload declaration is needed but not sure what your plans were for it exactly.

from cm_redissession.

justinbeaty avatar justinbeaty commented on July 28, 2024

I guess it could be added, but I don't typically see Magento modules doing this.

If the module is installed with Cotya/magento-composer-installer (or modman, etc) then it is placed into app/code/community and Magento will find the class. For example:

<?php
define('MAGENTO_ROOT', '/home/www-data/magento-root/htdocs');

require MAGENTO_ROOT . '/app/bootstrap.php';
require_once MAGENTO_ROOT . '/app/Mage.php';
 
Mage::app();
 
$c = new Cm_RedisSession_Model_Session();

I think adding an autoloader would be equivalent to adding one to colinmollenhour/Cm_OrderProducts so someone could call new Cm_OrderProducts_Model_System_Config_Source_Filter(). But what is the point? Unless I am missing something...

Edit: So I think if there's a use-case for a separate entry point like in the OP's 1.php, why not just bootstrap Magento? Even if we did add an autoload entry I don't think any of the other Mage_ classes would work.

from cm_redissession.

speller avatar speller commented on July 28, 2024

In my case, I'm not using any module managers and use a customized Magento 1 instance that can load backend-only modules directly from the composer directory without copying or symlinking. So I need this package classes to be available for the composer autoloader.

The Cm_Cache_Backend_Redis module has the autoloader section and it works fine.

from cm_redissession.

justinbeaty avatar justinbeaty commented on July 28, 2024

Interesting; I’m surprised that works since this module has calls to Mage::app(). But in any case, I don’t think adding an autoload entry would negatively affect an install into OpenMage. If you want to make a PR it sounds like Colin would merge it. I would just double check that having the autoload entry still allows one to override the class via Magento‘s config.xml (which I can also test later today).

from cm_redissession.

justinbeaty avatar justinbeaty commented on July 28, 2024

I added an autoload entry in my fork and installed via composer justinbeaty@2527c53

The results are that the class can now be loaded with:

<?php

include_once 'vendor/autoload.php';

$c = new \Cm\RedisSession\Model\Session();

But this throws a new error:

$ php test.php 
PHP Fatal error:  Uncaught Error: Interface 'Zend_Session_SaveHandler_Interface' not found in /home/www-data/magento-root/htdocs/vendor/colinmollenhour/magento-redis-session/app/code/community/Cm/RedisSession/Model/Session.php:32
Stack trace:
#0 /home/www-data/magento-root/htdocs/vendor/composer/ClassLoader.php(478): include()
#1 /home/www-data/magento-root/htdocs/vendor/composer/ClassLoader.php(346): Composer\Autoload\includeFile()
#2 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#3 /home/www-data/magento-root/htdocs/test.php(5): spl_autoload_call()
#4 {main}
  thrown in /home/www-data/magento-root/htdocs/vendor/colinmollenhour/magento-redis-session/app/code/community/Cm/RedisSession/Model/Session.php on line 32

Which is not surprising because the Zend classes do not have autoload entries... Maybe in your customized Magento 1 fork you have autoload entries for those classes too.

So overall I'm not sure this is needed for this repo. Alternatively, could you just define the autoload entry in your own composer.json?

"psr-0": {
    "Cm\\RedisSession\\": "vendor/colinmollenhour/magento-redis-session/app/code/community/"
}

from cm_redissession.

speller avatar speller commented on July 28, 2024

But this throws a new error:

The Cm_Cache_Backend_Redis module has the same issue but it works fine in my case.

So overall I'm not sure this is needed for this repo. Alternatively, could you just define the autoload entry in your own composer.json?

This is a working option, thank you. But as this doesn't break existing package functionality, could you add it to the package repo, please?

from cm_redissession.

speller avatar speller commented on July 28, 2024

I just double-checked the psr-0 solution and found that the $c = new \Cm\RedisSession\Model\Session() triggers a correct autoloading but the class name is still Cm_RedisSession_Model_Session and can't be found by PHP. The proper variant is:

  "autoload": {
    "psr-0": {
      "Cm_RedisSession_": "vendor/colinmollenhour/magento-redis-session/app/code/community/"
    }
  }

This makes the $c = new Cm_RedisSession_Model_Session() code working fine.

Moreover, the Cm\RedisSession\ autoload namespace is already taken by the colinmollenhour/php-redis-session-abstract package.

from cm_redissession.

colinmollenhour avatar colinmollenhour commented on July 28, 2024

An important distinction between Cm_Cache_Backend_Redis and Cm_RedisSession is that the former is just a class that extends Zend_Cache_Backend_Abstract and can be used anywhere and the latter is a Magento module which is designed to have classes loaded via Varien_Autoload. Does your custom Magento setup not use Varien_Autoload?

from cm_redissession.

colinmollenhour avatar colinmollenhour commented on July 28, 2024

Your last example looks fine for your project composer.json file but for a module I don't think it is a proper use of composer so I'd prefer not to commit it to this repo.

from cm_redissession.

Related Issues (20)

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.