Skip to content

Commit

Permalink
Add composer PSR-0 autoloader and namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidpeywasti committed Sep 22, 2017
1 parent 0941c97 commit 5397a85
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 69 deletions.
1 change: 1 addition & 0 deletions config/autoload.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
; List modules which are required to be loaded beforehand
;;
requires[] = "core"
requires[] = "*_autoload"
requires[] = "changelanguage"

;;
Expand Down
42 changes: 5 additions & 37 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,12 @@
* @license LGPL-3.0+
*/


/**
* Register the namespaces
*/
ClassLoader::addNamespaces(array
(
'Respinar\Products',
));


/**
* Register the classes
/**
* Register PSR-0 namespaces
*/
ClassLoader::addClasses(array
(
// Modules
'Respinar\Products\ModuleProduct' => 'system/modules/products/library/Respinar/Products/Frontend/Module/ModuleProduct.php',
'Respinar\Products\ModuleProductDetail' => 'system/modules/products/library/Respinar/Products/Frontend/Module/ModuleProductDetail.php',
'Respinar\Products\ModuleProductList' => 'system/modules/products/library/Respinar/Products/Frontend/Module/ModuleProductList.php',

// Elements
'Respinar\Products\ContentProduct' => 'system/modules/products/library/Respinar/Products/Frontend/Element/ContentProduct.php',
'Respinar\Products\ContentProductSingle'=> 'system/modules/products/library/Respinar/Products/Frontend/Element/ContentProductSingle.php',

// Models
'Respinar\Products\ProductPriceModel' => 'system/modules/products/library/Respinar/Products/Model/ProductPriceModel.php',
'Respinar\Products\ProductModel' => 'system/modules/products/library/Respinar/Products/Model/ProductModel.php',
'Respinar\Products\ProductCatalogModel' => 'system/modules/products/library/Respinar/Products/Model/ProductCatalogModel.php',

// Classes
'Respinar\Products\Product' => 'system/modules/products/library/Respinar/Products/Product.php',

// Change Language Classes
'Respinar\Products\EventListener\CallbackSetupListener' => 'system/modules/products/library/Respinar/Products/EventListener/CallbackSetupListener.php',
'Respinar\Products\EventListener\Navigation\ProductNavigationListener' => 'system/modules/products/library/Respinar/Products/EventListener/Navigation/ProductNavigationListener.php',
'Respinar\Products\EventListener\DataContainer\ProductListener' => 'system/modules/products/library/Respinar/Products/EventListener/DataContainer/ProductListener.php'
));

if (class_exists('NamespaceClassLoader')) {
NamespaceClassLoader::add('Respinar\Products', 'system/modules/products/library');
}

/**
* Register the templates
Expand Down
18 changes: 13 additions & 5 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
),
));

/**
* Register models
*/

$GLOBALS['TL_MODELS']['tl_product'] = 'Respinar\Products\Model\ProductModel';
$GLOBALS['TL_MODELS']['tl_product_catalog'] = 'Respinar\Products\Model\ProductCatalogModel';
$GLOBALS['TL_MODELS']['tl_product_price'] = 'Respinar\Products\Model\ProductPriceModel';

/**
* Front end modules
*/
Expand All @@ -45,26 +53,26 @@
(
'products' => array
(
'product_list' => 'ModuleProductList',
'product_detail' => 'ModuleProductDetail',
'product_list' => 'Respinar\Products\Frontend\Module\ModuleProductList',
'product_detail' => 'Respinar\Products\Frontend\Module\ModuleProductDetail',
)
));


/**
* Content elements
*/
$GLOBALS['TL_CTE']['miscellaneous']['product'] = 'Respinar\Products\ContentProductSingle';
$GLOBALS['TL_CTE']['miscellaneous']['product'] = 'Respinar\Products\Frontend\Element\ContentProductSingle';


/**
* Register hook to add carpets items to the indexer
*/
$GLOBALS['TL_HOOKS']['getSearchablePages'][] = array('Product', 'getSearchablePages');
$GLOBALS['TL_HOOKS']['getSearchablePages'][] = array('Respinar\Products\Product', 'getSearchablePages');


