Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
eb663768
Commit
eb663768
authored
11 years ago
by
Andreas Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Inject memoryCache into Autoloader. Remove recursion-prevention hack.
parent
cadd71ec
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/autoloader.php
+28
-27
28 additions, 27 deletions
lib/autoloader.php
lib/base.php
+5
-1
5 additions, 1 deletion
lib/base.php
with
33 additions
and
28 deletions
lib/autoloader.php
+
28
−
27
View file @
eb663768
...
@@ -15,6 +15,12 @@ class Autoloader {
...
@@ -15,6 +15,12 @@ class Autoloader {
private
$classPaths
=
array
();
private
$classPaths
=
array
();
/**
* Optional low-latency memory cache for class to path mapping.
* @var \OC\Memcache\Cache
*/
protected
$memoryCache
;
/**
/**
* Add a custom prefix to the autoloader
* Add a custom prefix to the autoloader
*
*
...
@@ -112,44 +118,39 @@ class Autoloader {
...
@@ -112,44 +118,39 @@ class Autoloader {
* @param string $class
* @param string $class
* @return bool
* @return bool
*/
*/
protected
$memoryCache
=
null
;
protected
$constructingMemoryCache
=
true
;
// hack to prevent recursion
public
function
load
(
$class
)
{
public
function
load
(
$class
)
{
// Does this PHP have an in-memory cache? We cache the paths there
$pathsToRequire
=
null
;
if
(
$this
->
constructingMemoryCache
&&
!
$this
->
memoryCache
)
{
$this
->
constructingMemoryCache
=
false
;
try
{
$this
->
memoryCache
=
\OC\Memcache\Factory
::
createLowLatency
(
'Autoloader'
);
}
catch
(
\Exception
$ex
)
{
// no caching then - fine with me
}
}
if
(
$this
->
memoryCache
)
{
if
(
$this
->
memoryCache
)
{
$pathsToRequire
=
$this
->
memoryCache
->
get
(
$class
);
$pathsToRequire
=
$this
->
memoryCache
->
get
(
$class
);
if
(
is_array
(
$pathsToRequire
))
{
foreach
(
$pathsToRequire
as
$path
)
{
require_once
$path
;
}
return
false
;
}
}
}
// Use the normal class loading path
if
(
!
is_array
(
$pathsToRequire
))
{
$paths
=
$this
->
findClass
(
$class
);
// No cache or cache miss
if
(
is_array
(
$paths
))
{
$pathsToRequire
=
array
();
$pathsToRequire
=
array
();
foreach
(
$
paths
as
$path
)
{
foreach
(
$
this
->
findClass
(
$class
)
as
$path
)
{
if
(
$fullPath
=
stream_resolve_include_path
(
$path
)
)
{
$fullPath
=
stream_resolve_include_path
(
$path
)
;
require_once
$fullPath
;
if
(
$fullPath
)
{
$pathsToRequire
[]
=
$fullPath
;
$pathsToRequire
[]
=
$fullPath
;
}
}
}
}
}
// Save in our memory cache
if
(
$this
->
memoryCache
)
{
if
(
$this
->
memoryCache
)
{
$this
->
memoryCache
->
set
(
$class
,
$pathsToRequire
,
60
);
// cache 60 sec
$this
->
memoryCache
->
set
(
$class
,
$pathsToRequire
,
60
);
// cache 60 sec
}
}
foreach
(
$pathsToRequire
as
$fullPath
)
{
require_once
$fullPath
;
}
}
return
false
;
return
false
;
}
}
/**
* @brief Sets the optional low-latency cache for class to path mapping.
* @param \OC\Memcache\Cache $memoryCache Instance of memory cache.
*/
public
function
setMemoryCache
(
\OC\Memcache\Cache
$memoryCache
)
{
$this
->
memoryCache
=
$memoryCache
;
}
}
}
This diff is collapsed.
Click to expand it.
lib/base.php
+
5
−
1
View file @
eb663768
...
@@ -371,6 +371,11 @@ class OC {
...
@@ -371,6 +371,11 @@ class OC {
// register autoloader
// register autoloader
require_once
__DIR__
.
'/autoloader.php'
;
require_once
__DIR__
.
'/autoloader.php'
;
self
::
$loader
=
new
\OC\Autoloader
();
self
::
$loader
=
new
\OC\Autoloader
();
spl_autoload_register
(
array
(
self
::
$loader
,
'load'
));
try
{
self
::
$loader
->
setMemoryCache
(
\OC\Memcache\Factory
::
createLowLatency
(
'Autoloader'
));
}
catch
(
\Exception
$ex
)
{
}
self
::
$loader
->
registerPrefix
(
'Doctrine\\Common'
,
'doctrine/common/lib'
);
self
::
$loader
->
registerPrefix
(
'Doctrine\\Common'
,
'doctrine/common/lib'
);
self
::
$loader
->
registerPrefix
(
'Doctrine\\DBAL'
,
'doctrine/dbal/lib'
);
self
::
$loader
->
registerPrefix
(
'Doctrine\\DBAL'
,
'doctrine/dbal/lib'
);
self
::
$loader
->
registerPrefix
(
'Symfony\\Component\\Routing'
,
'symfony/routing'
);
self
::
$loader
->
registerPrefix
(
'Symfony\\Component\\Routing'
,
'symfony/routing'
);
...
@@ -378,7 +383,6 @@ class OC {
...
@@ -378,7 +383,6 @@ class OC {
self
::
$loader
->
registerPrefix
(
'Sabre\\VObject'
,
'3rdparty'
);
self
::
$loader
->
registerPrefix
(
'Sabre\\VObject'
,
'3rdparty'
);
self
::
$loader
->
registerPrefix
(
'Sabre_'
,
'3rdparty'
);
self
::
$loader
->
registerPrefix
(
'Sabre_'
,
'3rdparty'
);
self
::
$loader
->
registerPrefix
(
'Patchwork'
,
'3rdparty'
);
self
::
$loader
->
registerPrefix
(
'Patchwork'
,
'3rdparty'
);
spl_autoload_register
(
array
(
self
::
$loader
,
'load'
));
// set some stuff
// set some stuff
//ob_start();
//ob_start();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment