How to use Zend Framework 1 when is installed through composer? - php

Recently I discovered that Zend Framework 1 (ZF1) can be installed using composer so I did a: composer require zendframework/zendframework1. That change my composer.json by adding the following:
{
...
"autoload": {
"psr-0": { "": ["application/models", "application/controllers", "application/forms"]},
"psr-4": { "": ["src/", "library/"]}
},
"require": {
...
"zendframework/zendframework1": "^1.12"
}
}
After run the command composer update and composer dump-autoload I look into the composer generated files and I can see the following:
/vendor/composer/autoload_files.php
===================================
// autoload_files.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'92c8763cd6170fce6fcfe7e26b4e8c10' => $vendorDir . '/symfony/phpunit-bridge/bootstrap.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'b067bc7112e384b61c701452d53a14a8' => $vendorDir . '/mtdowling/jmespath.php/src/JmesPath.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'8a9dc1de0ca7e01f3e08231539562f61' => $vendorDir . '/aws/aws-sdk-php/src/functions.php',
'5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php',
'023d27dca8066ef29e6739335ea73bad' => $vendorDir . '/symfony/polyfill-php70/bootstrap.php',
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
'6a47392539ca2329373e0d33e1dba053' => $vendorDir . '/symfony/polyfill-intl-icu/bootstrap.php',
'32dcc8afd4335739640db7d200c1971d' => $vendorDir . '/symfony/polyfill-apcu/bootstrap.php',
'3a37ebac017bc098e9a86b35401e7a68' => $vendorDir . '/mongodb/mongodb/src/functions.php',
);
/vendor/composer/autoload_namespaces.php
===================================
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Zend_' => array($vendorDir . '/zendframework/zendframework1/library'),
'Twig_' => array($vendorDir . '/twig/twig/lib'),
'SensioLabs\\Security' => array($vendorDir . '/sensiolabs/security-checker'),
'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'),
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'),
'' => array($baseDir . '/application/models', $baseDir . '/application/controllers', $baseDir . '/application/forms'),
);
/vendor/composer/include_paths.php
===================================
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
$vendorDir . '/zendframework/zendframework1/library',
);
I am trying to use then the class from the application/bootstrap.php file as for example:
use Zend_Config_Ini;
$config = new Zend_Config_Ini('./../config/config.ini', 'general');
But PHP is complaining with the following error:
PHP Fatal error: Uncaught Error: Class 'Zend_Config_Ini' not found in
/var/www/html/application/bootstrap.php:23
Why? What I am missing here?

That are composer basics, you need to include the autoloader file to be able to load those classes.
require __DIR__ . '/vendor/autoload.php';

Related

Symfony autoloading a namespace on every controller

I have already seen that there is an autoload_namespace.php file in Symfony but I cant seem to get it to work.
I want to autoload the: Symfony\Component\HttpFoundation\Session\Session namespace.
Here is the autoload_namespace.php so far
<?php
// autoload_namespaces.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Twig_' => array($vendorDir . '/twig/twig/lib'),
'SensioLabs\\Security' => array($vendorDir . '/sensiolabs/security-checker'),
'Psr\\Log\\' => array($vendorDir . '/psr/log'),
'Doctrine\\ORM\\' => array($vendorDir . '/doctrine/orm/lib'),
'Doctrine\\DBAL\\' => array($vendorDir . '/doctrine/dbal/lib'),
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'),
'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib'),
//this is the session namespace i want to auto include
'Symfony\\Component\\HttpFoundation\\Session\\Session\\' => array($vendorDir . '/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Session.php')
);
Thanks

Cannot find existing key in array

