Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
ab6e3645
Commit
ab6e3645
authored
Apr 13, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added simpler and easier environment handling.
parent
34cb9a00
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
44 deletions
+106
-44
core.php
laravel/core.php
+70
-41
request.php
laravel/request.php
+25
-0
url.php
laravel/url.php
+1
-3
LaravelRequest.php
...endor/Symfony/Component/HttpFoundation/LaravelRequest.php
+10
-0
No files found.
laravel/core.php
View file @
ab6e3645
...
@@ -108,93 +108,122 @@ Autoloader::namespaces(array(
...
@@ -108,93 +108,122 @@ Autoloader::namespaces(array(
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
Set The CLI Options Array
|
Magic Quotes Strip Slashes
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
|
|
If the current request is from the Artisan command-line interface, we
|
Even though "Magic Quotes" are deprecated in PHP 5.3.x, they may still
|
will parse the command line arguments and options and set them the
|
be enabled on the server. To account for this, we will strip slashes
|
array of options in the $_SERVER global array for convenience
.
|
on all input arrays if magic quotes are enabled for the server
.
|
|
*/
*/
if
(
defined
(
'STDIN'
))
if
(
magic_quotes
(
))
{
{
$
console
=
CLI\Command
::
options
(
$_SERVER
[
'argv'
]
);
$
magics
=
array
(
&
$_GET
,
&
$_POST
,
&
$_COOKIE
,
&
$_REQUEST
);
list
(
$arguments
,
$options
)
=
$console
;
foreach
(
$magics
as
&
$magic
)
{
$magic
=
array_strip_slashes
(
$magic
);
}
}
$options
=
array_change_key_case
(
$options
,
CASE_UPPER
);
/*
|--------------------------------------------------------------------------
| Create The HttpFoundation Request
|--------------------------------------------------------------------------
|
| Laravel uses the HttpFoundation Symfony component to handle the request
| and response functionality for the framework. This allows us to not
| worry about that boilerplate code and focus on what matters.
|
*/
$_SERVER
[
'CLI'
]
=
$options
;
use
Symfony\Component\HttpFoundation\LaravelRequest
as
RequestFoundation
;
}
Request
::
$foundation
=
RequestFoundation
::
createFromGlobals
();
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
Set The CLI Laravel
Environment
|
Determine The Application
Environment
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
|
| Next we'
ll set the LARAVEL_ENV variable if the current request is from
| Next we'
re ready to determine the application environment. This may be
|
the Artisan command-line interface. Since the environment is often
|
set either via the command line options, or, if the request is from
|
specified within an Apache .htaccess file, we need to set it here
|
the web, via the mapping of URIs to environments that lives in
|
when the request is not coming through Apache
.
|
the "paths.php" file for the application and is parsed
.
|
|
*/
*/
if
(
isset
(
$_SERVER
[
'CLI'
][
'ENV'
]))
if
(
Request
::
cli
())
{
foreach
(
Request
::
foundation
()
->
server
->
get
(
'argv'
)
as
$argument
)
{
if
(
starts_with
(
$argument
,
'--env='
))
{
$environment
=
substr
(
$argument
,
6
);
break
;
}
}
}
else
{
{
$
_SERVER
[
'LARAVEL_ENV'
]
=
$_SERVER
[
'CLI'
][
'ENV'
]
;
$
environment
=
Request
::
detect_env
(
$environments
)
;
}
}
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
Register The Laravel Bundles
|
Set The Application Environment
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
|
| Finally we will register all of the bundles that have been defined for
| Once we have determined the application environment, we will set it on
| the application. None of them will be started, yet but will be setup
| the global server array of the HttpFoundation request. This makes it
| so that they may be started by the develop at any time.
| available throughout the application, thought it is mainly only
| used to determine which configuration files to merge in.
|
|
*/
*/
$bundles
=
require
path
(
'app'
)
.
'bundles'
.
EXT
;
if
(
!
is_null
(
$environment
))
foreach
(
$bundles
as
$bundle
=>
$config
)
{
{
Bundle
::
register
(
$bundle
,
$config
);
Request
::
foundation
()
->
server
->
set
(
'LARAVEL_ENV'
,
$environment
);
}
}
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
Magic Quotes Strip Slashes
|
Set The CLI Options Array
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
|
|
Even though "Magic Quotes" are deprecated in PHP 5.3.x, they may still
|
If the current request is from the Artisan command-line interface, we
|
be enabled on the server. To account for this, we will strip slashes
|
will parse the command line arguments and options and set them the
|
on all input arrays if magic quotes are enabled for the server
.
|
array of options in the $_SERVER global array for convenience
.
|
|
*/
*/
if
(
magic_quotes
(
))
if
(
defined
(
'STDIN'
))
{
{
$
magics
=
array
(
&
$_GET
,
&
$_POST
,
&
$_COOKIE
,
&
$_REQUEST
);
$
console
=
CLI\Command
::
options
(
$_SERVER
[
'argv'
]
);
foreach
(
$magics
as
&
$magic
)
list
(
$arguments
,
$options
)
=
$console
;
{
$magic
=
array_strip_slashes
(
$magic
);
$options
=
array_change_key_case
(
$options
,
CASE_UPPER
);
}
$_SERVER
[
'CLI'
]
=
$options
;
}
}
/*
/*
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
Create The HttpFoundation Request
|
Register The Laravel Bundles
|--------------------------------------------------------------------------
|--------------------------------------------------------------------------
|
|
|
Laravel uses the HttpFoundation Symfony component to handle the request
|
Finally we will register all of the bundles that have been defined for
|
and response functionality for the framework. This allows us to not
|
the application. None of them will be started, yet but will be setup
|
worry about that boilerplate code and focus on what matters
.
|
so that they may be started by the develop at any time
.
|
|
*/
*/
use
Symfony\Component\HttpFoundation\LaravelRequest
as
RequestFoundation
;
$bundles
=
require
path
(
'app'
)
.
'bundles'
.
EXT
;
Request
::
$foundation
=
RequestFoundation
::
createFromGlobals
();
foreach
(
$bundles
as
$bundle
=>
$config
)
\ No newline at end of file
{
Bundle
::
register
(
$bundle
,
$config
);
}
\ No newline at end of file
laravel/request.php
View file @
ab6e3645
...
@@ -208,6 +208,31 @@ class Request {
...
@@ -208,6 +208,31 @@ class Request {
return
static
::
env
()
===
$env
;
return
static
::
env
()
===
$env
;
}
}
/**
* Detect the current environment from an environment configuration.
*
* @param array $environments
* @return string|null
*/
public
static
function
detect_env
(
array
$environments
)
{
$root
=
static
::
foundation
()
->
getRootUrl
();
foreach
(
$environments
as
$environment
=>
$patterns
)
{
// Essentially we just want to loop through each environment pattern
// and determine if the current URI matches the pattern and if so
// we'll simply return the environment for that URI pattern.
foreach
(
$patterns
as
$pattern
)
{
if
(
Str
::
is
(
$pattern
,
$root
))
{
return
$environment
;
}
}
}
}
/**
/**
* Get the main route handling the request.
* Get the main route handling the request.
*
*
...
...
laravel/url.php
View file @
ab6e3645
...
@@ -70,9 +70,7 @@ class URL {
...
@@ -70,9 +70,7 @@ class URL {
}
}
else
else
{
{
$f
=
Request
::
foundation
();
$base
=
Request
::
foundation
()
->
getRootUrl
();
$base
=
$f
->
getScheme
()
.
'://'
.
$f
->
getHttpHost
()
.
$f
->
getBasePath
();
}
}
return
static
::
$base
=
$base
;
return
static
::
$base
=
$base
;
...
...
laravel/vendor/Symfony/Component/HttpFoundation/LaravelRequest.php
View file @
ab6e3645
...
@@ -24,4 +24,14 @@ class LaravelRequest extends Request {
...
@@ -24,4 +24,14 @@ class LaravelRequest extends Request {
return
$request
;
return
$request
;
}
}
/**
* Get the root URL of the application.
*
* @return string
*/
public
function
getRootUrl
()
{
return
$this
->
getScheme
()
.
'://'
.
$this
->
getHttpHost
()
.
$this
->
getBasePath
();
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment