-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
psr-0 via composer broken. #51
Comments
Yes, I am getting same issue. Can you please fix |
@trq @yogeshkoli The problem exists with the last release 0.3.0 ? |
Yes, Problem is still there. I have installed package into Laravel 4.2 Trying to call Autoload.php file using below code: require_once 'path/to/PhpPowerpoint/src/PhpPowerpoint/Autoloader.php'; But it won't worked, can't create the object. I have also tried to call using namespace, but getting issues use phpoffice\phppowerpoint; |
@yogeshkoli If you replace in your composer.json :
with :
Does it work ? If not, remove the psr-0 key. |
@Progi1984 I have replaced psr-0, I am getting same issue. Class 'PhpOffice\PhpPowerpoint' not found Here is my code: <?php
use PhpOffice\PhpPowerpoint;
class HomeController extends BaseController {
public function showWelcome()
{
$objPHPPowerPoint = new PhpPowerpoint();
var_dump($objPHPPowerPoint);
}
} // and PSR-0
|
@yogeshkoli If you remove PSR-0 in composer.json and use PSR-4 ? |
@Progi1984 Yes tried that now, getting same issue. "psr-4": { |
@yogeshkoli We stay with : "psr-0": {
"PhpOffice\\PhpPowerpoint\\": "src/PhpPowerpoint/"
} Could you change your use PhpOffice\PhpPowerpoint\PhpPowerpoint; |
@Progi1984 - Yes, Great Thanks, it works now. 👍 Thank you for your help. |
I updated the composer.json in the develop branch. Could you test with it and your code ? If it's ok, I will close this issue. |
Sure - let me test, I will update you in while. Thanks! |
@Progi1984 I have tested and it is working fine for me.. 👍 |
@yogeshkoli Cool. So I close the issue. |
Sure, Thank you for your help. |
The psr-0 config does nothing (is still broken) and can safely be removed. https://github.com/PHPOffice/PHPPowerPoint/blob/master/composer.json#L38 |
May be it is useful for Laravel ? @yogeshkoli No ? Yes ? |
No. It is not useful at all, it is broken, is of no use. |
So if we remove the psr-0 config, it will work for Laravel too ? Sorry, I'm not an expert in Laravel. |
The psr-0 config you have is broken. It has nothing to do with Laravel. Do you not use composer? |
@trq If I try with this composer.json, I update composer, and I test my PHP file : i have no errors. composer.json {
"require": {
"phpoffice/phppowerpoint": "dev-develop"
}
} test.php <?php
//include 'vendor/autoload.php';
// OR
//require_once 'vendor/phpoffice/phppowerpoint/src/PhpPowerpoint/Autoloader.php';
\PhpOffice\PhpPowerpoint\Autoloader::register();
use \PhpOffice\PhpPowerpoint\IOFactory as IOFactory;
use \PhpOffice\PhpPowerpoint\PhpPowerpoint as PhpPowerpoint;
use \PhpOffice\PhpPowerpoint\Style\Alignment as Alignment;
use \PhpOffice\PhpPowerpoint\Style\Color as Color;
$objPHPPowerPoint = new PhpPowerpoint();
// Create slide
$currentSlide = $objPHPPowerPoint->getActiveSlide();
// Create a shape (text)
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
$textRun = $shape->createTextRun('Thank you for using PHPPowerPoint!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new Color( 'FFE06B20' ) );
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample.pptx");
$oWriterODP = IOFactory::createWriter($objPHPPowerPoint, 'ODPresentation');
$oWriterODP->save(__DIR__ . "/sample.odp"); |
Because it is using the psr-4 config, the psr-0 config is broken and can be removed. |
@trq I try to remove the psr-4 in composer.json of PHPPowerpoint and dump-autoload composer, and it works again |
You either need to use psr-0 or psr-4, not both. |
Ok. I remove the PSR-0. |
Okay for you @trq & @yogeshkoli ? |
@Progi1984 @trq It is working for me with PSR-0, In laravel 4.2. |
I think you will find it is the psr-4 that is actually working. |
@yogeshkoli Could you update your code (and take the develop branch) ? Normally, with the help of @trq, it is ok with PSR-4. |
@Progi1984 Sure, let me test with develop branch. |
@yogeshkoli OK, I wait for your tests. |
@Progi1984 I have tried with both one by one (psr-4 and psr-0), working fine with me. no issues. 👍 composer.json file: "psr-4": {
"PhpOffice\\PhpPowerpoint\\": "src/PhpPowerpoint/"
} Controller: <?php
use PhpOffice\PhpPowerpoint\PhpPowerpoint;
class HomeController extends BaseController {
public function create()
{
$ppt = new PhpPowerpoint();
var_dump($ppt);
}
} Output:
|
Perfect, I close the issue. Thank you, guys : @trq @yogeshkoli ! |
I realise this bug is closed, but in case any other Laravel people stumble over here wondering why their PHPPowerPoint class can no longer be found, here's what you'll need to do. Add the following use statements to the top of your code:
I may not have covered all the classes, but you get the drift. You will then need to change from using classes named with the namespace and underscores to the simpler aliased class name, eg. PHPPowerPoint_IOFactory becomes IOFactory, etc. Even though the PSR-0 directive is broken, it doesn't matter because the class loader will use the PSR-4 approach anyway, so you don't actually have to switch to dev-develop branch to pick up the change to composer.json, you can stay on dev-master. |
@jamesggordon There are no classes in the package that use the old PEAR style eg; PHPPowerPoint_IOFactory. |
How about that! I started using PHPPowerPoint several years ago when it was hosted on Codeplex and it was using the old style. I just kept using that style even when I switched to this version via composer and it kept working, which is very cool! I guess that was due to psr-0 figuring out the class locations from the fully-qualified, underscore-delimited class names. |
@jamesggordon Since the version 0.2, PHPPowerPoint use namespaces. The version changes has break the use of the version 0.1. Else you can add a PR in docs for adding this question in FAQ. |
You are telling composer that the namespace "PHPPowerPoint" exists within src/, it doesn't.
All your code is within PhpOffice\PhpPowerpoint.
Please fix.
The text was updated successfully, but these errors were encountered: