Skip to content
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

Closed
trq opened this issue Sep 2, 2014 · 36 comments
Closed

psr-0 via composer broken. #51

trq opened this issue Sep 2, 2014 · 36 comments
Assignees
Milestone

Comments

@trq
Copy link

trq commented Sep 2, 2014

You are telling composer that the namespace "PHPPowerPoint" exists within src/, it doesn't.

All your code is within PhpOffice\PhpPowerpoint.

Please fix.

@yogeshkoli
Copy link

Yes, I am getting same issue.

Can you please fix

@Progi1984
Copy link
Member

@trq @yogeshkoli The problem exists with the last release 0.3.0 ?

@yogeshkoli
Copy link

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';
\PhpOffice\PhpPowerpoint\Autoloader::register();

But it won't worked, can't create the object.

I have also tried to call using namespace, but getting issues

use phpoffice\phppowerpoint;

@Progi1984
Copy link
Member

@yogeshkoli If you replace in your composer.json :

"psr-0": {
            "PHPPowerPoint": "src/"
        },

with :

"psr-0": {
            "PhpOffice\\PhpPowerpoint\\": "src/PhpPowerpoint/"
        },

Does it work ?

If not, remove the psr-0 key.

@yogeshkoli
Copy link

@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

    "psr-0": {
            "PhpOffice\\PhpPowerpoint\\": "src/PhpPowerpoint/"
        }

@Progi1984
Copy link
Member

@yogeshkoli If you remove PSR-0 in composer.json and use PSR-4 ?

@yogeshkoli
Copy link

@Progi1984 Yes tried that now, getting same issue.

"psr-4": {
"PhpOffice\PhpPowerpoint": "src/PhpPowerpoint/"
}

@Progi1984
Copy link
Member

@yogeshkoli We stay with :

 "psr-0": {
    "PhpOffice\\PhpPowerpoint\\": "src/PhpPowerpoint/"
}

Could you change your use ?

use PhpOffice\PhpPowerpoint\PhpPowerpoint;

@yogeshkoli
Copy link

@Progi1984 - Yes, Great Thanks, it works now. 👍

Thank you for your help.

Progi1984 added a commit that referenced this issue Oct 6, 2014
@Progi1984
Copy link
Member

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.

@yogeshkoli
Copy link

Sure - let me test, I will update you in while.

Thanks!

@yogeshkoli
Copy link

@Progi1984 I have tested and it is working fine for me.. 👍

@Progi1984
Copy link
Member

@yogeshkoli Cool. So I close the issue.

@yogeshkoli
Copy link

Sure, Thank you for your help.

@trq
Copy link
Author

trq commented Oct 6, 2014

The psr-0 config does nothing (is still broken) and can safely be removed. https://github.com/PHPOffice/PHPPowerPoint/blob/master/composer.json#L38

@Progi1984
Copy link
Member

May be it is useful for Laravel ?

@yogeshkoli No ? Yes ?

@trq
Copy link
Author

trq commented Oct 6, 2014

No. It is not useful at all, it is broken, is of no use.

@Progi1984
Copy link
Member

So if we remove the psr-0 config, it will work for Laravel too ?

Sorry, I'm not an expert in Laravel.

@trq
Copy link
Author

trq commented Oct 6, 2014

The psr-0 config you have is broken. It has nothing to do with Laravel. Do you not use composer?

@Progi1984 Progi1984 reopened this Oct 7, 2014
@Progi1984
Copy link
Member

@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");

@trq
Copy link
Author

trq commented Oct 7, 2014

Because it is using the psr-4 config, the psr-0 config is broken and can be removed.

@Progi1984
Copy link
Member

@trq I try to remove the psr-4 in composer.json of PHPPowerpoint and dump-autoload composer, and it works again

@trq
Copy link
Author

trq commented Oct 7, 2014

You either need to use psr-0 or psr-4, not both.

@Progi1984
Copy link
Member

