Skip to content

Manual install instructions from the current documentation are obsolete #2543

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

Closed
MisterVector opened this issue Jan 7, 2024 · 2 comments · Fixed by #2722
Closed

Manual install instructions from the current documentation are obsolete #2543

MisterVector opened this issue Jan 7, 2024 · 2 comments · Fixed by #2722
Assignees
Milestone

Comments

@MisterVector
Copy link

The manual install instructions, found here, do not apply anymore since this change removed the ability to do a manual install.

@Progi1984 Progi1984 added this to the 1.3.0 milestone Aug 16, 2024
@Progi1984 Progi1984 modified the milestones: 1.3.0, 1.3.1 Aug 31, 2024
@zitot-hawaii-edu
Copy link

zitot-hawaii-edu commented Dec 20, 2024

Made an attempt helped by documentation, reddit, stackoverflow and chatgpt. Structure of directories is assumed to place our source code in /lib/PhpOffice/PhpWord, samples at /samples, Autoloader.php at /lib/PhpOffice/PhpWord/, modified bootstrap.php. Note that I only got Sample_01 through Sample_03 working and may have made other changes that I forgot about. PDF shows as failed but the docx/html seem to work.

Did not test anything besides Sample_01 to Sample_04, haven't tried actually writing code or running real tests, sorry. Hopefully this serves as a base, idk

./
├── ./lib
│   └── ./lib/PhpOffice
│       ├── ./lib/PhpOffice/Common
│       ├── ./lib/PhpOffice/PhpWord
│       └── ./lib/PhpOffice/PHPWord
└── ./samples
    ├── ./samples/bootstrap
    │   ├── ./samples/bootstrap/css
    │   ├── ./samples/bootstrap/fonts
    │   └── ./samples/bootstrap/js
    ├── ./samples/resources
    └── ./samples/results
...

https://pastebin.com/SKMWn9VN <-- added ./lib/PhpOffice/PhpWord/Autoloader.php

<?php

namespace PhpOffice\PhpWord;

/**
 * Custom Autoloader for PHPWord
 */
class Autoloader
{
    const BASE_DIR = __DIR__;

    /**
     * Register the autoloader
     */
    public static function register()
    {
        spl_autoload_register([new self, 'autoload']);
    }

    /**
     * Autoload function
     */
    public static function autoload($class)
    {
        $prefix = "PhpOffice\\PhpWord\\";
        $baseDir = self::BASE_DIR . DIRECTORY_SEPARATOR;

        if (strpos($class, $prefix) !== 0) {
            return false;
        }

        $relativeClass = substr($class, strlen($prefix));
        $file = $baseDir . str_replace("\\", DIRECTORY_SEPARATOR, $relativeClass) . ".php";

        if (file_exists($file)) {
            require_once $file;
        } else {
            die("Class $class not found in $file");
        }
    }
}

https://pastebin.com/Yn23zEXi <-- modified ./bootstrap.php

<?php
$phpWordPath = realpath(__DIR__ . '/lib/PhpOffice/PhpWord');

if (file_exists($phpWordPath . '/Autoloader.php')) {
    require_once $phpWordPath . '/Autoloader.php';

    \PhpOffice\PhpWord\Autoloader::register();
} else {
    throw new Exception(
        sprintf(
            "Could not find the PHPWord autoloader at '%s'. Please check your file paths.",
            $phpWordPath . '/Autoloader.php'
        )
    );
}
?>

@Progi1984
Copy link
Member

This issue has been fixed by a maintainer. You can help him by sponsoring him through Github sponsors.

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

Successfully merging a pull request may close this issue.

3 participants