I'm working with composer and I have the following classmap:
return array(
'Wit\\Cache\\CacheAdapterInterface' => $baseDir . '/src/Wit/Cache/CacheAdapterInterface.php',
'Wit\\Cache\\CacheManager' => $baseDir . '/src/Wit/Cache/CacheManager.php',
'Wit\\Cache\\FileAdapter' => $baseDir . '/src/Wit/Cache/FileAdapter.php',
'Wit\\Cache\\RedisAdapter' => $baseDir . '/src/Wit/Cache/RedisAdapter.php',
'Wit\\Request\\Request' => $baseDir . '/src/Wit/Request/Request.php',
'Wit\\Zenpoint\\ZenpointUser' => $baseDir . '/src/Wit/Zenpoint/ZenpointUser.php',
'Wit\\Zenpoint\\ZenpointConfig' => $baseDir . '/src/Wit/Zenpoint/ZenpointConfig.php',
'Wit\\Zenpoint\\ZenpointCarrello' => $baseDir . '/src/Wit/Zenpoint/ZenpointCarrello.php',
'Wit\\Zenpoint\\ZenpointAcquisitions' => $baseDir . '/src/Wit/Zenpoint/ZenpointAcquisitions.php',
'Wit\\Zenpoint\\ZenpointAcquisition' => $baseDir . '/src/Wit/Zenpoint/ZenpointAcquisition.php',
'Wit\\Cart\\ZipCodeChecker' => $baseDir . '/src/Wit/Cart/ZipCodeChecker.php',
'Wit\\Cart\\ZipCodeLoader' => $baseDir . '/src/Wit/Cart/ZipCodeLoader.php',
'Wit\\Complimentary\\OmaggioOrdine' => $baseDir . '/src/Wit/Complimentary/OmaggioOrdine.php',
'Wit\\Complimentary\\PacchettoOmaggio' => $baseDir . '/src/Wit/Complimentary/PacchettoOmaggio.php',
'Wit\\Complimentary\\ProdottiAScelta' => $baseDir . '/src/Wit/Complimentary/ProdottiAScelta.php',
'Wit\\Complimentary\\OmaggioLoader' => $baseDir . '/src/Wit/Complimentary/OmaggioLoader.php',
'Wit\\Complimentary\\PacchettoLoader' => $baseDir . '/src/Wit/Complimentary/PacchettoLoader.php',
'Wit\\Complimentary\\ProdottiASceltaLoader' => $baseDir . '/src/Wit/Complimentary/ProdottiASceltaLoader.php',
'Wit\\Complimentary\\ProdottiLoader' => $baseDir . '/src/Wit/Complimentary/ProdottiLoader.php',
);
I then have the following in a file: use WIT\Complimentary\OmaggioLoader;
The problem is that PHP says it cannot find the class:
Fatal error: Class 'WIT\ComplimentaryProducts\OmaggioLoader' not found.
The first thing I thought was that the path was wrong, but it doesn't seem so. So I tried to see what was happening in the Composer ClassLoader.php file and dumped the following:
var_dump($class); //string(31) "WIT\Complimentary\OmaggioLoader"
var_dump(array_keys($this->classMap)); //[15]=> string(31) "Wit\Complimentary\OmaggioLoader"
var_dump(array_key_exists($class, $this->classMap)); //bool(false)
var_dump($this->classMap[$class]); //NULL
var_dump($this->classMap['Wit\\Complimentary\\OmaggioLoader']);//string(69) "/path/to/Wit/Complimentary/OmaggioLoader.php"
So, why PHP cannot find the array element if the key is correct? Why if I insert it manually, will PHP finds it?
Class names in PHP are case insensitive, array keys are not. They have different beginning.

Thumb create in Yii2 gives an error

I want to create a thumb but am getting this error:
PHP Fatal Error – yii\base\ErrorException
Class 'Imagine\Image\ManipulatorInterface' not found
I don't know from where i can get this? I used yii2-imagine but didn't find any ManipulatorInterface class.
controller file:
<?php
namespace backend\controllers;
use Yii;
use app\models\Employee;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\imagine\Image; // this is where i used Image class
public function actionCreate()
{
$model = new Employee();
$model->added_date_time = date('Y-m-d H:i:s');
if($model->load(Yii::$app->request->post())) {
$model->file = UploadedFile::getInstance($model,'avatar');
if(!empty($model->file)) {
$imageName = Yii::$app->security->generateRandomString();
$model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
$model->avatar = $imageName.'.'.$model->file->extension;
$file = 'uploads/'.$imageName.'.'.$model->file->extension;
Image::thumbnail($file, 200, 200)->save('uploads/thumb/', ['quality' => 80]);
}
if($model->save()){
$this->redirect(\Yii::$app->urlManager->createUrl('employee'));
}
}
else {
return $this->render('create', [
'model' => $model
]);
}
}
?>
Image class file is in \vendor\yiisoft\yii2\imagine folder and ManipulatorInterface is in \vendor\yiisoft\yii2\imagine\Imagefolder
Image.php
<?php
namespace yii\Imagine;
class Image extends BaseImage
{
}
?>
BaseImage.php
<?php
namespace yii\imagine;
use Yii;
use imagine\Image\Box;
use imagine\Image\Color;
use imagine\Image\ImageInterface;
use imagine\Image\ImagineInterface;
use imagine\Image\ManipulatorInterface;
use imagine\Image\Point;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
class BaseImage
{
public static function thumbnail($filename, $width, $height, $mode = 'outbound')
{
$box = new Box($width, $height);
$img = static::getImagine()->open(Yii::getAlias($filename));
if (($img->getSize()->getWidth() <= $box->getWidth() && $img->getSize()->getHeight() <= $box->getHeight()) || (!$box->getWidth() && !$box->getHeight())) {
return $img->copy();
}
$img = $img->thumbnail($box, $mode);
// create empty image to preserve aspect ratio of thumbnail
$thumb = static::getImagine()->create($box, new Color('FFF', 100));
// calculate points
$size = $img->getSize();
$startX = 0;
$startY = 0;
if ($size->getWidth() < $width) {
$startX = ceil($width - $size->getWidth()) / 2;
}
if ($size->getHeight() < $height) {
$startY = ceil($height - $size->getHeight()) / 2;
}
$thumb->paste($img, new Point($startX, $startY));
return $thumb;
}
?>
I have the same problem. I try 'composer global require "fxp/composer-asset-plugin:~1.0.0"' after that I try 'composer.phar require --prefer-dist yiisoft/yii2-imagine' again and it's work for me. Hope it helps you too
you can try this:
1) copy imagine to your vendor
`pathA: "vendor/Imagine/Draw...."`
2) add a alias into config.php
'components' => [
],
....
'aliases'=>[
'#Imagine'=>'#vendor/Imagine', //this should correspond to pathA above
],
....
'params' => [
],
3) check vendor/composer/autoload_psr4.php
config it like this
return array(
...
'yii\\imagine\\' => array($vendorDir . '/yiisoft/yii2-imagine'),
...
);
4) copy yii-imagine into yiisoft
pathB:"vendor/yiisoft/yii-imagine"
then you can use it .
I have resolved to set path in extensions.php under the yiisoft folder.
Just follow 2 steps:
Open extensions.php
On the bottom of the file add
'yiisoft/yii2-imagine' =>
array (
'name' => 'yiisoft/yii2-imagine',
'version' => '~2.0.0',
'alias' =>
array (
'#yii/imagine' => $vendorDir . '/yiisoft/yii2-imagine',
'#Imagine/Image' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Image',
'#Imagine/Gd' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Gd',
'#Imagine/Draw' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Draw',
'#Imagine/Effects' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Effects',
'#Imagine/Exception' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Exception',
'#Imagine/Filter' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Filter',
'#Imagine/Gmagick' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Gmagick',
'#Imagine/Imagick' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Imagick',
'#Imagine/resources' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/resources',
),
),
So my extensions.php looks like
<?php
$vendorDir = dirname(__DIR__);
return array (
'yiisoft/yii2-swiftmailer' =>
array (
'name' => 'yiisoft/yii2-swiftmailer',
'version' => '2.0.6.0',
'alias' =>
array (
'#yii/swiftmailer' => $vendorDir . '/yiisoft/yii2-swiftmailer',
),
),
'yiisoft/yii2-bootstrap' =>
array (
'name' => 'yiisoft/yii2-bootstrap',
'version' => '2.0.6.0',
'alias' =>
array (
'#yii/bootstrap' => $vendorDir . '/yiisoft/yii2-bootstrap',
),
),
'yiisoft/yii2-debug' =>
array (
'name' => 'yiisoft/yii2-debug',
'version' => '2.0.6.0',
'alias' =>
array (
'#yii/debug' => $vendorDir . '/yiisoft/yii2-debug',
),
),
'yiisoft/yii2-gii' =>
array (
'name' => 'yiisoft/yii2-gii',
'version' => '2.0.5.0',
'alias' =>
array (
'#yii/gii' => $vendorDir . '/yiisoft/yii2-gii',
),
),
'yiisoft/yii2-faker' =>
array (
'name' => 'yiisoft/yii2-faker',
'version' => '2.0.3.0',
'alias' =>
array (
'#yii/faker' => $vendorDir . '/yiisoft/yii2-faker',
),
),
'yiisoft/yii2-imagine' =>
array (
'name' => 'yiisoft/yii2-imagine',
'version' => '~2.0.0',
'alias' =>
array (
'#yii/imagine' => $vendorDir . '/yiisoft/yii2-imagine',
'#Imagine/Image' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Image',
'#Imagine/Gd' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Gd',
'#Imagine/Draw' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Draw',
'#Imagine/Effects' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Effects',
'#Imagine/Exception' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Exception',
'#Imagine/Filter' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Filter',
'#Imagine/Gmagick' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Gmagick',
'#Imagine/Imagick' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/Imagick',
'#Imagine/resources' => $vendorDir . '/yiisoft/yii2-imagine/Imagine/resources',
),
),
);

