Download the PHP package thnguyendev/phpwebcore without Composer

On this page you can find all versions of the php package thnguyendev/phpwebcore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpwebcore

PHPWebCore 1.0.0

PHPWebCore is a MVC framework in PHP. It is built on the habits of using ASP.NET Core. It aims to be simple and easy to use. PHPWebCore implements PSR-7 HTTP message interfaces and PSR-17 HTTP Factories. It also supports dependency injection.

PHPWebCore is a very basic framework. But, you can always include any PHP packages that need for your app, for instance, RedBeanPHP, Doctrine ORM, Firebase PHP-JWT, php-amqplib, etc...

Quick start

  1. PHPWebCore needs Composer and of course PHP. Make sure you download and install PHP and Composer.
  2. Create PHPWebCore project by Composer. Then, run the update command from Composer to download all of denpendencies.

  3. The web root folder is "public" in project folder. There are several ways to run the app: use the PHP built-in server, Apache server or Nginx server, etc.. For PHP built-in server, you just need to set the document root is "public" folder. In Apache server, .htaccess file is ready in "public" folder, you need to set "public" folder is Apache web root directory. If you use Nginx server, you need to add a server in nginx.conf which has root points to "public" folder in app and setup location like below.

    • PHP built-in server

    • Apache server .htaccess config

    • Nginx server nginx.conf config
  4. Now back to the app, your workspace in the app is just inside the "src/app" folder. Working with the routes of web app is our first step. PHPWebCore does not use the PHP attributes for the routing. The default routing is the Route class extends from PHPWebCore\AppRoute in Route.php. You need to implement initialize() method for Route class. Routes should be defined here. The request Url paths split into paths and parameters. PHPWebCore will map it to the first route that has the most segments in path. In this example, we create 2 routes: one is the root path and the other is also the root path but it has "name" as parameter.

    • [project folder]/src/app/Route.php
  5. As you see, the routes need HomeController class with the method index(). A controller class can have any name that you like but it must be derived from PHPWebCore/Controller class. The name "HomeController" comes from ASP.NET Core. Moreover, the index() method can take 1 argument or nothing at all. The index() method will call view() method and pass "name" to $args. Now, we create a folder name "Controllers" inside "app" folder and create a file "HomeController.php". Please note that the name of the php file must be the same as the class name.

    • [project folder]/src/app/Controllers/HomeController.php
  6. The routes also need a view for the controller. It recommends to use HTML or PHP for the view file. You could put PHP codes inside your HTML template. According to our declaration in routers, the app will look for the view "HomeView", "HomeView.php" or "HomeView.html" in "Views" folder inside "app" folder. So, we create "Views" folder inside "src/app", then create "HomeView.php" inside "Views" folder.

    • [project folder]/src/app/Views/HomeView.php
  7. So, everything is ready except the last step, the app entry point. Default PHPWebCore app entry class is Bootstrap, which is devired from PHPWebCore/App. Yes, it is Bootstrap instead of Startup. Did you feel the ASP.NET Core until now :D? We need to implement process() method. We will make flow of processing of the app here, such as add servcies to app's container, redirect to HTTPS, allow CORS (origin only), use routing, invoke action, etc... You can also run middlewares here, before and after invoke action like authorization. In this example, we only use routing and invoke action after that.

    • [project folder]/src/app/Bootstrap.php
  8. Finally, your first PHPWebCore app is ready. Run your app and try it. Use the following Urls in your browser.
    • http://[your host]
    • http://[your host]/[name]

      Web API

      In this tutorial, we will create a PHPWebCore Web API app. First thing first, you need to create a PHPWebCore project.

  9. When you have your project, define your API route that uses GET method. This api just simply returns the information of your project in JSON.

    • [project folder]/src/app/Route.php
  10. Next step is creating ProjectController.php of the controller in "Controllers" folder. Set the response content type is application/json.

    • [project folder]/src/app/Controllers/ProjectController.php
  11. It is almost done now. Use the routing and invoke action in your Bootstrap entry class then your app is ready to run.

    • [project folder]/src/app/Bootstrap.php
  12. Is it too simple? Run your project and use below Url in a browser to see your work.
    • http://[your host]/project

      Override exception handler

      This shows how to have your own way to deal with the errors in your app. From your app antry point, the PHPWebCore\ErrorServiceInterface takes care of the exceptions in your app. So, to handle errors by yourself, just have your class implement ErrorServiceInterface and override it in app's container. The interface just need a method name process() with a Throwable parameter.

  13. Create your own exception handler and override the default

    • [project folder]/src/app/ExceptionHandler.php

    • [project folder]/src/app/Bootstrap.php
  14. Run your project and open below Url in browser.
    • http://[your host]

      RedBeanPHP and SQLite

      This example desmonstrates how your PHPWebCore app work with databases. We use RedBeanPHP and SQLite because it is so easy to included to your app.

  15. Before we continue, let's make sure you have SQLite enabled in PHP, created your PHPWebCore and update composer.json to include RedBeanPHP to your app then run update command from Composer

    • php.ini

    • [project folder]/composer.json

    • Run Composer update command
  16. We build 2 services for our app, one is DatabaseService to work with SQLite. It creates a connection and initializes the database in the constructor. It also provides a method to stop the connection before the app stops. The other service is ProjectService which provides the data from database. We use this service as a dependency injection of the controller, so we need to build an interface for this service. You need to create "Services" folder in your app folder to put all of these servies in.

    • [project folder]/src/app/Services/DatabaseService.php

    • [project folder]/src/app/Services/ProjectServiceInterface.php

    • [project folder]/src/app/Services/ProjectService.php
  17. The last step we create a controller, declare a route and update the Bootstrap. Beside use routing and invoke controller action in Boostrap, we need to add ProjectService to app's container, initialize the database and close it before app stops.

    • [project folder]/src/app/Controllers/ProjectController.php

    • [project folder]/src/app/Route.php

    • [project folder]/src/app/Bootstrap.php
  18. Now your PHPWebCore app is ready to run. When the first request send to your app. It will creates a SQLite file name "Project.db" in your app folder. Try the following Url
    • http://[your host]/project

      Firebase PHP-JWT authorization

      This time we make PHPWebCore app work with PHP-JWT authorization.

  19. We create new PHPWebCore project and add Firebase PHP-JWT in

    • [project folder]/composer.json

    • Run Composer update command
  20. We build UserService to provide 2 functions are login() and authorize(). The login() method needs 2 parameters are $username and $password and it generates a token if $username and $password are matched with "username" and "password". The authorize() finds a $token from query string and return payload if $token is valid. We don't use Authorization header in request but the query string so that we can use the token in Url.

    • [project folder]/src/app/Services/UserServiceInterface.php

    • [project folder]/src/app/Services/UserService.php
  21. We also create a controller has 2 action methods login() and getUserInfo(). The login() method get 2 parameters $username and $password from the Url path rather then from POST data so we can test it in a browser easily. The other getUserInfo() method need to be authorized and print the payload from the valid token.

    • [project folder]/src/app/Controllers/UserController.php
  22. Now we just need to declare routes and configure app entry point then it's done.

    • [project folder]/src/app/Route.php

    • [project folder]/src/app/Bootstrap.php
  23. Run your PHPWebCore app and use the login Url to get a token. Then, we use the token in user Url to get the payload from the token.

All versions of phpwebcore with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
psr/http-message Version 1.0.1
psr/http-factory Version 1.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thnguyendev/phpwebcore contains the following files

Loading the files please wait ....