-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added alternative to composer autoloader (#388)
* added alternative to composer autoloader * README.md: added small installation section for composer and alt-loader * alt_autoload.php-dist: refined how to use section * Update README.md: removed obsolete the Co-authored-by: Jérémy Benoist <[email protected]> * fixed coding style issues * Fixed class not found in alt-autoload test (ElementString) this is weird, because it works on my local machine which also runs PHP 7.4 * CI workflow: moved alt-autoload test to its own test-block Running it together with Composer made no sense. * corrected authorship of new added files Co-authored-by: Jérémy Benoist <[email protected]>
- Loading branch information
Showing
10 changed files
with
182 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* @file This file is part of the PdfParser library. | ||
* | ||
* @author Konrad Abicht <[email protected]> | ||
* @date 2021-02-09 | ||
* | ||
* @license LGPLv3 | ||
* @url <https://github.com/smalot/pdfparser> | ||
* | ||
* PdfParser is a pdf library written in PHP, extraction oriented. | ||
* Copyright (C) 2017 - Sébastien MALOT <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. | ||
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. | ||
* | ||
* -------------------------------------------------------------------------------------- | ||
* | ||
* About: | ||
* This file provides an alternative to the Composer-approach. | ||
* Include it into your project and all required files of PDFParser will be loaded automatically. | ||
* Please use it only, if Composer is not available. | ||
* | ||
* How to use: | ||
* 1. include this file as it is OR copy and rename it as you like (and then include it) | ||
* 2. afterwards you can use PDFParser classes | ||
* Done. | ||
*/ | ||
|
||
/** | ||
* Loads all files found in a given folder. | ||
* Calls itself recursively for all sub folders. | ||
* | ||
* @param string $dir | ||
*/ | ||
function requireFilesOfFolder($dir) | ||
{ | ||
foreach (new DirectoryIterator($dir) as $fileInfo) { | ||
if (!$fileInfo->isDot()) { | ||
if ($fileInfo->isDir()) { | ||
requireFilesOfFolder($fileInfo->getPathname()); | ||
} else { | ||
require_once $fileInfo->getPathname(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
$rootFolder = __DIR__.'/src/Smalot/PdfParser'; | ||
|
||
// Manually require files, which can't be loaded automatically that easily. | ||
require_once $rootFolder.'/Element.php'; | ||
require_once $rootFolder.'/PDFObject.php'; | ||
require_once $rootFolder.'/Font.php'; | ||
require_once $rootFolder.'/Page.php'; | ||
require_once $rootFolder.'/Element/ElementString.php'; | ||
|
||
/* | ||
* Load the rest of PDFParser files from /src/Smalot/PDFParser | ||
* Dont worry, it wont load files multiple times. | ||
*/ | ||
requireFilesOfFolder($rootFolder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* @file This file is part of the PdfParser library. | ||
* | ||
* @author Konrad Abicht <[email protected]> | ||
* @date 2021-02-09 | ||
* | ||
* @license LGPLv3 | ||
* @url <https://github.com/smalot/pdfparser> | ||
* | ||
* PdfParser is a pdf library written in PHP, extraction oriented. | ||
* Copyright (C) 2017 - Sébastien MALOT <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. | ||
* If not, see <http://www.pdfparser.org/sites/default/LICENSE.txt>. | ||
*/ | ||
require __DIR__.'/../alt_autoload.php-dist'; | ||
|
||
$parser = new Smalot\PdfParser\Parser(); | ||
|
||
$filename = __DIR__.'/../samples/InternationalChars.pdf'; | ||
$document = $parser->parseFile($filename); | ||
|
||
$needle = 'Лорем ипсум долор сит амет, еу сед либрис долорем инцоррупте.'; | ||
if (0 !== strpos($document->getText(), $needle)) { | ||
return 0; | ||
} | ||
|
||
throw new Exception('Something went wrong. Alt-Autoload is not working.'); |