Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Provide easy access to composer loader object
Browse files Browse the repository at this point in the history
Also includes some code style fixes and license header updates.
  • Loading branch information
Matthew Gamble committed Feb 20, 2019
1 parent 2470fcb commit edebd4f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Installation
"require" section:
```
"fontis/composer-autoloader": "2.0.*"
"fontis/composer-autoloader": "2.1.*"
```
2. Edit `app/etc/local.xml` and add the following XML. Modify the path to suit
Expand Down Expand Up @@ -53,4 +53,4 @@ line versus how Magento does it for web requests.
This is an improvement over v1 of this extension, where you had to manually
dispatch an event after bootstrapping Magento to ensure the composer autoloader
was required.
was required in command-line scripts.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"homepage": "http://www.fontis.com.au",
"authors": [
{
"name":"Fontis",
"email":"[email protected]"
"name": "Fontis",
"email": "[email protected]"
}
],
"require": {
Expand Down
34 changes: 29 additions & 5 deletions src/app/code/community/Fontis/ComposerAutoloader/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2014 Fontis Pty. Ltd. (http://www.fontis.com.au)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/


use Composer\Autoload\ClassLoader;

class Fontis_ComposerAutoloader_Helper_Data extends Mage_Core_Helper_Abstract
{
const AUTOLOAD_FILENAME = 'autoload.php';
Expand All @@ -32,6 +34,7 @@ public function getVendorDirectoryPath()
if (!$path) {
$path = self::DEFAULT_PATH;
}

$path = str_replace('/', DS, $path);
$path = str_replace('{{basedir}}', Mage::getBaseDir(), $path);
$path = str_replace('{{libdir}}', Mage::getBaseDir('lib'), $path);
Expand All @@ -42,17 +45,38 @@ public function getVendorDirectoryPath()
/**
* @param string|null $path Path to vendor directory. Pass null to use the configured value.
* @param string|null $filename Filename of autoload file. Pass null to use the default (autoload.php).
* @return bool
*/
public function registerAutoloader($path = null, $filename = null)
{
$loader = $this->getAutoloader($path, $filename);
if ($loader) {
return true;
} else {
return false;
}
}

/**
* @param string|null $path Path to vendor directory. Pass null to use the configured value.
* @param string|null $filename Filename of autoload file. Pass null to use the default (autoload.php).
* @return ClassLoader|null
*/
public function getAutoloader($path = null, $filename = null)
{
if ($path === null) {
$path = $this->getVendorDirectoryPath();
}

if ($filename === null) {
$filename = self::AUTOLOAD_FILENAME;
}

if (file_exists($path . DS . $filename)) {
require_once($path . DS . $filename);
// phpcs:ignore MEQP1.Security.IncludeFile.FoundIncludeFile -- No other alternative.
return require($path . DS . $filename);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2014 Fontis Pty. Ltd. (http://www.fontis.com.au)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Fontis_ComposerAutoloader_Model_Observer
{
/**
Expand All @@ -23,13 +23,15 @@ class Fontis_ComposerAutoloader_Model_Observer
protected static $added = false;

/**
* Register the Composer autoloader
* Register the Composer autoloader.
*
* @listen resource_get_tablename
* @param Varien_Event_Observer $observer
*/
public function addComposerAutoloader(Varien_Event_Observer $observer)
{
if (self::$added === false) {
/** @var $helper Fontis_ComposerAutoloader_Helper_Data */
/** @var Fontis_ComposerAutoloader_Helper_Data $helper */
$helper = Mage::helper('fontis_composerautoloader');
$helper->registerAutoloader();
self::$added = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2014 Fontis Pty. Ltd. (http://www.fontis.com.au)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config>
<modules>
<Fontis_ComposerAutoloader>
<version>2.0.3</version>
<version>2.1.1</version>
</Fontis_ComposerAutoloader>
</modules>
</config>
19 changes: 19 additions & 0 deletions src/app/code/community/Varien/Profiler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* Fontis Composer Autoloader
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

// phpcs:disable MEQP1.Security.Superglobal.SuperglobalUsageWarning -- The framework has not been bootstrapped at this point.
// phpcs:disable MEQP1.Security.IncludeFile.FoundIncludeFile -- Also not relevant here, as this is outside the framework.

if (!empty($_SERVER["FCA_PROFILER_PATH"])) {
require_once($_SERVER["FCA_PROFILER_PATH"]);
Expand All @@ -8,6 +26,7 @@
} else {
$FCA_BASEPATH = BP;
}

require_once($FCA_BASEPATH . DS . "lib" . DS . "Varien" . DS . "Profiler.php");
unset($FCA_BASEPATH);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/etc/fontis_composerautoloader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2014 Fontis Pty. Ltd. (http://www.fontis.com.au)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config>
Expand Down
6 changes: 3 additions & 3 deletions src/app/etc/modules/Fontis_ComposerAutoloader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* https://opensource.org/licenses/osl-3.0.php
*
* @category Fontis
* @package Fontis_ComposerAutoloader
* @copyright Copyright (c) 2014 Fontis Pty. Ltd. (http://www.fontis.com.au)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright Copyright (c) 2019 Fontis Pty. Ltd. (https://www.fontis.com.au)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
-->
<config>
Expand Down

0 comments on commit edebd4f

Please sign in to comment.