Ok. I remove the PSR-0.

Progi1984 added a commit that referenced this issue Oct 7, 2014
@Progi1984
Copy link
Member

Okay for you @trq & @yogeshkoli ?

@yogeshkoli
Copy link

@Progi1984 @trq It is working for me with PSR-0, In laravel 4.2.

@trq
Copy link
Author

trq commented Oct 8, 2014

I think you will find it is the psr-4 that is actually working.

@Progi1984
Copy link
Member

@yogeshkoli Could you update your code (and take the develop branch) ? Normally, with the help of @trq, it is ok with PSR-4.

@yogeshkoli
Copy link

@Progi1984 Sure, let me test with develop branch.

@Progi1984
Copy link
Member

@yogeshkoli OK, I wait for your tests.

@yogeshkoli
Copy link

@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:

object(PhpOffice\PhpPowerpoint\PhpPowerpoint)[124]
  private 'properties' => 
    object(PhpOffice\PhpPowerpoint\DocumentProperties)[131]
      private 'creator' => string 'Unknown Creator' (length=15)
      private 'lastModifiedBy' => string 'Unknown Creator' (length=15)
      private 'created' => int 1412762932
      private 'modified' => int 1412762932
      private 'title' => string 'Untitled Presentation' (length=21)
      private 'description' => string '' (length=0)
      private 'subject' => string '' (length=0)
      private 'keywords' => string '' (length=0)
      private 'category' => string '' (length=0)
      private 'company' => string 'Microsoft Corporation' (length=21)
  private 'layout' => 
    object(PhpOffice\PhpPowerpoint\DocumentLayout)[132]
      private 'dimension' => 
        array (size=11)
          'screen4x3' => 
            array (size=2)
              ...
          'screen16x10' => 
            array (size=2)
              ...
          'screen16x9' => 
            array (size=2)
              ...
          '35mm' => 
            array (size=2)
              ...
          'A3' => 
            array (size=2)
              ...
          'A4' => 
            array (size=2)
              ...
          'B4ISO' => 
            array (size=2)
              ...
          'B5ISO' => 
            array (size=2)
              ...
          'banner' => 
            array (size=2)
              ...
          'letter' => 
            array (size=2)
              ...
          'overhead' => 
            array (size=2)
              ...
      private 'layout' => string 'screen4x3' (length=9)
      private 'dimensionX' => int 9144000
      private 'dimensionY' => int 6858000
  private 'slideCollection' => 
    array (size=1)
      0 => 
        object(PhpOffice\PhpPowerpoint\Slide)[129]
          private 'parent' => 
            &object(PhpOffice\PhpPowerpoint\PhpPowerpoint)[124]
          private 'shapeCollection' => 
            object(ArrayObject)[130]
              ...
          private 'identifier' => string '6314400d5903ef12b5e24eb78218b798' (length=32)
          private 'slideLayout' => string 'Blank' (length=5)
          private 'slideMasterId' => int 1
          private 'hashIndex' => null
  private 'activeSlideIndex' => int 0

@Progi1984
Copy link
Member

Perfect, I close the issue. Thank you, guys : @trq @yogeshkoli !

@jamesggordon
Copy link
Contributor

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:

use PhpOffice\PhpPowerpoint\IOFactory as IOFactory;
use PhpOffice\PhpPowerpoint\PhpPowerpoint as PhpPowerpoint;
use PhpOffice\PhpPowerpoint\Shape\MemoryDrawing as MemoryDrawing;
use PhpOffice\PhpPowerpoint\Style\Alignment as Alignment;
use PhpOffice\PhpPowerpoint\Style\Color as Color;

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.

@trq
Copy link
Author

trq commented Oct 9, 2014

@jamesggordon There are no classes in the package that use the old PEAR style eg; PHPPowerPoint_IOFactory.

@jamesggordon
Copy link
Contributor

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.

@Progi1984
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants