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
47db2ff1
Commit
47db2ff1
authored
Sep 21, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring, added uri class.
parent
1463617f
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
509 additions
and
246 deletions
+509
-246
aliases.php
application/config/aliases.php
+1
-0
.gitignore
application/libraries/.gitignore
+0
-0
changelog.md
changelog.md
+8
-0
arr.php
laravel/arr.php
+4
-2
apc.php
laravel/cache/drivers/apc.php
+48
-11
container.php
laravel/config/container.php
+145
-164
core.php
laravel/core.php
+14
-1
facades.php
laravel/facades.php
+1
-0
file.php
laravel/file.php
+1
-1
form.php
laravel/form.php
+1
-1
loader.php
laravel/loader.php
+59
-2
request.php
laravel/request.php
+72
-52
loader.php
laravel/routing/loader.php
+0
-9
route.php
laravel/routing/route.php
+10
-2
manager.php
laravel/session/manager.php
+4
-1
uri.php
laravel/uri.php
+141
-0
No files found.
application/config/aliases.php
View file @
47db2ff1
...
...
@@ -41,6 +41,7 @@ return array(
'Loader'
=>
'Laravel\\Facades\\Loader'
,
'Messages'
=>
'Laravel\\Validation\\Messages'
,
'Package'
=>
'Laravel\\Facades\\Package'
,
'URI'
=>
'Laravel\\Facades\\URI'
,
'URL'
=>
'Laravel\\Facades\\URL'
,
'Redirect'
=>
'Laravel\\Facades\\Redirect'
,
'Request'
=>
'Laravel\\Facades\\Request'
,
...
...
application/libraries/.gitignore
deleted
100644 → 0
View file @
1463617f
changelog.md
View file @
47db2ff1
# Laravel Change Log
## Version 1.5.9
-
Fixed bug in Eloquent relationship loading.
### Upgrading from 1.5.8
-
Replace
**system**
directory.
## Version 1.5.8
-
Fixed bug in form class that prevent name attributes from being set properly.
...
...
laravel/arr.php
View file @
47db2ff1
<?php
namespace
Laravel
;
use
Closure
;
class
Arr
{
/**
...
...
@@ -30,7 +32,7 @@ class Arr {
{
if
(
!
is_array
(
$array
)
or
!
array_key_exists
(
$segment
,
$array
))
{
return
(
$default
instanceof
\
Closure
)
?
call_user_func
(
$default
)
:
$default
;
return
(
$default
instanceof
Closure
)
?
call_user_func
(
$default
)
:
$default
;
}
$array
=
$array
[
$segment
];
...
...
@@ -107,7 +109,7 @@ class Arr {
if
(
call_user_func
(
$callback
,
$key
,
$value
))
return
$value
;
}
return
(
$default
instanceof
\
Closure
)
?
call_user_func
(
$default
)
:
$default
;
return
(
$default
instanceof
Closure
)
?
call_user_func
(
$default
)
:
$default
;
}
/**
...
...
laravel/cache/drivers/apc.php
View file @
47db2ff1
<?php
namespace
Laravel\Cache\Drivers
;
use
Laravel\Proxy
;
class
APC_Engine
{
/**
* Retrieve an item from the APC cache.
*
* @param string $key
* @return mixed
*/
public
function
fetch
(
$key
)
{
return
apc_fetch
(
$key
);
}
/**
* Store an item in the APC cache.
*
* @param string $key
* @param mixed $value
* @param int $seconds
* @return void
*/
public
function
store
(
$key
,
$value
,
$seconds
)
{
apc_store
(
$key
,
$value
,
$seconds
);
}
/**
* Delete an item from the APC cache.
*
* @param string $key
* @return void
*/
public
function
delete
(
$key
)
{
apc_delete
(
$key
);
}
}
class
APC
extends
Driver
{
/**
* The
proxy class
instance.
* The
APC engine
instance.
*
* @var
Proxy
* @var
APC_Engine
*/
private
$
proxy
;
private
$
apc
;
/**
* The cache key from the cache configuration file.
...
...
@@ -21,14 +58,14 @@ class APC extends Driver {
/**
* Create a new APC cache driver instance.
*
* @param
Proxy $proxy
* @param string $key
* @param
APC_Engine $apc
* @param string
$key
* @return void
*/
public
function
__construct
(
Proxy
$proxy
,
$key
)
public
function
__construct
(
APC_Engine
$apc
,
$key
)
{
$this
->
apc
=
$apc
;
$this
->
key
=
$key
;
$this
->
proxy
=
$proxy
;
}
/**
...
...
@@ -50,7 +87,7 @@ class APC extends Driver {
*/
protected
function
retrieve
(
$key
)
{
if
(
!
is_null
(
$cache
=
$this
->
proxy
->
apc_
fetch
(
$this
->
key
.
$key
)))
return
$cache
;
if
(
!
is_null
(
$cache
=
$this
->
apc
->
fetch
(
$this
->
key
.
$key
)))
return
$cache
;
}
/**
...
...
@@ -63,7 +100,7 @@ class APC extends Driver {
*/
public
function
put
(
$key
,
$value
,
$minutes
)
{
$this
->
proxy
->
apc_
store
(
$this
->
key
.
$key
,
$value
,
$minutes
*
60
);
$this
->
apc
->
store
(
$this
->
key
.
$key
,
$value
,
$minutes
*
60
);
}
/**
...
...
@@ -74,7 +111,7 @@ class APC extends Driver {
*/
public
function
forget
(
$key
)
{
$this
->
proxy
->
apc_
delete
(
$this
->
key
.
$key
);
$this
->
apc
->
delete
(
$this
->
key
.
$key
);
}
}
\ No newline at end of file
laravel/config/container.php
View file @
47db2ff1
This diff is collapsed.
Click to expand it.
laravel/core.php
View file @
47db2ff1
...
...
@@ -69,4 +69,17 @@ spl_autoload_register(array($container->resolve('laravel.loader'), 'load'));
// --------------------------------------------------------------
// Set the application environment configuration option.
// --------------------------------------------------------------
$container
->
resolve
(
'laravel.config'
)
->
set
(
'application.env'
,
$env
);
\ No newline at end of file
$container
->
resolve
(
'laravel.config'
)
->
set
(
'application.env'
,
$env
);
// --------------------------------------------------------------
// Define some convenient global functions.
// --------------------------------------------------------------
function
e
(
$value
)
{
return
IoC
::
container
()
->
resolve
(
'laravel.html'
)
->
entities
(
$value
);
}
function
__
(
$key
,
$replacements
=
array
(),
$language
=
null
)
{
return
IoC
::
container
()
->
resolve
(
'laravel.lang'
)
->
line
(
$key
,
$replacements
,
$language
);
}
\ No newline at end of file
laravel/facades.php
View file @
47db2ff1
...
...
@@ -52,6 +52,7 @@ class Redirect extends Facade { public static $resolve = 'laravel.redirect'; }
class
Request
extends
Facade
{
public
static
$resolve
=
'laravel.request'
;
}
class
Response
extends
Facade
{
public
static
$resolve
=
'laravel.response'
;
}
class
Session
extends
Facade
{
public
static
$resolve
=
'laravel.session'
;
}
class
URI
extends
Facade
{
public
static
$resolve
=
'laravel.uri'
;
}
class
URL
extends
Facade
{
public
static
$resolve
=
'laravel.url'
;
}
class
Validator
extends
Facade
{
public
static
$resolve
=
'laravel.validator'
;
}
class
View
extends
Facade
{
public
static
$resolve
=
'laravel.view'
;
}
\ No newline at end of file
laravel/file.php
View file @
47db2ff1
...
...
@@ -79,7 +79,7 @@ class File {
*/
public
function
delete
(
$path
)
{
@
unlink
(
$path
);
if
(
$this
->
exists
(
$path
))
@
unlink
(
$path
);
}
/**
...
...
laravel/form.php
View file @
47db2ff1
...
...
@@ -81,7 +81,7 @@ class Form {
$attributes
[
'accept-charset'
]
=
$this
->
html
->
encoding
;
}
$append
=
(
$method
==
'PUT'
or
$method
==
'DELETE'
)
?
$this
->
hidden
(
'_REQUEST_METHOD'
,
$method
)
:
''
;
$append
=
(
$method
==
'PUT'
or
$method
==
'DELETE'
)
?
$this
->
hidden
(
Request
::
spoofer
,
$method
)
:
''
;
return
'<form'
.
$this
->
html
->
attributes
(
$attributes
)
.
'>'
.
$append
.
PHP_EOL
;
}
...
...
laravel/loader.php
View file @
47db2ff1
...
...
@@ -7,14 +7,14 @@ class Loader {
*
* @var array
*/
p
ublic
$paths
;
p
rotected
$paths
;
/**
* The class aliases defined for the application.
*
* @var array
*/
p
ublic
$aliases
;
p
rotected
$aliases
;
/**
* Create a new class loader instance.
...
...
@@ -37,8 +37,12 @@ class Loader {
*/
public
function
load
(
$class
)
{
// All Laravel core classes follow a namespace to directory convention. So, we will
// replace all of the namespace slashes with directory slashes.
$file
=
strtolower
(
str_replace
(
'\\'
,
'/'
,
$class
));
// First, we'll check to determine if an alias exists. If it does, we will define the
// alias and bail out. Aliases are defined for most developer used core classes.
if
(
array_key_exists
(
$class
,
$this
->
aliases
))
return
class_alias
(
$this
->
aliases
[
$class
],
$class
);
foreach
(
$this
->
paths
as
$path
)
...
...
@@ -52,4 +56,57 @@ class Loader {
}
}
/**
* Register a class alias with the auto-loader.
*
* Note: Aliases are lazy-loaded, so the aliased class will not be included until it is needed.
*
* <code>
* // Register an alias for the "SwiftMailer\Transport" class
* Loader::alias('Transport', 'SwiftMailer\\Transport');
* </code>
*
* @param string $alias
* @param string $class
* @return void
*/
public
function
alias
(
$alias
,
$class
)
{
$this
->
aliases
[
$alias
]
=
$class
;
}
/**
* Register a path with the auto-loader.
*
* The registered path will be searched when auto-loading classes.
*
* <code>
* // Register a path to be searched by the auto-loader
* Loader::path('path/to/files');
* </code>
*
* @param string $path
* @return void
*/
public
function
path
(
$path
)
{
$this
->
paths
[]
=
rtrim
(
$path
,
'/'
)
.
'/'
;
}
/**
* Remove an alias from the auto-loader's alias registrations.
*
* <code>
* // Remove the "Transport" alias from the registered aliases
* Loader::forget_alias('Transport');
* </code>
*
* @param string $alias
* @return void
*/
public
function
forget_alias
(
$alias
)
{
unset
(
$this
->
aliases
[
$alias
]);
}
}
\ No newline at end of file
laravel/request.php
View file @
47db2ff1
...
...
@@ -2,12 +2,19 @@
class
Request
{
/**
* The URI for the current request.
*
* @var string
*/
protected
$uri
;
/**
* The $_SERVER array for the request.
*
* @var array
*/
p
ublic
$server
;
p
rotected
$server
;
/**
* The $_POST array for the request.
...
...
@@ -17,40 +24,30 @@ class Request {
protected
$post
;
/**
* The
base URL of the application
.
* The
route handling the current request
.
*
* @var
string
* @var
Routing\Route
*/
p
rotected
$url
;
p
ublic
$route
;
/**
* The request URI.
*
* After determining the URI once, this property will be set and returned
* on subsequent requests for the URI.
* The request data key that is used to indicate the spoofed request method.
*
* @var string
*/
protected
$uri
;
/**
* The route handling the current request.
*
* @var Routing\Route
*/
public
$route
;
const
spoofer
=
'__spoofer'
;
/**
* Create a new request instance.
*
* @param string $uri
* @param array $server
* @param array $post
* @param string $url
* @return void
*/
public
function
__construct
(
$
server
,
$post
,
$url
)
public
function
__construct
(
$
uri
,
$server
,
$post
)
{
$this
->
ur
l
=
$url
;
$this
->
ur
i
=
$uri
;
$this
->
post
=
$post
;
$this
->
server
=
$server
;
}
...
...
@@ -69,32 +66,7 @@ class Request {
*/
public
function
uri
()
{
if
(
!
is_null
(
$this
->
uri
))
return
$this
->
uri
;
if
(
isset
(
$this
->
server
[
'PATH_INFO'
]))
{
$uri
=
$this
->
server
[
'PATH_INFO'
];
}
elseif
(
isset
(
$this
->
server
[
'REQUEST_URI'
]))
{
$uri
=
parse_url
(
$this
->
server
[
'REQUEST_URI'
],
PHP_URL_PATH
);
}
else
{
throw
new
\Exception
(
'Unable to determine the request URI.'
);
}
if
(
$uri
===
false
)
{
throw
new
\Exception
(
'Malformed request URI. Request terminated.'
);
}
foreach
(
array
(
parse_url
(
$this
->
url
,
PHP_URL_PATH
),
'/index.php'
)
as
$value
)
{
$uri
=
(
strpos
(
$uri
,
$value
)
===
0
)
?
substr
(
$uri
,
strlen
(
$value
))
:
$uri
;
}
return
$this
->
uri
=
((
$uri
=
trim
(
$uri
,
'/'
))
==
''
)
?
'/'
:
$uri
;
return
$this
->
uri
;
}
/**
...
...
@@ -102,6 +74,14 @@ class Request {
*
* The format is determined by essentially taking the "extension" of the URI.
*
* <code>
* // Returns "html" for a request to "/user/profile"
* $format = Request::format();
*
* // Returns "json" for a request to "/user/profile.json"
* $format = Request::format();
* </code>
*
* @return string
*/
public
function
format
()
...
...
@@ -120,27 +100,62 @@ class Request {
*/
public
function
method
()
{
return
(
$this
->
spoofed
())
?
$this
->
post
[
'_REQUEST_METHOD'
]
:
$this
->
server
[
'REQUEST_METHOD'
];
return
(
$this
->
spoofed
())
?
$this
->
post
[
Request
::
spoofer
]
:
$this
->
server
[
'REQUEST_METHOD'
];
}
/**
* Get an item from the $_SERVER array.
*
* Like most array retrieval methods, a default value may be specified.
*
* <code>
* // Get an item from the $_SERVER array
* $value = Request::server('http_x_requested_for');
*
* // Get an item from the $_SERVER array or return a default value
* $value = Request::server('http_x_requested_for', '127.0.0.1');
* </code>
*
* @param string $key
* @param mixed $default
* @return string
*/
public
function
server
(
$key
=
null
,
$default
=
null
)
{
return
Arr
::
get
(
$this
->
server
,
strtoupper
(
$key
),
$default
);
}
/**
* Determine if the request method is being spoofed by a hidden Form element.
*
* Hidden elements are used to spoof PUT and DELETE requests since they are not supported by HTML forms.
* Hidden elements are used to spoof PUT and DELETE requests since they are not supported
* by HTML forms. If the request is being spoofed, Laravel considers the spoofed request
* method the actual request method throughout the framework.
*
* @return bool
*/
public
function
spoofed
()
{
return
is_array
(
$this
->
post
)
and
array_key_exists
(
'REQUEST_METHOD'
,
$this
->
post
);
return
is_array
(
$this
->
post
)
and
array_key_exists
(
Request
::
spoofer
,
$this
->
post
);
}
/**
* Get the requestor's IP address.
*
* A default may be passed and will be returned in the event the IP can't be determined
*
* <code>
* // Get the requestor's IP address
* $ip = Request::ip();
*
* // Get the requestor's IP address or return a default value
* $ip = Request::ip('127.0.0.1');
* </code>
*
* @param mixed $default
* @return string
*/
public
function
ip
()
public
function
ip
(
$default
=
'0.0.0.0'
)
{
if
(
isset
(
$this
->
server
[
'HTTP_X_FORWARDED_FOR'
]))
{
...
...
@@ -154,11 +169,16 @@ class Request {
{
return
$this
->
server
[
'REMOTE_ADDR'
];
}
return
(
$default
instanceof
\Closure
)
?
call_user_func
(
$default
)
:
$default
;
}
/**
* Get the HTTP protocol for the request.
*
* This method will return either "https" or "http", depending on whether HTTPS
* is being used for the current request.
*
* @return string
*/
public
function
protocol
()
...
...
@@ -167,17 +187,17 @@ class Request {
}
/**
* Determine if the request is using HTTPS.
* Determine if the
current
request is using HTTPS.
*
* @return bool
*/
public
function
secure
()
{
return
(
$this
->
protocol
()
==
'https'
)
;
return
$this
->
protocol
()
==
'https'
;
}
/**
* Determine if the request is an AJAX request.
* Determine if the
current
request is an AJAX request.
*
* @return bool
*/
...
...
laravel/routing/loader.php
View file @
47db2ff1
...
...
@@ -72,14 +72,6 @@ class Loader {
{
return
require
$path
;
}
// Even if we didn't find a matching file for the segment, we still want to
// check for a "routes.php" file which could handle the root route and any
// routes that are impossible to handle in an explicitly named file.
if
(
file_exists
(
$path
=
str_replace
(
'.php'
,
'/routes.php'
,
$path
)))
{
return
require
$path
;
}
}
return
array
();
...
...
@@ -99,7 +91,6 @@ class Loader {
$routes
=
array
();
// First we will check for the base routes file in the application directory.
if
(
file_exists
(
$path
=
$this
->
base
.
'routes'
.
EXT
))
{
$routes
=
array_merge
(
$routes
,
require
$path
);
...
...
laravel/routing/route.php
View file @
47db2ff1
...
...
@@ -99,7 +99,10 @@ class Route {
// route is delegating the responsibility for handling the request to a controller.
elseif
(
is_array
(
$this
->
callback
))
{
$callback
=
Arr
::
first
(
$this
->
callback
,
function
(
$key
,
$value
)
{
return
$key
==
'delegate'
or
$value
instanceof
Closure
;});
$callback
=
Arr
::
first
(
$this
->
callback
,
function
(
$key
,
$value
)
{
return
$key
==
'delegate'
or
$value
instanceof
Closure
;
});
return
(
$callback
instanceof
Closure
)
?
call_user_func_array
(
$callback
,
$this
->
parameters
)
:
new
Delegate
(
$callback
);
}
...
...
@@ -121,7 +124,12 @@ class Route {
*/
public
function
filters
(
$name
)
{
return
(
is_array
(
$this
->
callback
)
and
isset
(
$this
->
callback
[
$name
]))
?
explode
(
', '
,
$this
->
callback
[
$name
])
:
array
();
if
(
is_array
(
$this
->
callback
)
and
isset
(
$this
->
callback
[
$name
]))
{
return
explode
(
', '
,
$this
->
callback
[
$name
]);
}
return
array
();
}
/**
...
...
laravel/session/manager.php
View file @
47db2ff1
...
...
@@ -65,7 +65,10 @@ class Manager {
// are generated per session to protect against Cross-Site Request Forgery attacks on
// the application. It is up to the developer to take advantage of them using the token
// methods on the Form class and the "csrf" route filter.
if
(
!
$payload
->
has
(
'csrf_token'
))
$payload
->
put
(
'csrf_token'
,
Str
::
random
(
16
));
if
(
!
$payload
->
has
(
'csrf_token'
))
{
$payload
->
put
(
'csrf_token'
,
Str
::
random
(
16
));
}
return
$payload
;
}
...
...
laravel/uri.php
0 → 100644
View file @
47db2ff1
<?php
namespace
Laravel
;
class
URI
{
/**
* The $_SERVER array for the current request.
*
* @var array
*/
protected
$server
;
/**
* The application URL as specified in the application configuration file.
*
* @var string
*/
protected
$url
;
/**
* The URI for the current request.
*
* This property will be set after the URI is detected for the first time.
*
* @var string
*/
protected
$uri
;
/**
* Create a new URI instance.
*
* @param array $server
* @param string $url
* @return void
*/
public
function
__construct
(
$server
,
$url
)
{
$this
->
url
=
$url
;
$this
->
server
=
$server
;
}
/**
* Get the URI for the current request.
*
* @return string
*/
public
function
get
()
{
if
(
!
is_null
(
$this
->
uri
))
return
$this
->
uri
;
if
((
$uri
=
$this
->
from_server
())
===
false
)
{
throw
new
\Exception
(
'Malformed request URI. Request terminated.'
);
}
return
$this
->
uri
=
$this
->
format
(
$this
->
clean
(
$uri
));
}
/**
* Get a given URI segment from the URI for the current request.
*
* <code>
* // Get the first segment from the request URI
* $first = Request::uri()->segment(1);
*
* // Get the second segment or return a default value if it doesn't exist
* $second = Request::uri()->segment(2, 'Taylor');
*
* // Get all of the segments for the request URI
* $segments = Request::uri()->segment();
* </code>
*
* @param int $segment
* @param mixed $default
* @return string
*/
public
function
segment
(
$segment
=
null
,
$default
=
null
)
{
$segments
=
Arr
::
without
(
explode
(
'/'
,
$this
->
detect
()),
array
(
''
));
if
(
!
is_null
(
$segment
))
$segment
=
$segment
-
1
;
return
Arr
::
get
(
$segments
,
$segment
,
$default
);
}
/**
* Get the request URI from the $_SERVER array.
*
* @return string
*/
protected
function
from_server
()
{
// If the PATH_INFO $_SERVER element is set, we will use since it contains
// the request URI formatted perfectly for Laravel's routing engine.
if
(
isset
(
$this
->
server
[
'PATH_INFO'
]))
{
return
$this
->
server
[
'PATH_INFO'
];
}
// If the REQUEST_URI is set, we need to extract the URL path since this
// should return the URI formatted in a manner similar to PATH_INFO.
elseif
(
isset
(
$this
->
server
[
'REQUEST_URI'
]))
{
return
parse_url
(
$this
->
server
[
'REQUEST_URI'
],
PHP_URL_PATH
);
}
throw
new
\Exception
(
'Unable to determine the request URI.'
);
}
/**
* Remove extraneous segments from the URI such as the URL and index page.
*
* These segments need to be removed since they will cause problems in the
* routing engine if they are present in the URI.
*
* @param string $uri
* @return string
*/
protected
function
clean
(
$uri
)
{
foreach
(
array
(
parse_url
(
$this
->
url
,
PHP_URL_PATH
),
'/index.php'
)
as
$value
)
{
$uri
=
(
strpos
(
$uri
,
$value
)
===
0
)
?
substr
(
$uri
,
strlen
(
$value
))
:
$uri
;
}
return
$uri
;
}
/**
* Format the URI.
*
* If the request URI is empty, a single forward slash will be returned.
*
* @param string $uri
* @return string
*/
protected
function
format
(
$uri
)
{
return
((
$uri
=
trim
(
$uri
,
'/'
))
==
''
)
?
'/'
:
$uri
;
}
}
\ 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