Laravel Valet Configuration Run Flarum Forum method

Source: Internet
Author: User
Tags php class


Laravel Valet is a minimalist development environment for Mac OS X, but the valet configuration differs from the traditional HTTP server (Apache, Nginx, and so on), unlike rewriting URLs in a configuration file. Valet defines URL processing by using a modular approach in the PHP class. Because the Flarum and laravel default directory structures are different, we need to define their access configuration in valet.

There is a default profile samplevaletdriver.php in the ~/.valet/drivers directory, which contains three methods: Serves,isstaticfile and Frontcontrollerpath. Now we're going to configure our own profile flarumvaletdriver.php, and follow these three methods to write your own driver extensions:

CP samplevaletdriver.php flarumvaletdriver.php
Open flarumvaletdriver.php, first rewrite the Serves method, in which we want to specify valet corresponding to the Web root directory flarum application directory (I am here flarum, if not the same need to modify your own Flarum application directory) exists, which is somewhat similar Nginx in the definition root:

Public function serves ($sitePath, $siteName, $uri) {
Return Is_dir ($sitePath. ' /vendor/flarum ')
&& file_exists ($sitePath. ' /flarum ');
}
The next step in the Isstaticfile method is to determine whether a given URL points to a static file, and the static file does exist, similar to the way we define static file access in Nginx:

Public Function Isstaticfile ($sitePath, $siteName, $uri) {
if ($this->isactualfile ($staticFilePath = $sitePath. $uri)) {
return $staticFilePath;
}

return false;
}
Finally, rewrite the Frontcontrollerpath method, which resembles the Try_uri in Mod_rewrite and Nginx in Apache, where we can override the request access path:

Public Function Frontcontrollerpath ($sitePath, $siteName, $uri)
{
if (Strpos ($uri, '/admin ') = = 0) {
return $sitePath. ' /admin.php ';
}
if (Strpos ($uri, '/api ') = = 0) {
return $sitePath. ' /api.php ';
}

return $sitePath. ' /index.php ';
}
The final results are as follows, and we save it to ~/.valet/drivers:

<?php

Class Flarumvaletdriver extends Valetdriver
{
   /**
     * Determine if the driver serves the request.
     *
     * @param   string  $sitePath
      * @param   string  $siteName
     * @param   string  $uri
& nbsp;    *
     * @return BOOL
     */
     Public Function serves ($sitePath, $siteName, $uri)
    {
     & nbsp;  return Is_dir ($sitePath. ' /vendor/flarum ') && file_exists ($sitePath. ' /flarum ');
   }

/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
*
* @return String|false
*/
Public Function Isstaticfile ($sitePath, $siteName, $uri)
{
if ($this->isactualfile ($staticFilePath = $sitePath. $uri)) {
return $staticFilePath;
}
return false;
}

/**
* Get the fully resolved path to the application ' s front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
*
* @return String
*/
Public Function Frontcontrollerpath ($sitePath, $siteName, $uri)
{
if (Strpos ($uri, '/admin ') = = 0) {
return $sitePath. ' /admin.php ';
}
if (Strpos ($uri, '/api ') = = 0) {
return $sitePath. ' /api.php ';
}

return $sitePath. ' /index.php ';
}
}
This allows normal access to all routes of the falrum. If access is an error:

Call to undefined method Flarumvaletdriver::isactualfile () in/users/sunqiang/.valet/drivers/flarumvaletdriver.php on Line 29
This is because valet is not upgraded to the latest version, and the following command is upgraded valet:

Composer Global Update

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.