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

Getting Started Issue #29

Closed
designcise opened this issue Apr 9, 2017 · 26 comments
Closed

Getting Started Issue #29

designcise opened this issue Apr 9, 2017 · 26 comments
Assignees

Comments

@designcise
Copy link

I'm following the docs:

<?php

require __DIR__.'/../vendor/autoload.php';

$app = new Hawkbit\Application();

$app->get('/', function ($request, $response) {
    $response->getBody()->write('<h1>It works!</h1>');
    return $response;
});

$app->run();

?>

But that code returns:

Fatal error: Class 'Hawkbit\Application\Application' not found in D:\Work\web\index.php on line 5

Removing "\Application" works (so it must mean there's a typo in the docs), but this presents the following issue:

League\Route\Http\Exception\NotFoundException: Not Found in file D:\Work\framework\vendor\league\route\src\Dispatcher.php on line 76 Stack trace: 1. League\Route\Http\Exception\NotFoundException->() D:\Work\framework\vendor\league\route\src\Dispatcher.php:76 2. League\Route\Dispatcher->handleNotFound() D:\Work\framework\vendor\league\route\src\Dispatcher.php:35 3. League\Route\Dispatcher->handle() D:\Work\framework\vendor\league\route\src\RouteCollection.php:118 4. League\Route\RouteCollection->dispatch() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:920 5. Hawkbit\Application->handleResponse() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:875 6. Hawkbit\Application->Hawkbit\{closure}() [internal]:0 7. Closure->__invoke() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 8. call_user_func_array() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 9. Hawkbit\Application\MiddlewareRunner->Hawkbit\Application\{closure}() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:868 10. Hawkbit\Application->Hawkbit\{closure}() [internal]:0 11. Closure->__invoke() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 12. call_user_func_array() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 13. Hawkbit\Application\MiddlewareRunner->Hawkbit\Application\{closure}() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:101 14. Hawkbit\Application\MiddlewareRunner->run() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:884 15. Hawkbit\Application->handle() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:985 16. Hawkbit\Application->run() D:\Work\framework\web\index.php:12

Any help would be greatly appreciated! Here's my composer.json:

{
    "require": {
		"hawkbit/hawkbit": "~2.0",
		"hawkbit/Presentation": "~1.0"
	}
}
@mbunge
Copy link
Contributor

mbunge commented Apr 19, 2017

Hey there,

I'll proof and provide a solution :) I'l create a working example and fix typo. You may be would need to add an .htaccess-file:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
RewriteBase /

# Disallow set PHPSESSID
RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Best regards,
Marco

@designcise
Copy link
Author

designcise commented Apr 19, 2017

Hi Marco,

Really appreciate the response. I already had a simple .htaccess w/url rewrite:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

It still doesn't work. Even tried replacing it with yours, I still get:

League\Route\Http\Exception\NotFoundException: Not Found in file D:\Work\framework\vendor\league\route\src\Dispatcher.php on line 76 Stack trace: 1. League\Route\Http\Exception\NotFoundException->() D:\Work\framework\vendor\league\route\src\Dispatcher.php:76 2. League\Route\Dispatcher->handleNotFound() D:\Work\framework\vendor\league\route\src\Dispatcher.php:35 3. League\Route\Dispatcher->handle() D:\Work\framework\vendor\league\route\src\RouteCollection.php:118 4. League\Route\RouteCollection->dispatch() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:920 5. Hawkbit\Application->handleResponse() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:875 6. Hawkbit\Application->Hawkbit\{closure}() [internal]:0 7. Closure->__invoke() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 8. call_user_func_array() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 9. Hawkbit\Application\MiddlewareRunner->Hawkbit\Application\{closure}() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:868 10. Hawkbit\Application->Hawkbit\{closure}() [internal]:0 11. Closure->__invoke() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 12. call_user_func_array() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:97 13. Hawkbit\Application\MiddlewareRunner->Hawkbit\Application\{closure}() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application\MiddlewareRunner.php:101 14. Hawkbit\Application\MiddlewareRunner->run() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:884 15. Hawkbit\Application->handle() D:\Work\framework\vendor\hawkbit\hawkbit\src\Application.php:985 16. Hawkbit\Application->run() D:\Work\framework\web\index.php:25

I'm thinking if it's an issue with namespacing, maybe a \ is needed at the start of the namespace e.g. \League\Route\Http\Exception\NotFoundException

I hope this can be resolved as I really wish to play around with your framework, it looks very good and modular!

Good to see this project is still alive by the way! Good work!

Edit: Sorry, accidentally closed the topic.

@mbunge
Copy link
Contributor

mbunge commented Apr 19, 2017

Hey,

I've released a new version 2.3.0 including an example (please see public/)

I hope this is helping you!

If not, feel free to reopen this repository 😉

Best regards,

Marco Bunge

@designcise
Copy link
Author

designcise commented Apr 19, 2017

Ran the update with composer, and tried the sample code in public/; I still get the same error. I'm using PHP Version 5.6.28 if that helps.

@mbunge
Copy link
Contributor

mbunge commented Apr 20, 2017

Wamp or XAMPP? Or a custom PHP + Apache solution?
What is you URL? Could you please check your rewritebase?

I'll check as soon as possible!

@mbunge mbunge reopened this Apr 20, 2017
@designcise
Copy link
Author

designcise commented Apr 20, 2017

XAMP; phpinfo() details:

PHP Version 5.6.28
System: Windows NT IM-A-PC 6.2 build 9200 (Windows 8 Home Premium Edition) i586
Build Date: Nov 9 2016 06:33:44
Compiler: MSVC11 (Visual C++ 2012)
Architecture: x86

I've tried with .htaccess residing in my root folder with the following code:

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} PHPSESSID=.*$
RewriteRule .* %{REQUEST_URI}? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ web/index.php [QSA,L]

And also tried with a .htaccess in the web/ folder with the last line as: RewriteRule ^ index.php [QSA,L]

And my directory structure is:

+
+-- vendor
+-- web
+-- +-- index.php
+-- .htaccess

index.php code:

<?php
use \Psr\Http\Message\ResponseInterface;
use \Psr\Http\Message\ServerRequestInterface;
require __DIR__.'/../vendor/autoload.php';
$app = new Hawkbit\Application();
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
    $response->getBody()->write('<h1>Hello, World!</h1>');
    return $response;
});
$app->run();

Let me know if you need additional details. Thanks!

@designcise
Copy link
Author

Hi Marco, any luck so far?

@BlackScorp
Copy link
Contributor

BlackScorp commented Apr 25, 2017

@designcise

i just tested this. The Problem is your URL, if you use xampp, the htdocs folder contains your projects. lets say you created a project "hawkbitApplication" so you open URL

http://localhost/hawkbitApplication/ now you .htacess kicks in and redirect everything to index.php inside the folder. The Path of the Request Class is now "/hawkbitApplication/"

so you need to write $app->get('/hawkbitApplication/',fuction..) as your first URL.

To make it work like in the example of public directory, you need to create virtual hosts on xampp which points to xampp/htdocs/hawkbitApplication/web also after creating the virtual host you need to modify your windows hosts file and add a domain on your pc. Please google "Xampp Virtual hosts"

The easiest solution would be, don't use Apache from Xampp. Create a "server-start.bat" file in your Project with following code

https://pastebin.com/cntf1stz

then just double click the bat file and open localhost and you will see "Hello World" if you need apache from Xampp, then change the Port in the bat file to 8080 for example and to run this application you need to open localhost:8080 if you want to use xampp apache you use then just localhost

any question?

@mbunge league/route/src/Dispatcher.php line 34 $request->getUri()->getPath() contains the project folder instead of / and since there is no route for project folder, he get not found exception.

Maybe you can reacto to the NotFoundException with better error Reporting? Not just using their "Not found" Message but instead "Route to /url with method GET" not found or something like this

@designcise
Copy link
Author

@BlackScorp I wasn't able to completely follow your instructions, thus unable to replicate the process that made it work for you. In any case, the whole point of having a framework is that it should be easy to get started with, and if it's not, it defeats the purpose. Maybe it's something that needs to be worked on?