creating a zf2 module without controllers with some autoloaded classes

I'm trying to create a Zend Framework 2 module that has some generic classes that I want to use in some of my controllers.
I created a directory called 'tux-drink-zf2-module' in 'vendor' directory.
I added that directory to 'application.config.php'.
my Module.php has the following:
<?php
namespace TuxDrink;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements AutoloaderProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
update
new:
my autoload_classmap.php has the following:
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'TuxDrink\Module' => __DIR__ . '/Module.php',
'TuxDbCassandra' => __DIR__ . '/src/TuxDrink/TuxDb/Cassandra/TuxDbCassandra.php',
'TuxDrink\Drink\Model\AlcoholSum' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/AlcoholSum.php',
'TuxDrink\Drink\Model\AlcoholSumTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/AlcoholSumTable.php',
'TuxDrink\Drink\Model\Drink' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/Drink.php',
'TuxDrink\Drink\Model\DrinkBrand' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkBrand.php',
'TuxDrink\Drink\Model\DrinkBrandTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkBrandTable.php',
'TuxDrink\Drink\Model\DrinkCompany' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkCompany.php',
'TuxDrink\Drink\Model\DrinkCompanyTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkCompanyTable.php',
'TuxDrink\Drink\Model\DrinkFlavor' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavor.php',
'TuxDrink\Drink\Model\DrinkFlavorTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorTable.php',
'TuxDrink\Drink\Model\DrinkFlavorType' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorType.php',
'TuxDrink\Drink\Model\DrinkFlavorTypeTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkFlavorTypeTable.php',
'TuxDrink\Drink\Model\DrinkIngredient' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredient.php',
'TuxDrink\Drink\Model\DrinkIngredientTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientTable.php',
'TuxDrink\Drink\Model\DrinkIngredientType' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientType.php',
'TuxDrink\Drink\Model\DrinkIngredientTypeTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkIngredientTypeTable.php',
'TuxDrink\Drink\Model\DrinkTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkTable.php',
'TuxDrink\Drink\Model\DrinkType' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkType.php',
'TuxDrink\Drink\Model\DrinkTypeTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/DrinkTypeTable.php',
'TuxDrink\Drink\Model\GlobalImage' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImage.php',
'TuxDrink\Drink\Model\GlobalImageLink' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLink.php',
'TuxDrink\Drink\Model\GlobalImageLinkPending' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkPending.php',
'TuxDrink\Drink\Model\GlobalImageLinkPendingTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkPendingTable.php',
'TuxDrink\Drink\Model\GlobalImageLinkTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageLinkTable.php',
'TuxDrink\Drink\Model\GlobalImageTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageTable.php',
'TuxDrink\Drink\Model\GlobalImageType' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageType.php',
'TuxDrink\Drink\Model\GlobalImageTypeTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/GlobalImageTypeTable.php',
'TuxDrink\Drink\Model\LiquidColor' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColor.php',
'TuxDrink\Drink\Model\LiquidColorTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorTable.php',
'TuxDrink\Drink\Model\LiquidColorType' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorType.php',
'TuxDrink\Drink\Model\LiquidColorTypeTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/LiquidColorTypeTable.php',
'TuxDrink\Drink\Model\PendingDrinkCommits' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/PendingDrinkCommits.php',
'TuxDrink\Drink\Model\PendingDrinkCommitsTable' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Model/PendingDrinkCommitsTable.php',
'TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/TuxDbMysqlDrink.php',
'TuxDrink\TuxDb\Drink\Util\AlcoholCalc' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/Drink/Util/AlcoholCalc.php',
'TuxDrink\TuxDb\Mysql\TuxDbMysql' => __DIR__ . '/src/TuxDrink/TuxDb/Mysql/TuxDbMysql.php',
'TuxDrink\TuxDb\TuxDbAbstract' => __DIR__ . '/src/TuxDrink/TuxDb/TuxDbAbstract.php',
'TuxDrink\TuxDb\TuxDbInterface' => __DIR__ . '/src/TuxDrink/TuxDb/TuxDbInterface.php',
'TuxDrink\TuxDb\TuxDrinkInterface' => __DIR__ . '/src/TuxDrink/TuxDb/TuxDrinkInterface.php',
'TuxDrink\TuxDb\TuxTableInterface' => __DIR__ . '/src/TuxDrink/TuxDb/TuxTableInterface.php',
);
but still when I try to refresh my project I get the following error:
Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (tux-drink-zf2-module) could not be initialized.' in /Volumes/2g-storage/projects/php-projects/myalcoholist/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 144
maybe i'm missing some other files in order to properly configure this as a Module?
remember, this is a package for sources, without controllers, views and actions.
any information regarding the issue would be greatly appreciated.
update
this issue was solved when i fixed the directories structure.
but when I'm trying to use the module in one the the controllers.
in my case i need to use two classes from the TuxDrink module.
class 'TuxDbMysqlDrink' and class 'TuxDbMysql'.
I need to use them in controller 'DrinkController' in action 'drink-brand-autocomplete'.
I use the following code:
use \TuxDb\Mysql\Drink\TuxDbMysqlDrink;
use \TuxDb\Mysql\TuxDbMysql;
public function drinkBrandAutocompleteAction() {
$param=$this->getRequest()->getQuery('q');
if ($param) {
$drink = new TuxDbMysqlDrink();
$result=$drink->autoCompleteDrinkBrand($param);
return $result;
}
}
and I get the following error message:
Fatal error: DrinkManagement\Controller\DrinkController cannot use TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink - it is not a trait in /Volumes/2g-storage/projects/php-projects/myalcoholist/module/DrinkManagement/src/DrinkManagement/Controller/DrinkController.php on line 197
any ideas?
tried to google, couldn't understand what it means "it is not a trait"
update
resolved it with this code:
public function drinkBrandAutocompleteAction() {
$param=$this->getRequest()->getQuery('q');
if ($param) {
$drink = new \TuxDrink\TuxDb\Mysql\Drink\TuxDbMysqlDrink();
$result=$drink->autoCompleteDrinkBrand($param);
die(var_export($result,1));
...
Going by the error, the Module name is tux-drink-zf2-module. Taking sanitization into account, i'll assume your module is CamelCased like TuxDrinkZf2Module. Therefore the namespace you're assigning inside Module.php doesn't match, as it's only TuxDrink.
So my guess would be, either of your names is incorrect.

Symfony 2.1 Extending Core Classes

I am trying to override the core Symfony components with my own. The method I am using is:
"autoload": {
"psr-0": {
"": "src/",
"Symfony": "src/vendor/symfony/src/"
}
}
However when I run composer update and install it never seems to take this into account. Is this not the correct method to force the autoloader to look into another directory first before the Symfony core?
Any pointers appreciated!
EDIT: Paths to files
src/vendor/symfony/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
src/vendor/symfony/src/Symfony/Component/Translation/Translator.php
src/vendor/symfony/src/Symfony/Component/Translation/Loader/YamlFileLoader.php
<?php
// autoload_namespaces.php generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Twig_Extensions_' => $vendorDir . '/twig/extensions/lib/',
'Twig_' => $vendorDir . '/twig/twig/lib/',
'Symfony\\Bundle\\SwiftmailerBundle' => $vendorDir . '/symfony/swiftmailer-bundle/',
'Symfony\\Bundle\\MonologBundle' => $vendorDir . '/symfony/monolog-bundle/',
'Symfony\\Bundle\\AsseticBundle' => $vendorDir . '/symfony/assetic-bundle/',
'Symfony' => array($vendorDir . '/symfony/symfony/src/', '/src/vendor/symfony/src/'),
'SessionHandlerInterface' => $vendorDir . '/symfony/symfony/src/Symfony/Component/HttpFoundation/Resources/stubs',
'Sensio\\Bundle\\GeneratorBundle' => $vendorDir . '/sensio/generator-bundle/',
'Sensio\\Bundle\\FrameworkExtraBundle' => $vendorDir . '/sensio/framework-extra-bundle/',
'Sensio\\Bundle\\DistributionBundle' => $vendorDir . '/sensio/distribution-bundle/',
'Monolog' => $vendorDir . '/monolog/monolog/src/',
'Metadata\\' => $vendorDir . '/jms/metadata/src/',
'JMS\\SecurityExtraBundle' => $vendorDir . '/jms/security-extra-bundle/',
'JMS\\DiExtraBundle' => $vendorDir . '/jms/di-extra-bundle/',
'JMS\\AopBundle' => $vendorDir . '/jms/aop-bundle/',
'Doctrine\\ORM' => $vendorDir . '/doctrine/orm/lib/',
'Doctrine\\DBAL' => $vendorDir . '/doctrine/dbal/lib/',
'Doctrine\\Common' => $vendorDir . '/doctrine/common/lib/',
'Doctrine\\Bundle\\DoctrineBundle' => $vendorDir . '/doctrine/doctrine-bundle/',
'CG\\' => $vendorDir . '/jms/cg/src/',
'Assetic' => $vendorDir . '/kriswallsmith/assetic/src/',
'' => $baseDir . '/src/',
);
If I manually edit the autoload line to:
'Symfony' => array('/Users/macbook/Sites/Opia/Gaia/src/vendor/symfony/src/', $vendorDir . '/symfony/symfony/src/'),
Everything works as it is meant to. So now it is basically finding the solution to why composer does not compose properly.
EDIT 2:
Doing some more searching it appears the above method is not a good implementation:
https://groups.google.com/forum/#!msg/composer-dev/HprRV_wJZg4/M_zQ8O7lB6IJ
Instead I need to extend the given classes and tell Symfony to use those classes instead which should be possible through the parameters:
parameters:
security.authentication.listener.anonymous.class: Acme\DemoBundle
\Security\Http\Firewall\AcmeAnonymousAuthenticationListener
However I am not sure what parameters I need to set to load the extended classes in place of the core.
I finally found the answer to this.
Firstly if you need to find out which classes to override go to:
symfony/src/Symfony/Bundle/FrameworkBundle/Resources/%Your file to override%.xml
There you will find a list of possible Symfony classes that can be extended/overridden.
Then in your config.yml add (I chose to put mine in an extend namespace):
parameters:
twig.extension.trans.class: Extend\Symfony\Bridge\Twig\Extension\TranslationExtension
translation.loader.yml.class: Extend\Symfony\Component\Translation\Loader\YamlFileLoader
translator.class: Extend\Symfony\Bundle\FrameworkBundle\Translation\Translator
Finally in my composer.json:
"autoload": {
"psr-0": {
"": "src/",
"Extend\\Symfony": "/path/to/your/symfony/classes"
}
},

Categories