// Registrieren im Hooks replaceInsertTags
$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('Product', 'productURLInsertTags');
$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('Respinar\Products\Product', 'productURLInsertTags');


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use Contao\Date;
use Contao\Model;
use Respinar\Products\ProductModel;
use Respinar\Products\Model\ProductModel;
use Terminal42\ChangeLanguage\EventListener\DataContainer\AbstractChildTableListener;

class ProductListener extends AbstractChildTableListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Respinar\Products\EventListener\Navigation;

use Respinar\Products\ProductCatalogModel;
use Respinar\Products\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;
use Respinar\Products\Model\ProductModel;
use Contao\PageModel;
use Haste\Input\Input;
use Terminal42\ChangeLanguage\EventListener\Navigation\AbstractNavigationListener;
Expand Down
6 changes: 4 additions & 2 deletions library/Respinar/Products/Frontend/Element/ContentProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
/**
* Run in a custom namespace, so the class can be replaced
*/
namespace Respinar\Products;
namespace Respinar\Products\Frontend\Element;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;

/**
* Class ContentProduct
Expand Down Expand Up @@ -48,7 +50,7 @@ protected function sortOutProtected($arrCatalogs)
}

$this->import('FrontendUser', 'User');
$objCatalog = \ProductCatalogModel::findMultipleByIds($arrCatalogs);
$objCatalog = ProductCatalogModel::findMultipleByIds($arrCatalogs);
$arrCatalogs = array();

if ($objCatalog !== null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Frontend\Element;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;
use Respinar\Products\Frontend\Element\ContentProduct;

/**
* Class ContentProduct
Expand All @@ -25,7 +28,7 @@
* @author Hamid Abbaszadeh
* @package Devtools
*/
class ContentProductSingle extends \ContentProduct
class ContentProductSingle extends ContentProduct
{

/**
Expand All @@ -46,7 +49,7 @@ public function generate()

$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['product'][0]) . ' ###';

$objProduct = \ProductModel::findBy('id',$this->product);
$objProduct = ProductModel::findBy('id',$this->product);

$objTemplate->title = $this->headline;
$objTemplate->id = $objProduct->id;
Expand All @@ -70,7 +73,7 @@ public function generate()
protected function compile()
{

$objProduct = \ProductModel::findBy('id',$this->product);
$objProduct = ProductModel::findBy('id',$this->product);

if (null === $objProduct)
{
Expand Down
6 changes: 4 additions & 2 deletions library/Respinar/Products/Frontend/Module/ModuleProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
/**
* Run in a custom namespace, so the class can be replaced
*/
namespace Respinar\Products;
namespace Respinar\Products\Frontend\Module;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;

/**
* Class ModuleProduct
Expand Down Expand Up @@ -48,7 +50,7 @@ protected function sortOutProtected($arrCatalogs)
}

$this->import('FrontendUser', 'User');
$objCatalog = \ProductCatalogModel::findMultipleByIds($arrCatalogs);
$objCatalog = ProductCatalogModel::findMultipleByIds($arrCatalogs);
$arrCatalogs = array();

if ($objCatalog !== null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Frontend\Module;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;

/**
* Class ModuleProductDetail
Expand All @@ -25,7 +27,7 @@
* @author Hamid Abbaszadeh
* @package Devtools
*/
class ModuleProductDetail extends \ModuleProduct
class ModuleProductDetail extends ModuleProduct
{

/**
Expand Down Expand Up @@ -78,7 +80,7 @@ protected function compile()
$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
$this->Template->relateds_headline = $GLOBALS['TL_LANG']['MSC']['relateds_headline'];

$objProduct = \ProductModel::findPublishedByParentAndIdOrAlias(\Input::get('items'),$this->product_catalogs);
$objProduct = ProductModel::findPublishedByParentAndIdOrAlias(\Input::get('items'),$this->product_catalogs);

if (null === $objProduct)
{
Expand Down Expand Up @@ -120,7 +122,7 @@ protected function compile()

if (!empty($objProduct->related)) {

$objProducts = \ProductModel::findPublishedByIds($objProduct->related);
$objProducts = ProductModel::findPublishedByIds($objProduct->related);

$this->Template->relateds = $this->parseRelateds($objProducts);
}
Expand Down
12 changes: 7 additions & 5 deletions library/Respinar/Products/Frontend/Module/ModuleProductList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Frontend\Module;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;

/**
* Class ModuleCatalogList
Expand All @@ -25,7 +27,7 @@
* @author Hamid Abbaszadeh
* @package Devtools
*/
class ModuleProductList extends \ModuleProduct
class ModuleProductList extends ModuleProduct
{

/**
Expand Down Expand Up @@ -103,7 +105,7 @@ protected function compile()
$this->Template->products = array();
$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyCatalog'];

$intTotal = \ProductModel::countPublishedByPids($this->product_catalogs,$blnFeatured);
$intTotal = ProductModel::countPublishedByPids($this->product_catalogs,$blnFeatured);

if ($intTotal < 1)
{
Expand Down Expand Up @@ -180,11 +182,11 @@ protected function compile()
// Get the items
if (isset($limit))
{
$objProducts = \ProductModel::findPublishedByPids($this->product_catalogs, $blnFeatured, $limit, $offset, $arrOptions);
$objProducts = ProductModel::findPublishedByPids($this->product_catalogs, $blnFeatured, $limit, $offset, $arrOptions);
}
else
{
$objProducts = \ProductModel::findPublishedByPids($this->product_catalogs, $blnFeatured, 0, $offset, $arrOptions);
$objProducts = ProductModel::findPublishedByPids($this->product_catalogs, $blnFeatured, 0, $offset, $arrOptions);
}


Expand Down
2 changes: 1 addition & 1 deletion library/Respinar/Products/Model/ProductCatalogModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Model;

/**
* Class CatalogModel
Expand Down
2 changes: 1 addition & 1 deletion library/Respinar/Products/Model/ProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Model;

/**
* Class ProductModel
Expand Down
2 changes: 1 addition & 1 deletion library/Respinar/Products/Model/ProductPriceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Namespace
*/
namespace Respinar\Products;
namespace Respinar\Products\Model;

/**
* Class CatalogPriceModel
Expand Down
10 changes: 6 additions & 4 deletions library/Respinar/Products/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
namespace Respinar\Products;

use Respinar\Products\Model\ProductModel;
use Respinar\Products\Model\ProductCatalogModel;

/**
* Class Product
Expand Down Expand Up @@ -49,7 +51,7 @@ public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false)
$arrProcessed = array();

// Get all catalog categories
$objCatalog = \ProductCatalogModel::findByProtected('');
$objCatalog = ProductCatalogModel::findByProtected('');

// Walk through each archive
if ($objCatalog !== null)
Expand Down Expand Up @@ -101,7 +103,7 @@ public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false)
$strUrl = $arrProcessed[$objCatalog->jumpTo];

// Get the items
$objProduct = \ProductModel::findPublishedByPid($objCatalog->id);
$objProduct = ProductModel::findPublishedByPid($objCatalog->id);

if ($objProduct !== null)
{
Expand Down Expand Up @@ -152,12 +154,12 @@ public function productURLInsertTags($strTag)
if (isset($arrSplit[1]))
{
// Get the items
if (($objProduct = \ProductModel::findPublishedByIdOrAlias($arrSplit[1])) === null)
if (($objProduct = ProductModel::findPublishedByIdOrAlias($arrSplit[1])) === null)
{
return false;
}

$objCatalog = \ProductCatalogModel::findBy('id',$objProduct->pid);
$objCatalog = ProductCatalogModel::findBy('id',$objProduct->pid);

$objParent = \PageModel::findWithDetails($objCatalog->jumpTo);

Expand Down

0 comments on commit 5397a85

Please sign in to comment.