@BlackScorp
Copy link
Contributor

BlackScorp commented Apr 26, 2017

@designcise

ok this will be a long answer :D because there is no short version.

A Framework means that you have a "frame" where you work within, means that this package deliver classes for you and you have to use them their way. The classes are router, event dispatcher, dependency injection etc, you will need them for 99% of applications. The purpose of the Framework is not getting started quick, but having basic classes which you can use instead of writing them every time again and again for every project.

Now regarding the public folder. If you fail here, you will fail with any framework, on laravel you have to start the php server as well, see https://laravel.com/docs/5.4 "Local Development Server" on Symfony you have the same http://symfony.com/doc/current/setup.html#running-the-symfony-application
This framework is an microframework and the server start script is not delivered with. But this is just a normal way, its just hard to accomplish with XAMPP. But i will guide you later to this.

Now you thinking, why do all the frameworks do this? The Web is working like this: You create Request to a Server IP the application on the Server is waiting for a Request on Port 80 if it gets the Request, it try to response, for example if you request a CSS the Server will just return the CSS file, how ever for PHP Files it asks the Interpreter to handle the file and return the interpreters output. There were several cases in the past where this interpreter communication failed, due to bad server setup or ther things. If the websever does not know that it has to ask the interpreter, it will just display the php files as plain text. And you dont want to show your code via browser to others;) Also frameworks like Symfony or Laravel has their configurations stored in .yaml files, which are text files. So anyone who know the path to the file, could potentially read the database username and password. by having a "web" folder or "public" if this happens, only the index.php is shown but it contians usually an include the a bootstrap file one level higher.

Now to your Problem

you told that is your directory structure

+-- vendor
+-- web
+-- +-- index.php
+-- .htaccess

lets stick with it, put the .htaccess file into web folder and create in your project folder a "server-start.bat" so now you directory looks like this

+-- vendor
+-- web
+-- +-- index.php
+-- +-- .htaccess
+-- server-start.bat

now edit the file with any text editor, this is the code https://pastebin.com/cntf1stz this code assumes that your xampp is installed in C:\xampp if not, then change the path.

Now make sure that in your XAMPP Controll panel, the apache server is disabled. Then just double click on the server-start.bat and open http://localhost

Its easy ;)

@designcise
Copy link
Author

designcise commented Apr 26, 2017

@BlackScorp Thank you for the reply, I really appreciate it. While I'm no stranger to frameworks, and definitely not a newbie, what I meant was, it needs to work right out of the box. I have tried Lumen and Slim (which are also microframeworks, and lumen is the scaled down version of Laravel) and they work out of the box. They just weren't what I was looking for. Hawkbit seemed like a much better built and structured framework, which is why I'm eager to try it, but I'm having a hard time setting it up. And what I meant was, ease-of-use / ease-of-setup needs to be a big factor in any sort of framework because one has to build on top of it, just because it isn't a norm, doesn't mean it can't be worked into Hawkbit. I mean if most of my time is spent trying to figure out hacks to make it work, then it defeats the whole purpose. Now, I gather it may be an XAMPP-specific issue, but again, if we could understand why it was happening, maybe we could update the code in Hawkbit, such that it works right out of the box. And I did try your suggestion with the bat file, it still doesn't work.

@BlackScorp
Copy link
Contributor

BlackScorp commented Apr 26, 2017

@designcise how could Lumen work right out of the box?

https://lumen.laravel.com/docs/5.4

see "Serving Your Application" its the same thing. Every framework work this way, so if youre no stranger to frameworks, you should be able to run this.

What my suggested batch file is doing, just calling within cmd.exe

C:\xampp\php\php.exe -S 0.0.0.0:80 -t <path where .bat file is located>web

and if this is not working, then none framework will work. Or you used something different for Lumen/Slim than xampp

Here https://www.slimframework.com/docs/tutorial/first-app.html "Run Your Application With PHP’s Webserver"

shame on all the PHP Frameworks which cannot name their headers for linking

@designcise
Copy link
Author

