scrivo / highlight.php

A port of highlight.js by Ivan Sagalaev to PHP
BSD 3-Clause "New" or "Revised" License
695 stars 45 forks source link

Autoloader.php #45

Closed Docsconsole closed 5 years ago

Docsconsole commented 5 years ago

hi Scrivo,

I have installed the highlight project in my Laravel project by using Composer. Added below given snippet into the controller.

require_once "../Highlight/Autoloader.php";
spl_autoload_register("Highlight\\Autoloader::load");

When i am running the code then it is displaying with below error message.

App\Http\Controllers\AController::show(): Failed opening required '../Highlight/Autoloader.php' (include_path='.;C:\php\pear')

Can you please help me here.

allejo commented 5 years ago

If you're installing this library through Composer (i.e. composer require), then Composer will handle the autoloading for you and there's no need to manually require the Autoloader provided by this library. You just need to use the autoloader provided by Composer, and if you're using Laravel, that should already be taken care of for you.

Docsconsole commented 5 years ago

If you're installing this library through Composer (i.e. composer require), then Composer will handle the autoloading for you and there's no need to manually require the Autoloader provided by this library. You just need to use the autoloader provided by Composer, and if you're using Laravel, that should already be taken care of for you.

hi, i have added below given code snippet in the controller.

$hl = new Highlight\Highlighter();

But it is giving below given error. can you please let me know where is the mistake.

Class 'App\Http\Controllers\Highlight\Highlighter' not found

allejo commented 5 years ago

Guess I should correct the README slightly. Take a look at what namespaces are in PHP.

The example in the README should be:

$hl = new \Highlight\Highlighter();

That error is basically saying that there’s no Highlighter class in your Laravel path because it actually exists in the Highlight path.