@BlackScorp gosh I meant obviously, worked as in worked out-of-box following the instructions, and in the environment I have. And no, I did not use anything different for Slim or Lumen, it works with composer + xampp easily by following the docs, whereas the same is not true for Hawkbit.

@BlackScorp
Copy link
Contributor

@designcise but all the instruction says, use composer create project, then call

php -S localhost:somePort -t public

please show me the instruction which worked for you out of the box and i will translate it to hawkbit

@designcise
Copy link
Author

designcise commented Apr 26, 2017

I never called "php -S localhost:somePort -t public" on lumen; I use composer, for example composer create-project --prefer-dist laravel/lumen blog (from the docs) and run xampp, point my browser to localhost/blog/public/ and it works! Whereas Hawkbit doesn't.

@BlackScorp
Copy link
Contributor

@designcise

just tested out, youre right, Hawkbit is using Zend Request class while lumen use Symfony Request class. it seems.

Inside the phpleague router in the Dispatcher the Request Path is used like this

$request->getUri()->getPath()

in Lumen this path is modified while in Zend Request it is not. In Lumen this works because of the bootstrap/app.php the new instance of the application is recieving the base path where the project is located, and base on this, they remove some parts from the request URL so the router is working

@mbunge all you need is that $app->getRequest()->getUri()->getPath() will return / if you call http://localhost/myProject/web/

@BlackScorp
Copy link
Contributor

@designcise i created a pull request, after the merge, it will work "out of the box" cheers

@designcise
Copy link
Author

@BlackScorp yep, that seems to work! You may want to remove double semi-colons at the end of line 188. Thanks a bunch for helping on this.

@BlackScorp
Copy link
Contributor

@designcise strange, i did it here https://github.com/BlackScorp/hawkbit/commit/47bbefe9c5d30ac4faed7e3e7cf79de0ae05d90f but the PR dont have it

@designcise
Copy link
Author

designcise commented Apr 26, 2017

@BlackScorp I just applied the change in Application.php as it appears here: https://github.com/BlackScorp/hawkbit/commit/a711c23ff1034648be4600dec076bcdca64aba51 and it seems to have resolved the issue.

Edit: Sorry, totally slipped my mind you were talking about the double semi-colon issue I pointed out. Sorry, it's almost 6 am here, need to get some sleep!

@BlackScorp
Copy link
Contributor

@designcise everything is good:D lets see if @mbunge accepts my PR

cheers

@designcise
Copy link
Author

@mbunge can you please test/accept the PR by @BlackScorp as it resolves the issue, thanks!

mbunge pushed a commit that referenced this issue Apr 27, 2017
* Fix for #29 enable to project to run even without document root set for public

* added tests

* fixed tests
@mbunge
Copy link
Contributor

mbunge commented Apr 27, 2017

Hello @BlackScorp and @designcise,

I had a huge workload. Thank you for PR, I already approved and merged it!

Have a look new special thanks section in readme ;)

I published a new Version 2.3.1

@mbunge mbunge closed this as completed Apr 27, 2017
@BlackScorp
Copy link
Contributor

i just changed like 3 lines of code :P

@designcise
Copy link
Author

designcise commented Apr 27, 2017

@mbunge Since there isn't a platform where we can discuss this, I'm going to ask this here, I hope you find the time to reply:

So, the Hawkbit framework is very good, but I want to know:

  1. Is the Hawkbit framework being actively developed? Are there any specific future goals, vision, etc. laid out?
  2. What made you develop Hawkbit? Why you felt there was a need for it?
  3. Was Hawkbit intended to compete, innovate, lead, or merely co-exist?
  4. How many developers are working on it? What kind of funding is required and how much time they are able to apply to the project?

Sorry, I'm just asking to assess what the future holds for the framework before implementing it into my projects. I would love to contribute to it in the future, but it's important to know how things are presently.

Thank you for your time! I really appreciate it!

@mbunge
Copy link
Contributor

mbunge commented Apr 28, 2017

@designcise I've open a new issue #33 for your questions :)

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

No branches or pull requests

3 participants