Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
66
web/core/lib/Drupal/Component/Annotation/AnnotationBase.php
Normal file
66
web/core/lib/Drupal/Component/Annotation/AnnotationBase.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation;
|
||||
|
||||
/**
|
||||
* Provides a base class for classed annotations.
|
||||
*/
|
||||
abstract class AnnotationBase implements AnnotationInterface {
|
||||
|
||||
/**
|
||||
* The annotated class ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The class used for this annotated class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
/**
|
||||
* The provider of the annotated class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProvider() {
|
||||
return $this->provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setProvider($provider) {
|
||||
$this->provider = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClass() {
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setClass($class) {
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation;
|
||||
|
||||
/**
|
||||
* Defines a common interface for classed annotations.
|
||||
*/
|
||||
interface AnnotationInterface {
|
||||
|
||||
/**
|
||||
* Gets the value of an annotation.
|
||||
*/
|
||||
public function get();
|
||||
|
||||
/**
|
||||
* Gets the name of the provider of the annotated class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProvider();
|
||||
|
||||
/**
|
||||
* Sets the name of the provider of the annotated class.
|
||||
*
|
||||
* @param string $provider
|
||||
*/
|
||||
public function setProvider($provider);
|
||||
|
||||
/**
|
||||
* Gets the unique ID for this annotated class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Gets the class of the annotated class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClass();
|
||||
|
||||
/**
|
||||
* Sets the class of the annotated class.
|
||||
*
|
||||
* @param string $class
|
||||
*/
|
||||
public function setClass($class);
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Annotation/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Annotation/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
112
web/core/lib/Drupal/Component/Annotation/Plugin.php
Normal file
112
web/core/lib/Drupal/Component/Annotation/Plugin.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation;
|
||||
|
||||
use Drupal\Component\Utility\NestedArray;
|
||||
|
||||
/**
|
||||
* Defines a Plugin annotation object.
|
||||
*
|
||||
* Annotations in plugin classes can use this class in order to pass various
|
||||
* metadata about the plugin through the parser to
|
||||
* DiscoveryInterface::getDefinitions() calls. This allows the metadata
|
||||
* of a class to be located with the class itself, rather than in module-based
|
||||
* info hooks.
|
||||
*
|
||||
* @ingroup plugin_api
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class Plugin implements AnnotationInterface {
|
||||
|
||||
/**
|
||||
* The plugin definition read from the class annotation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $definition;
|
||||
|
||||
/**
|
||||
* Constructs a Plugin object.
|
||||
*
|
||||
* Builds up the plugin definition and invokes the get() method for any
|
||||
* classed annotations that were used.
|
||||
*/
|
||||
public function __construct($values) {
|
||||
$reflection = new \ReflectionClass($this);
|
||||
// Only keep actual default values by ignoring NULL values.
|
||||
$defaults = array_filter($reflection->getDefaultProperties(), function ($value) {
|
||||
return $value !== NULL;
|
||||
});
|
||||
$parsed_values = $this->parse($values);
|
||||
$this->definition = NestedArray::mergeDeep($defaults, $parsed_values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an annotation into its definition.
|
||||
*
|
||||
* @param array $values
|
||||
* The annotation array.
|
||||
*
|
||||
* @return array
|
||||
* The parsed annotation as a definition.
|
||||
*/
|
||||
protected function parse(array $values) {
|
||||
$definitions = array();
|
||||
foreach ($values as $key => $value) {
|
||||
if ($value instanceof AnnotationInterface) {
|
||||
$definitions[$key] = $value->get();
|
||||
}
|
||||
elseif (is_array($value)) {
|
||||
$definitions[$key] = $this->parse($value);
|
||||
}
|
||||
else {
|
||||
$definitions[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get() {
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProvider() {
|
||||
return isset($this->definition['provider']) ? $this->definition['provider'] : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setProvider($provider) {
|
||||
$this->definition['provider'] = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->definition['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClass() {
|
||||
return $this->definition['class'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setClass($class) {
|
||||
$this->definition['class'] = $class;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation\Plugin\Discovery;
|
||||
|
||||
use Drupal\Component\Annotation\AnnotationInterface;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
|
||||
use Drupal\Component\Annotation\Reflection\MockFileFinder;
|
||||
use Doctrine\Common\Annotations\SimpleAnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Doctrine\Common\Reflection\StaticReflectionParser;
|
||||
use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
|
||||
|
||||
/**
|
||||
* Defines a discovery mechanism to find annotated plugins in PSR-0 namespaces.
|
||||
*/
|
||||
class AnnotatedClassDiscovery implements DiscoveryInterface {
|
||||
|
||||
use DiscoveryTrait;
|
||||
|
||||
/**
|
||||
* The namespaces within which to find plugin classes.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $pluginNamespaces;
|
||||
|
||||
/**
|
||||
* The name of the annotation that contains the plugin definition.
|
||||
*
|
||||
* The class corresponding to this name must implement
|
||||
* \Drupal\Component\Annotation\AnnotationInterface.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $pluginDefinitionAnnotationName;
|
||||
|
||||
/**
|
||||
* The doctrine annotation reader.
|
||||
*
|
||||
* @var \Doctrine\Common\Annotations\Reader
|
||||
*/
|
||||
protected $annotationReader;
|
||||
|
||||
/**
|
||||
* Additional namespaces to be scanned for annotation classes.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $annotationNamespaces = [];
|
||||
|
||||
/**
|
||||
* The file cache object.
|
||||
*
|
||||
* @var \Drupal\Component\FileCache\FileCacheInterface
|
||||
*/
|
||||
protected $fileCache;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param string[] $plugin_namespaces
|
||||
* (optional) An array of namespace that may contain plugin implementations.
|
||||
* Defaults to an empty array.
|
||||
* @param string $plugin_definition_annotation_name
|
||||
* (optional) The name of the annotation that contains the plugin definition.
|
||||
* Defaults to 'Drupal\Component\Annotation\Plugin'.
|
||||
* @param string[] $annotation_namespaces
|
||||
* (optional) Additional namespaces to be scanned for annotation classes.
|
||||
*/
|
||||
function __construct($plugin_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin', array $annotation_namespaces = []) {
|
||||
$this->pluginNamespaces = $plugin_namespaces;
|
||||
$this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name;
|
||||
$this->annotationNamespaces = $annotation_namespaces;
|
||||
|
||||
$file_cache_suffix = str_replace('\\', '_', $plugin_definition_annotation_name);
|
||||
$file_cache_suffix .= ':' . hash('crc32b', serialize($annotation_namespaces));
|
||||
$this->fileCache = FileCacheFactory::get('annotation_discovery:' . $file_cache_suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the used doctrine annotation reader.
|
||||
*
|
||||
* @return \Doctrine\Common\Annotations\Reader
|
||||
* The annotation reader.
|
||||
*/
|
||||
protected function getAnnotationReader() {
|
||||
if (!isset($this->annotationReader)) {
|
||||
$this->annotationReader = new SimpleAnnotationReader();
|
||||
|
||||
// Add the namespaces from the main plugin annotation, like @EntityType.
|
||||
$namespace = substr($this->pluginDefinitionAnnotationName, 0, strrpos($this->pluginDefinitionAnnotationName, '\\'));
|
||||
$this->annotationReader->addNamespace($namespace);
|
||||
|
||||
// Register additional namespaces to be scanned for annotations.
|
||||
foreach ($this->annotationNamespaces as $namespace) {
|
||||
$this->annotationReader->addNamespace($namespace);
|
||||
}
|
||||
}
|
||||
return $this->annotationReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDefinitions() {
|
||||
$definitions = array();
|
||||
|
||||
$reader = $this->getAnnotationReader();
|
||||
|
||||
// Clear the annotation loaders of any previous annotation classes.
|
||||
AnnotationRegistry::reset();
|
||||
// Register the namespaces of classes that can be used for annotations.
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
|
||||
// Search for classes within all PSR-0 namespace locations.
|
||||
foreach ($this->getPluginNamespaces() as $namespace => $dirs) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (file_exists($dir)) {
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS)
|
||||
);
|
||||
foreach ($iterator as $fileinfo) {
|
||||
if ($fileinfo->getExtension() == 'php') {
|
||||
if ($cached = $this->fileCache->get($fileinfo->getPathName())) {
|
||||
if (isset($cached['id'])) {
|
||||
// Explicitly unserialize this to create a new object instance.
|
||||
$definitions[$cached['id']] = unserialize($cached['content']);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$sub_path = $iterator->getSubIterator()->getSubPath();
|
||||
$sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
|
||||
$class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');
|
||||
|
||||
// The filename is already known, so there is no need to find the
|
||||
// file. However, StaticReflectionParser needs a finder, so use a
|
||||
// mock version.
|
||||
$finder = MockFileFinder::create($fileinfo->getPathName());
|
||||
$parser = new StaticReflectionParser($class, $finder, TRUE);
|
||||
|
||||
/** @var $annotation \Drupal\Component\Annotation\AnnotationInterface */
|
||||
if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass(), $this->pluginDefinitionAnnotationName)) {
|
||||
$this->prepareAnnotationDefinition($annotation, $class);
|
||||
|
||||
$id = $annotation->getId();
|
||||
$content = $annotation->get();
|
||||
$definitions[$id] = $content;
|
||||
// Explicitly serialize this to create a new object instance.
|
||||
$this->fileCache->set($fileinfo->getPathName(), ['id' => $id, 'content' => serialize($content)]);
|
||||
}
|
||||
else {
|
||||
// Store a NULL object, so the file is not reparsed again.
|
||||
$this->fileCache->set($fileinfo->getPathName(), [NULL]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't let annotation loaders pile up.
|
||||
AnnotationRegistry::reset();
|
||||
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the annotation definition.
|
||||
*
|
||||
* @param \Drupal\Component\Annotation\AnnotationInterface $annotation
|
||||
* The annotation derived from the plugin.
|
||||
* @param string $class
|
||||
* The class used for the plugin.
|
||||
*/
|
||||
protected function prepareAnnotationDefinition(AnnotationInterface $annotation, $class) {
|
||||
$annotation->setClass($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of PSR-0 namespaces to search for plugin classes.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getPluginNamespaces() {
|
||||
return $this->pluginNamespaces;
|
||||
}
|
||||
|
||||
}
|
39
web/core/lib/Drupal/Component/Annotation/PluginID.php
Normal file
39
web/core/lib/Drupal/Component/Annotation/PluginID.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation;
|
||||
|
||||
/**
|
||||
* Defines a Plugin annotation object that just contains an ID.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
class PluginID extends AnnotationBase {
|
||||
|
||||
/**
|
||||
* The plugin ID.
|
||||
*
|
||||
* When an annotation is given no key, 'value' is assumed by Doctrine.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get() {
|
||||
return array(
|
||||
'id' => $this->value,
|
||||
'class' => $this->class,
|
||||
'provider' => $this->provider,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
12
web/core/lib/Drupal/Component/Annotation/README.txt
Normal file
12
web/core/lib/Drupal/Component/Annotation/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Annotation Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Annotation\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\ClassFinderInterface;
|
||||
|
||||
/**
|
||||
* Defines a mock file finder that only returns a single filename.
|
||||
*
|
||||
* This can be used with Doctrine\Common\Reflection\StaticReflectionParser if
|
||||
* the filename is known and inheritance is not a concern (for example, if
|
||||
* only the class annotation is needed).
|
||||
*/
|
||||
class MockFileFinder implements ClassFinderInterface {
|
||||
|
||||
/**
|
||||
* The only filename this finder ever returns.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findFile($class) {
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new mock file finder objects.
|
||||
*/
|
||||
static public function create($filename) {
|
||||
$object = new static();
|
||||
$object->filename = $filename;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
18
web/core/lib/Drupal/Component/Annotation/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Annotation/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Annotation
|
20
web/core/lib/Drupal/Component/Annotation/composer.json
Normal file
20
web/core/lib/Drupal/Component/Annotation/composer.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "drupal/core-annotation",
|
||||
"description": "Annotation discovery and implementation of plugins.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"doctrine/common": "2.5.*",
|
||||
"doctrine/annotations": "1.2.*",
|
||||
"drupal/core-fileCache": "~8.2",
|
||||
"drupal/core-plugin": "~8.2",
|
||||
"drupal/core-utility": "~8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Annotation\\": ""
|
||||
}
|
||||
}
|
||||
}
|
41
web/core/lib/Drupal/Component/Assertion/Handle.php
Normal file
41
web/core/lib/Drupal/Component/Assertion/Handle.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Assertion;
|
||||
|
||||
/**
|
||||
* Handler for runtime assertion failures.
|
||||
*
|
||||
* This class allows PHP 5.x to throw exceptions on runtime assertion fails
|
||||
* in the same manner as PHP 7, and sets the ASSERT_EXCEPTION flag to TRUE
|
||||
* for the PHP 7 runtime.
|
||||
*
|
||||
* @ingroup php_assert
|
||||
*/
|
||||
class Handle {
|
||||
|
||||
/**
|
||||
* Registers uniform assertion handling.
|
||||
*/
|
||||
public static function register() {
|
||||
// Since we're using exceptions, turn error warnings off.
|
||||
assert_options(ASSERT_WARNING, FALSE);
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0.0-dev') < 0) {
|
||||
if (!class_exists('AssertionError', FALSE)) {
|
||||
require __DIR__ . '/global_namespace_php5.php';
|
||||
}
|
||||
// PHP 5 - create a handler to throw the exception directly.
|
||||
assert_options(ASSERT_CALLBACK, function($file = '', $line = 0, $code = '', $message = '') {
|
||||
if (empty($message)) {
|
||||
$message = $code;
|
||||
}
|
||||
throw new \AssertionError($message, 0, NULL, $file, $line);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// PHP 7 - just turn exception throwing on.
|
||||
assert_options(ASSERT_EXCEPTION, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
424
web/core/lib/Drupal/Component/Assertion/Inspector.php
Normal file
424
web/core/lib/Drupal/Component/Assertion/Inspector.php
Normal file
|
@ -0,0 +1,424 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Assertion;
|
||||
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Generic inspections for the assert() statement.
|
||||
*
|
||||
* This is a static function collection for inspecting variable contents. All
|
||||
* functions in this collection check a variable against an assertion about its
|
||||
* structure.
|
||||
*
|
||||
* Example call:
|
||||
* @code
|
||||
* assert('Drupal\\Component\\Assertion\\Inspector::assertAllStrings($array)');
|
||||
* @endcode
|
||||
*
|
||||
* @ingroup php_assert
|
||||
*/
|
||||
class Inspector {
|
||||
|
||||
/**
|
||||
* Asserts argument can be traversed with foreach.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed with foreach.
|
||||
*/
|
||||
public static function assertTraversable($traversable) {
|
||||
return is_array($traversable) || $traversable instanceof Traversable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts callback returns TRUE for each member of a traversable.
|
||||
*
|
||||
* This is less memory intensive than using array_filter() to build a second
|
||||
* array and then comparing the arrays. Many of the other functions in this
|
||||
* collection alias this function passing a specific callback to make the
|
||||
* code more readable.
|
||||
*
|
||||
* @param callable $callable
|
||||
* Callback function.
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and $callable returns TRUE on
|
||||
* all members.
|
||||
*
|
||||
* @see http://php.net/manual/language.types.callable.php
|
||||
*/
|
||||
public static function assertAll(callable $callable, $traversable) {
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
if (!$callable($member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are strings.
|
||||
*
|
||||
* Use this only if it is vital that the members not be objects, otherwise
|
||||
* test with ::assertAllStringable().
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are strings.
|
||||
*/
|
||||
public static function assertAllStrings($traversable) {
|
||||
return static::assertAll('is_string', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts all members are strings or objects with magic __toString() method.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are strings or
|
||||
* objects with __toString().
|
||||
*/
|
||||
public static function assertAllStringable($traversable) {
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
if (!static::assertStringable($member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts argument is a string or an object castable to a string.
|
||||
*
|
||||
* Use this instead of is_string() alone unless the argument being an object
|
||||
* in any way will cause a problem.
|
||||
*
|
||||
* @param mixed $string
|
||||
* Variable to be examined
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $string is a string or an object castable to a string.
|
||||
*/
|
||||
public static function assertStringable($string) {
|
||||
return is_string($string) || (is_object($string) && method_exists($string, '__toString'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are arrays.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are arrays.
|
||||
*/
|
||||
public static function assertAllArrays($traversable) {
|
||||
return static::assertAll('is_array', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the array is strict.
|
||||
*
|
||||
* What PHP calls arrays are more formally called maps in most other
|
||||
* programming languages. A map is a datatype that associates values to keys.
|
||||
* The term 'strict array' here refers to a 0-indexed array in the classic
|
||||
* sense found in programming languages other than PHP.
|
||||
*
|
||||
* @param mixed $array
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable is a 0-indexed array.
|
||||
*
|
||||
* @see http://php.net/manual/language.types.array.php
|
||||
*/
|
||||
public static function assertStrictArray($array) {
|
||||
if (!is_array($array)) {
|
||||
return FALSE;
|
||||
}
|
||||
$i = 0;
|
||||
|
||||
foreach (array_keys($array) as $key) {
|
||||
if ($i !== $key) {
|
||||
return FALSE;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts all members are strict arrays.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are strict arrays.
|
||||
*
|
||||
* @see ::assertStrictArray
|
||||
*/
|
||||
public static function assertAllStrictArrays($traversable) {
|
||||
return static::assertAll([__CLASS__, 'assertStrictArray'], $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts all given keys exist in every member array.
|
||||
*
|
||||
* Drupal has several data structure arrays that require certain keys be set.
|
||||
* You can overload this function to specify a list of required keys. All
|
||||
* of the keys must be set for this method to return TRUE.
|
||||
*
|
||||
* As an example, this assertion tests for the keys of a theme registry.
|
||||
*
|
||||
* @code
|
||||
* assert('Drupal\\Component\\Assertion\\Inspector::assertAllHaveKey(
|
||||
* $arrayToTest, "type", "theme path", "function", "template", "variables", "render element", "preprocess functions")');
|
||||
* @endcode
|
||||
*
|
||||
* Note: If a method requires certain keys to be present it will usually be
|
||||
* specific about the data types for the values of those keys. Therefore it
|
||||
* will be best to write a specific test for it. Such tests are either bound
|
||||
* to the object that uses them, or are collected into one assertion set for
|
||||
* the package.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
* @param string ...
|
||||
* Keys to be searched for.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members have all keys.
|
||||
*/
|
||||
public static function assertAllHaveKey() {
|
||||
$args = func_get_args();
|
||||
$traversable = array_shift($args);
|
||||
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
foreach ($args as $key) {
|
||||
if (!array_key_exists($key, $member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are integer values.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are integers.
|
||||
*/
|
||||
public static function assertAllIntegers($traversable) {
|
||||
return static::assertAll('is_int', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are float values.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are floating point
|
||||
* numbers.
|
||||
*/
|
||||
public static function assertAllFloat($traversable) {
|
||||
return static::assertAll('is_float', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are callable.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are callable.
|
||||
*/
|
||||
public static function assertAllCallable($traversable) {
|
||||
return static::assertAll('is_callable', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are not empty.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members not empty.
|
||||
*/
|
||||
public static function assertAllNotEmpty($traversable) {
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
if (empty($member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts all members are numeric data types or strings castable to such.
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are numeric.
|
||||
*/
|
||||
public static function assertAllNumeric($traversable) {
|
||||
return static::assertAll('is_numeric', $traversable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are strings that contain the specified string.
|
||||
*
|
||||
* This runs faster than the regular expression equivalent.
|
||||
*
|
||||
* @param string $pattern
|
||||
* The needle to find.
|
||||
* @param mixed $traversable
|
||||
* Variable to examine.
|
||||
* @param bool $case_sensitive
|
||||
* TRUE to use strstr(), FALSE to use stristr() which is case insensitive.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are strings
|
||||
* containing $pattern.
|
||||
*/
|
||||
public static function assertAllMatch($pattern, $traversable, $case_sensitive = FALSE) {
|
||||
if (static::assertTraversable($traversable)) {
|
||||
if ($case_sensitive) {
|
||||
foreach ($traversable as $member) {
|
||||
if (!(is_string($member) && strstr($member, $pattern))) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($traversable as $member) {
|
||||
if (!(is_string($member) && stristr($member, $pattern))) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that all members are strings matching a regular expression.
|
||||
*
|
||||
* @param string $pattern
|
||||
* Regular expression string to find.
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are strings
|
||||
* matching $pattern.
|
||||
*/
|
||||
public static function assertAllRegularExpressionMatch($pattern, $traversable) {
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
if (!is_string($member)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!preg_match($pattern, $member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that all members are objects.
|
||||
*
|
||||
* When testing if a collection is composed of objects those objects should
|
||||
* be given a common interface to implement and the test should be written to
|
||||
* search for just that interface. While this method will allow tests for
|
||||
* just object status or for multiple classes and interfaces this was done to
|
||||
* allow tests to be written for existing code without altering it. Only use
|
||||
* this method in that manner when testing code from third party vendors.
|
||||
*
|
||||
* Here are some examples:
|
||||
* @code
|
||||
* // Just test all are objects, like a cache.
|
||||
* assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
|
||||
* $collection');
|
||||
*
|
||||
* // Test if traversable objects (arrays won't pass this)
|
||||
* assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
|
||||
* $collection', \'\\Traversable\');
|
||||
*
|
||||
* // Test for the Foo class or Bar\None interface
|
||||
* assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
|
||||
* $collection', \'\\Foo\', \'\\Bar\\None\'');
|
||||
* @endcode
|
||||
*
|
||||
* @param mixed $traversable
|
||||
* Variable to be examined.
|
||||
* @param string ...
|
||||
* Classes and interfaces to test objects against.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if $traversable can be traversed and all members are objects with
|
||||
* at least one of the listed classes or interfaces.
|
||||
*/
|
||||
public static function assertAllObjects() {
|
||||
$args = func_get_args();
|
||||
$traversable = array_shift($args);
|
||||
|
||||
if (static::assertTraversable($traversable)) {
|
||||
foreach ($traversable as $member) {
|
||||
if (count($args) > 0) {
|
||||
foreach ($args as $instance) {
|
||||
if ($member instanceof $instance) {
|
||||
// We're continuing to the next member on the outer loop.
|
||||
// @see http://php.net/continue
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
elseif (!is_object($member)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Assertion/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Assertion/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/Assertion/README.txt
Normal file
12
web/core/lib/Drupal/Component/Assertion/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Assertion Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Assertion/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Assertion/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Assertion
|
15
web/core/lib/Drupal/Component/Assertion/composer.json
Normal file
15
web/core/lib/Drupal/Component/Assertion/composer.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "drupal/core-assertion",
|
||||
"description": "Provides runtime assertions similar to those in PHP 7, under PHP 5.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Assertion\\": ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains PHP5 version of the \AssertionError class.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Emulates PHP 7 AssertionError as closely as possible.
|
||||
*
|
||||
* This class is declared in the global namespace. It will only be included by
|
||||
* \Drupal\Component\Assertion\Handle for PHP5 since this class exists natively
|
||||
* in PHP 7. Note that in PHP 7 it extends from Error, not Exception, but that
|
||||
* isn't possible for PHP 5 - all exceptions must extend from exception.
|
||||
*/
|
||||
class AssertionError extends Exception {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($message = '', $code = 0, Exception $previous = NULL, $file = '', $line = 0) {
|
||||
parent::__construct($message, $code, $previous);
|
||||
// Preserve the filename and line number of the assertion failure.
|
||||
$this->file = $file;
|
||||
$this->line = $line;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Bridge/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Bridge/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/Bridge/README.txt
Normal file
12
web/core/lib/Drupal/Component/Bridge/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Bridge Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Bridge/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Bridge/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Bridge
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Bridge;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Zend\Feed\Reader\ExtensionManagerInterface as ReaderManagerInterface;
|
||||
use Zend\Feed\Writer\ExtensionManagerInterface as WriterManagerInterface;
|
||||
|
||||
/**
|
||||
* Defines a bridge between the ZF2 service manager to Symfony container.
|
||||
*/
|
||||
class ZfExtensionManagerSfContainer implements ReaderManagerInterface, WriterManagerInterface, ContainerAwareInterface {
|
||||
|
||||
/**
|
||||
* This property was based from Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*
|
||||
* A map of characters to be replaced through strtr.
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @see \Drupal\Component\Bridge\ZfExtensionManagerSfContainer::canonicalizeName().
|
||||
*/
|
||||
protected $canonicalNamesReplacements = array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '');
|
||||
|
||||
/**
|
||||
* The prefix to be used when retrieving plugins from the container.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix = '';
|
||||
|
||||
/**
|
||||
* The service container.
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* A local cache of computed canonical names.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $canonicalNames;
|
||||
|
||||
/**
|
||||
* Constructs a ZfExtensionManagerSfContainer object.
|
||||
*
|
||||
* @param string $prefix
|
||||
* The prefix to be used when retrieving plugins from the container.
|
||||
*/
|
||||
public function __construct($prefix = '') {
|
||||
return $this->prefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($extension) {
|
||||
return $this->container->get($this->prefix . $this->canonicalizeName($extension));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($extension) {
|
||||
return $this->container->has($this->prefix . $this->canonicalizeName($extension));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was based from Zend Framework (http://framework.zend.com/)
|
||||
*
|
||||
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
||||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*
|
||||
* Canonicalize the extension name to a service name.
|
||||
*
|
||||
* @param string $name
|
||||
* The extension name.
|
||||
*
|
||||
* @return string
|
||||
* The service name, without the prefix.
|
||||
*/
|
||||
protected function canonicalizeName($name) {
|
||||
if (isset($this->canonicalNames[$name])) {
|
||||
return $this->canonicalNames[$name];
|
||||
}
|
||||
// This is just for performance instead of using str_replace().
|
||||
return $this->canonicalNames[$name] = strtolower(strtr($name, $this->canonicalNamesReplacements));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = NULL) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
}
|
16
web/core/lib/Drupal/Component/Bridge/composer.json
Normal file
16
web/core/lib/Drupal/Component/Bridge/composer.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "drupal/core-bridge",
|
||||
"description": "Bridge.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"zendframework/zend-feed": "~2.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Bridge\\": ""
|
||||
}
|
||||
}
|
||||
}
|
32
web/core/lib/Drupal/Component/ClassFinder/ClassFinder.php
Normal file
32
web/core/lib/Drupal/Component/ClassFinder/ClassFinder.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\ClassFinder;
|
||||
|
||||
use Doctrine\Common\Reflection\ClassFinderInterface;
|
||||
|
||||
/**
|
||||
* A Utility class that uses active autoloaders to find a file for a class.
|
||||
*/
|
||||
class ClassFinder implements ClassFinderInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findFile($class) {
|
||||
$loaders = spl_autoload_functions();
|
||||
foreach ($loaders as $loader) {
|
||||
if (is_array($loader) && isset($loader[0]) && is_object($loader[0]) && method_exists($loader[0], 'findFile')) {
|
||||
$file = call_user_func_array([$loader[0], 'findFile'], [$class]);
|
||||
// Different implementations return different empty values. For example,
|
||||
// \Composer\Autoload\ClassLoader::findFile() returns FALSE whilst
|
||||
// \Doctrine\Common\Reflection\ClassFinderInterface::findFile()
|
||||
// documents that a NULL should be returned.
|
||||
if (!empty($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/ClassFinder/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/ClassFinder/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/ClassFinder/README.txt
Normal file
12
web/core/lib/Drupal/Component/ClassFinder/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal ClassFinder Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/ClassFinder/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/ClassFinder/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group ClassFinder
|
16
web/core/lib/Drupal/Component/ClassFinder/composer.json
Normal file
16
web/core/lib/Drupal/Component/ClassFinder/composer.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "drupal/core-class-finder",
|
||||
"description": "This class provides a class finding utility.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"doctrine/common": "2.5.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\ClassFinder\\": ""
|
||||
}
|
||||
}
|
||||
}
|
654
web/core/lib/Drupal/Component/Datetime/DateTimePlus.php
Normal file
654
web/core/lib/Drupal/Component/Datetime/DateTimePlus.php
Normal file
|
@ -0,0 +1,654 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Datetime;
|
||||
use Drupal\Component\Utility\ToStringTrait;
|
||||
|
||||
/**
|
||||
* Wraps DateTime().
|
||||
*
|
||||
* This class wraps the PHP DateTime class with more flexible initialization
|
||||
* parameters, allowing a date to be created from an existing date object,
|
||||
* a timestamp, a string with an unknown format, a string with a known
|
||||
* format, or an array of date parts. It also adds an errors array
|
||||
* and a __toString() method to the date object.
|
||||
*
|
||||
* This class is less lenient than the DateTime class. It changes
|
||||
* the default behavior for handling date values like '2011-00-00'.
|
||||
* The DateTime class would convert that value to '2010-11-30' and report
|
||||
* a warning but not an error. This extension treats that as an error.
|
||||
*
|
||||
* As with the DateTime class, a date object may be created even if it has
|
||||
* errors. It has an errors array attached to it that explains what the
|
||||
* errors are. This is less disruptive than allowing datetime exceptions
|
||||
* to abort processing. The calling script can decide what to do about
|
||||
* errors using hasErrors() and getErrors().
|
||||
*/
|
||||
class DateTimePlus {
|
||||
|
||||
use ToStringTrait;
|
||||
|
||||
const FORMAT = 'Y-m-d H:i:s';
|
||||
|
||||
/**
|
||||
* A RFC7231 Compliant date.
|
||||
*
|
||||
* http://tools.ietf.org/html/rfc7231#section-7.1.1.1
|
||||
*
|
||||
* Example: Sun, 06 Nov 1994 08:49:37 GMT
|
||||
*/
|
||||
const RFC7231 = 'D, d M Y H:i:s \G\M\T';
|
||||
|
||||
/**
|
||||
* An array of possible date parts.
|
||||
*/
|
||||
protected static $dateParts = array(
|
||||
'year',
|
||||
'month',
|
||||
'day',
|
||||
'hour',
|
||||
'minute',
|
||||
'second',
|
||||
);
|
||||
|
||||
/**
|
||||
* The value of the time value passed to the constructor.
|
||||
*/
|
||||
protected $inputTimeRaw = '';
|
||||
|
||||
/**
|
||||
* The prepared time, without timezone, for this date.
|
||||
*/
|
||||
protected $inputTimeAdjusted = '';
|
||||
|
||||
/**
|
||||
* The value of the timezone passed to the constructor.
|
||||
*/
|
||||
protected $inputTimeZoneRaw = '';
|
||||
|
||||
/**
|
||||
* The prepared timezone object used to construct this date.
|
||||
*/
|
||||
protected $inputTimeZoneAdjusted = '';
|
||||
|
||||
/**
|
||||
* The value of the format passed to the constructor.
|
||||
*/
|
||||
protected $inputFormatRaw = '';
|
||||
|
||||
/**
|
||||
* The prepared format, if provided.
|
||||
*/
|
||||
protected $inputFormatAdjusted = '';
|
||||
|
||||
/**
|
||||
* The value of the language code passed to the constructor.
|
||||
*/
|
||||
protected $langcode = NULL;
|
||||
|
||||
/**
|
||||
* An array of errors encountered when creating this date.
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* The DateTime object.
|
||||
*
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $dateTimeObject = NULL;
|
||||
|
||||
/**
|
||||
* Creates a date object from an input date object.
|
||||
*
|
||||
* @param \DateTime $datetime
|
||||
* A DateTime object.
|
||||
* @param array $settings
|
||||
* @see __construct()
|
||||
*
|
||||
* @return static
|
||||
* A new DateTimePlus object.
|
||||
*/
|
||||
public static function createFromDateTime(\DateTime $datetime, $settings = array()) {
|
||||
return new static($datetime->format(static::FORMAT), $datetime->getTimezone(), $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a date object from an array of date parts.
|
||||
*
|
||||
* Converts the input value into an ISO date, forcing a full ISO
|
||||
* date even if some values are missing.
|
||||
*
|
||||
* @param array $date_parts
|
||||
* An array of date parts, like ('year' => 2014, 'month' => 4).
|
||||
* @param mixed $timezone
|
||||
* (optional) \DateTimeZone object, time zone string or NULL. NULL uses the
|
||||
* default system time zone. Defaults to NULL.
|
||||
* @param array $settings
|
||||
* (optional) A keyed array for settings, suitable for passing on to
|
||||
* __construct().
|
||||
*
|
||||
* @return static
|
||||
* A new DateTimePlus object.
|
||||
*
|
||||
* @throws \Exception
|
||||
* If the array date values or value combination is not correct.
|
||||
*/
|
||||
public static function createFromArray(array $date_parts, $timezone = NULL, $settings = array()) {
|
||||
$date_parts = static::prepareArray($date_parts, TRUE);
|
||||
if (static::checkArray($date_parts)) {
|
||||
// Even with validation, we can end up with a value that the
|
||||
// DateTime class won't handle, like a year outside the range
|
||||
// of -9999 to 9999, which will pass checkdate() but
|
||||
// fail to construct a date object.
|
||||
$iso_date = static::arrayToISO($date_parts);
|
||||
return new static($iso_date, $timezone, $settings);
|
||||
}
|
||||
else {
|
||||
throw new \Exception('The array contains invalid values.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a date object from timestamp input.
|
||||
*
|
||||
* The timezone of a timestamp is always UTC. The timezone for a
|
||||
* timestamp indicates the timezone used by the format() method.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* A UNIX timestamp.
|
||||
* @param mixed $timezone
|
||||
* @see __construct()
|
||||
* @param array $settings
|
||||
* @see __construct()
|
||||
*
|
||||
* @return static
|
||||
* A new DateTimePlus object.
|
||||
*
|
||||
* @throws \Exception
|
||||
* If the timestamp is not numeric.
|
||||
*/
|
||||
public static function createFromTimestamp($timestamp, $timezone = NULL, $settings = array()) {
|
||||
if (!is_numeric($timestamp)) {
|
||||
throw new \Exception('The timestamp must be numeric.');
|
||||
}
|
||||
$datetime = new static('', $timezone, $settings);
|
||||
$datetime->setTimestamp($timestamp);
|
||||
return $datetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a date object from an input format.
|
||||
*
|
||||
* @param string $format
|
||||
* PHP date() type format for parsing the input. This is recommended
|
||||
* to use things like negative years, which php's parser fails on, or
|
||||
* any other specialized input with a known format. If provided the
|
||||
* date will be created using the createFromFormat() method.
|
||||
* @see http://php.net/manual/datetime.createfromformat.php
|
||||
* @param mixed $time
|
||||
* @see __construct()
|
||||
* @param mixed $timezone
|
||||
* @see __construct()
|
||||
* @param array $settings
|
||||
* - validate_format: (optional) Boolean choice to validate the
|
||||
* created date using the input format. The format used in
|
||||
* createFromFormat() allows slightly different values than format().
|
||||
* Using an input format that works in both functions makes it
|
||||
* possible to a validation step to confirm that the date created
|
||||
* from a format string exactly matches the input. This option
|
||||
* indicates the format can be used for validation. Defaults to TRUE.
|
||||
* @see __construct()
|
||||
*
|
||||
* @return static
|
||||
* A new DateTimePlus object.
|
||||
*
|
||||
* @throws \Exception
|
||||
* If the a date cannot be created from the given format, or if the
|
||||
* created date does not match the input value.
|
||||
*/
|
||||
public static function createFromFormat($format, $time, $timezone = NULL, $settings = array()) {
|
||||
if (!isset($settings['validate_format'])) {
|
||||
$settings['validate_format'] = TRUE;
|
||||
}
|
||||
|
||||
// Tries to create a date from the format and use it if possible.
|
||||
// A regular try/catch won't work right here, if the value is
|
||||
// invalid it doesn't return an exception.
|
||||
$datetimeplus = new static('', $timezone, $settings);
|
||||
|
||||
$date = \DateTime::createFromFormat($format, $time, $datetimeplus->getTimezone());
|
||||
if (!$date instanceof \DateTime) {
|
||||
throw new \Exception('The date cannot be created from a format.');
|
||||
}
|
||||
else {
|
||||
// Functions that parse date is forgiving, it might create a date that
|
||||
// is not exactly a match for the provided value, so test for that by
|
||||
// re-creating the date/time formatted string and comparing it to the input. For
|
||||
// instance, an input value of '11' using a format of Y (4 digits) gets
|
||||
// created as '0011' instead of '2011'.
|
||||
if ($date instanceof DateTimePlus) {
|
||||
$test_time = $date->format($format, $settings);
|
||||
}
|
||||
elseif ($date instanceof \DateTime) {
|
||||
$test_time = $date->format($format);
|
||||
}
|
||||
$datetimeplus->setTimestamp($date->getTimestamp());
|
||||
$datetimeplus->setTimezone($date->getTimezone());
|
||||
|
||||
if ($settings['validate_format'] && $test_time != $time) {
|
||||
throw new \Exception('The created date does not match the input value.');
|
||||
}
|
||||
}
|
||||
return $datetimeplus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a date object set to a requested date and timezone.
|
||||
*
|
||||
* @param string $time
|
||||
* (optional) A date/time string. Defaults to 'now'.
|
||||
* @param mixed $timezone
|
||||
* (optional) \DateTimeZone object, time zone string or NULL. NULL uses the
|
||||
* default system time zone. Defaults to NULL.
|
||||
* @param array $settings
|
||||
* (optional) Keyed array of settings. Defaults to empty array.
|
||||
* - langcode: (optional) String two letter language code used to control
|
||||
* the result of the format(). Defaults to NULL.
|
||||
* - debug: (optional) Boolean choice to leave debug values in the
|
||||
* date object for debugging purposes. Defaults to FALSE.
|
||||
*/
|
||||
public function __construct($time = 'now', $timezone = NULL, $settings = array()) {
|
||||
|
||||
// Unpack settings.
|
||||
$this->langcode = !empty($settings['langcode']) ? $settings['langcode'] : NULL;
|
||||
|
||||
// Massage the input values as necessary.
|
||||
$prepared_time = $this->prepareTime($time);
|
||||
$prepared_timezone = $this->prepareTimezone($timezone);
|
||||
|
||||
try {
|
||||
if (!empty($prepared_time)) {
|
||||
$test = date_parse($prepared_time);
|
||||
if (!empty($test['errors'])) {
|
||||
$this->errors[] = $test['errors'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->errors)) {
|
||||
$this->dateTimeObject = new \DateTime($prepared_time, $prepared_timezone);
|
||||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
}
|
||||
|
||||
// Clean up the error messages.
|
||||
$this->checkErrors();
|
||||
$this->errors = array_unique($this->errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the timezone name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render() {
|
||||
return $this->format(static::FORMAT) . ' ' . $this->getTimeZone()->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the magic __call method.
|
||||
*
|
||||
* Passes through all unknown calls onto the DateTime object.
|
||||
*/
|
||||
public function __call($method, $args) {
|
||||
// @todo consider using assert() as per https://www.drupal.org/node/2451793.
|
||||
if (!isset($this->dateTimeObject)) {
|
||||
throw new \Exception('DateTime object not set.');
|
||||
}
|
||||
if (!method_exists($this->dateTimeObject, $method)) {
|
||||
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method));
|
||||
}
|
||||
return call_user_func_array(array($this->dateTimeObject, $method), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference between two DateTimePlus objects.
|
||||
*
|
||||
* @param \Drupal\Component\Datetime\DateTimePlus|\DateTime $datetime2
|
||||
* The date to compare to.
|
||||
* @param bool $absolute
|
||||
* Should the interval be forced to be positive?
|
||||
*
|
||||
* @return \DateInterval
|
||||
* A DateInterval object representing the difference between the two dates.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
* If the input isn't a DateTime or DateTimePlus object.
|
||||
*/
|
||||
public function diff($datetime2, $absolute = FALSE) {
|
||||
if ($datetime2 instanceof DateTimePlus) {
|
||||
$datetime2 = $datetime2->dateTimeObject;
|
||||
}
|
||||
if (!($datetime2 instanceof \DateTime)) {
|
||||
throw new \BadMethodCallException(sprintf('Method %s expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object', __METHOD__));
|
||||
}
|
||||
return $this->dateTimeObject->diff($datetime2, $absolute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the magic __callStatic method.
|
||||
*
|
||||
* Passes through all unknown static calls onto the DateTime object.
|
||||
*/
|
||||
public static function __callStatic($method, $args) {
|
||||
if (!method_exists('\DateTime', $method)) {
|
||||
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $method));
|
||||
}
|
||||
return call_user_func_array(array('\DateTime', $method), $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the magic __clone method.
|
||||
*
|
||||
* Deep-clones the DateTime object we're wrapping.
|
||||
*/
|
||||
public function __clone() {
|
||||
$this->dateTimeObject = clone($this->dateTimeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the input time value.
|
||||
*
|
||||
* Changes the input value before trying to use it, if necessary.
|
||||
* Can be overridden to handle special cases.
|
||||
*
|
||||
* @param mixed $time
|
||||
* An input value, which could be a timestamp, a string,
|
||||
* or an array of date parts.
|
||||
*
|
||||
* @return mixed
|
||||
* The massaged time.
|
||||
*/
|
||||
protected function prepareTime($time) {
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the input timezone value.
|
||||
*
|
||||
* Changes the timezone before trying to use it, if necessary.
|
||||
* Most importantly, makes sure there is a valid timezone
|
||||
* object before moving further.
|
||||
*
|
||||
* @param mixed $timezone
|
||||
* Either a timezone name or a timezone object or NULL.
|
||||
*
|
||||
* @return \DateTimeZone
|
||||
* The massaged time zone.
|
||||
*/
|
||||
protected function prepareTimezone($timezone) {
|
||||
// If the input timezone is a valid timezone object, use it.
|
||||
if ($timezone instanceof \DateTimezone) {
|
||||
$timezone_adjusted = $timezone;
|
||||
}
|
||||
|
||||
// Allow string timezone input, and create a timezone from it.
|
||||
elseif (!empty($timezone) && is_string($timezone)) {
|
||||
$timezone_adjusted = new \DateTimeZone($timezone);
|
||||
}
|
||||
|
||||
// Default to the system timezone when not explicitly provided.
|
||||
// If the system timezone is missing, use 'UTC'.
|
||||
if (empty($timezone_adjusted) || !$timezone_adjusted instanceof \DateTimezone) {
|
||||
$system_timezone = date_default_timezone_get();
|
||||
$timezone_name = !empty($system_timezone) ? $system_timezone : 'UTC';
|
||||
$timezone_adjusted = new \DateTimeZone($timezone_name);
|
||||
}
|
||||
|
||||
// We are finally certain that we have a usable timezone.
|
||||
return $timezone_adjusted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the input format value.
|
||||
*
|
||||
* Changes the input format before trying to use it, if necessary.
|
||||
* Can be overridden to handle special cases.
|
||||
*
|
||||
* @param string $format
|
||||
* A PHP format string.
|
||||
*
|
||||
* @return string
|
||||
* The massaged PHP format string.
|
||||
*/
|
||||
protected function prepareFormat($format) {
|
||||
return $format;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Examines getLastErrors() to see what errors to report.
|
||||
*
|
||||
* Two kinds of errors are important: anything that DateTime
|
||||
* considers an error, and also a warning that the date was invalid.
|
||||
* PHP creates a valid date from invalid data with only a warning,
|
||||
* 2011-02-30 becomes 2011-03-03, for instance, but we don't want that.
|
||||
*
|
||||
* @see http://php.net/manual/time.getlasterrors.php
|
||||
*/
|
||||
public function checkErrors() {
|
||||
$errors = \DateTime::getLastErrors();
|
||||
if (!empty($errors['errors'])) {
|
||||
$this->errors += $errors['errors'];
|
||||
}
|
||||
// Most warnings are messages that the date could not be parsed
|
||||
// which causes it to be altered. For validation purposes, a warning
|
||||
// as bad as an error, because it means the constructed date does
|
||||
// not match the input value.
|
||||
if (!empty($errors['warnings'])) {
|
||||
$this->errors[] = 'The date is invalid.';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if there were errors in the processing of this date.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if there were errors in the processing of this date, FALSE
|
||||
* otherwise.
|
||||
*/
|
||||
public function hasErrors() {
|
||||
return (boolean) count($this->errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets error messages.
|
||||
*
|
||||
* Public function to return the error messages.
|
||||
*
|
||||
* @return array
|
||||
* An array of errors encountered when creating this date.
|
||||
*/
|
||||
public function getErrors() {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ISO date from an array of values.
|
||||
*
|
||||
* @param array $array
|
||||
* An array of date values keyed by date part.
|
||||
* @param bool $force_valid_date
|
||||
* (optional) Whether to force a full date by filling in missing
|
||||
* values. Defaults to FALSE.
|
||||
*
|
||||
* @return string
|
||||
* The date as an ISO string.
|
||||
*/
|
||||
public static function arrayToISO($array, $force_valid_date = FALSE) {
|
||||
$array = static::prepareArray($array, $force_valid_date);
|
||||
$input_time = '';
|
||||
if ($array['year'] !== '') {
|
||||
$input_time = static::datePad(intval($array['year']), 4);
|
||||
if ($force_valid_date || $array['month'] !== '') {
|
||||
$input_time .= '-' . static::datePad(intval($array['month']));
|
||||
if ($force_valid_date || $array['day'] !== '') {
|
||||
$input_time .= '-' . static::datePad(intval($array['day']));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($array['hour'] !== '') {
|
||||
$input_time .= $input_time ? 'T' : '';
|
||||
$input_time .= static::datePad(intval($array['hour']));
|
||||
if ($force_valid_date || $array['minute'] !== '') {
|
||||
$input_time .= ':' . static::datePad(intval($array['minute']));
|
||||
if ($force_valid_date || $array['second'] !== '') {
|
||||
$input_time .= ':' . static::datePad(intval($array['second']));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $input_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a complete array from a possibly incomplete array of date parts.
|
||||
*
|
||||
* @param array $array
|
||||
* An array of date values keyed by date part.
|
||||
* @param bool $force_valid_date
|
||||
* (optional) Whether to force a valid date by filling in missing
|
||||
* values with valid values or just to use empty values instead.
|
||||
* Defaults to FALSE.
|
||||
*
|
||||
* @return array
|
||||
* A complete array of date parts.
|
||||
*/
|
||||
public static function prepareArray($array, $force_valid_date = FALSE) {
|
||||
if ($force_valid_date) {
|
||||
$now = new \DateTime();
|
||||
$array += array(
|
||||
'year' => $now->format('Y'),
|
||||
'month' => 1,
|
||||
'day' => 1,
|
||||
'hour' => 0,
|
||||
'minute' => 0,
|
||||
'second' => 0,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$array += array(
|
||||
'year' => '',
|
||||
'month' => '',
|
||||
'day' => '',
|
||||
'hour' => '',
|
||||
'minute' => '',
|
||||
'second' => '',
|
||||
);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that arrays of date parts will create a valid date.
|
||||
*
|
||||
* Checks that an array of date parts has a year, month, and day,
|
||||
* and that those values create a valid date. If time is provided,
|
||||
* verifies that the time values are valid. Sort of an
|
||||
* equivalent to checkdate().
|
||||
*
|
||||
* @param array $array
|
||||
* An array of datetime values keyed by date part.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the datetime parts contain valid values, otherwise FALSE.
|
||||
*/
|
||||
public static function checkArray($array) {
|
||||
$valid_date = FALSE;
|
||||
$valid_time = TRUE;
|
||||
// Check for a valid date using checkdate(). Only values that
|
||||
// meet that test are valid.
|
||||
if (array_key_exists('year', $array) && array_key_exists('month', $array) && array_key_exists('day', $array)) {
|
||||
if (@checkdate($array['month'], $array['day'], $array['year'])) {
|
||||
$valid_date = TRUE;
|
||||
}
|
||||
}
|
||||
// Testing for valid time is reversed. Missing time is OK,
|
||||
// but incorrect values are not.
|
||||
foreach (array('hour', 'minute', 'second') as $key) {
|
||||
if (array_key_exists($key, $array)) {
|
||||
$value = $array[$key];
|
||||
switch ($key) {
|
||||
case 'hour':
|
||||
if (!preg_match('/^([1-2][0-3]|[01]?[0-9])$/', $value)) {
|
||||
$valid_time = FALSE;
|
||||
}
|
||||
break;
|
||||
case 'minute':
|
||||
case 'second':
|
||||
default:
|
||||
if (!preg_match('/^([0-5][0-9]|[0-9])$/', $value)) {
|
||||
$valid_time = FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $valid_date && $valid_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads date parts with zeros.
|
||||
*
|
||||
* Helper function for a task that is often required when working with dates.
|
||||
*
|
||||
* @param int $value
|
||||
* The value to pad.
|
||||
* @param int $size
|
||||
* (optional) Size expected, usually 2 or 4. Defaults to 2.
|
||||
*
|
||||
* @return string
|
||||
* The padded value.
|
||||
*/
|
||||
public static function datePad($value, $size = 2) {
|
||||
return sprintf("%0" . $size . "d", $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the date for display.
|
||||
*
|
||||
* @param string $format
|
||||
* A format string using either PHP's date().
|
||||
* @param array $settings
|
||||
* - timezone: (optional) String timezone name. Defaults to the timezone
|
||||
* of the date object.
|
||||
*
|
||||
* @return string
|
||||
* The formatted value of the date.
|
||||
*/
|
||||
public function format($format, $settings = array()) {
|
||||
|
||||
// If there were construction errors, we can't format the date.
|
||||
if ($this->hasErrors()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Format the date and catch errors.
|
||||
try {
|
||||
// Clone the date/time object so we can change the time zone without
|
||||
// disturbing the value stored in the object.
|
||||
$dateTimeObject = clone $this->dateTimeObject;
|
||||
if (isset($settings['timezone'])) {
|
||||
$dateTimeObject->setTimezone(new \DateTimeZone($settings['timezone']));
|
||||
}
|
||||
$value = $dateTimeObject->format($format);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Datetime/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Datetime/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/Datetime/README.txt
Normal file
12
web/core/lib/Drupal/Component/Datetime/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Datetime Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Datetime/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Datetime/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Datetime
|
16
web/core/lib/Drupal/Component/Datetime/composer.json
Normal file
16
web/core/lib/Drupal/Component/Datetime/composer.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "drupal/core-datetime",
|
||||
"description": "This class wraps the PHP DateTime class with more flexible initialization parameters, allowing a date to be created from an existing date object, a timestamp, a string with an unknown format, a string with a known format, or an array of date parts. It also adds an errors array and a __toString() method to the date object.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"drupal/core-utility": "~8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Datetime\\": ""
|
||||
}
|
||||
}
|
||||
}
|
662
web/core/lib/Drupal/Component/DependencyInjection/Container.php
Normal file
662
web/core/lib/Drupal/Component/DependencyInjection/Container.php
Normal file
|
@ -0,0 +1,662 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ScopeInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||
|
||||
/**
|
||||
* Provides a container optimized for Drupal's needs.
|
||||
*
|
||||
* This container implementation is compatible with the default Symfony
|
||||
* dependency injection container and similar to the Symfony ContainerBuilder
|
||||
* class, but optimized for speed.
|
||||
*
|
||||
* It is based on a PHP array container definition dumped as a
|
||||
* performance-optimized machine-readable format.
|
||||
*
|
||||
* The best way to initialize this container is to use a Container Builder,
|
||||
* compile it and then retrieve the definition via
|
||||
* \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper::getArray().
|
||||
*
|
||||
* The retrieved array can be cached safely and then passed to this container
|
||||
* via the constructor.
|
||||
*
|
||||
* As the container is unfrozen by default, a second parameter can be passed to
|
||||
* the container to "freeze" the parameter bag.
|
||||
*
|
||||
* This container is different in behavior from the default Symfony container in
|
||||
* the following ways:
|
||||
*
|
||||
* - It only allows lowercase service and parameter names, though it does only
|
||||
* enforce it via assertions for performance reasons.
|
||||
* - The following functions, that are not part of the interface, are explicitly
|
||||
* not supported: getParameterBag(), isFrozen(), compile(),
|
||||
* getAServiceWithAnIdByCamelCase().
|
||||
* - The function getServiceIds() was added as it has a use-case in core and
|
||||
* contrib.
|
||||
* - Scopes are explicitly not allowed, because Symfony 2.8 has deprecated
|
||||
* them and they will be removed in Symfony 3.0.
|
||||
* - Synchronized services are explicitly not supported, because Symfony 2.8 has
|
||||
* deprecated them and they will be removed in Symfony 3.0.
|
||||
*
|
||||
* @ingroup container
|
||||
*/
|
||||
class Container implements IntrospectableContainerInterface, ResettableContainerInterface {
|
||||
|
||||
/**
|
||||
* The parameters of the container.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters = array();
|
||||
|
||||
/**
|
||||
* The aliases of the container.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aliases = array();
|
||||
|
||||
/**
|
||||
* The service definitions of the container.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serviceDefinitions = array();
|
||||
|
||||
/**
|
||||
* The instantiated services.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $services = array();
|
||||
|
||||
/**
|
||||
* The instantiated private services.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $privateServices = array();
|
||||
|
||||
/**
|
||||
* The currently loading services.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $loading = array();
|
||||
|
||||
/**
|
||||
* Whether the container parameters can still be changed.
|
||||
*
|
||||
* For testing purposes the container needs to be changed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $frozen = TRUE;
|
||||
|
||||
/**
|
||||
* Constructs a new Container instance.
|
||||
*
|
||||
* @param array $container_definition
|
||||
* An array containing the following keys:
|
||||
* - aliases: The aliases of the container.
|
||||
* - parameters: The parameters of the container.
|
||||
* - services: The service definitions of the container.
|
||||
* - frozen: Whether the container definition came from a frozen
|
||||
* container builder or not.
|
||||
* - machine_format: Whether this container definition uses the optimized
|
||||
* machine-readable container format.
|
||||
*/
|
||||
public function __construct(array $container_definition = array()) {
|
||||
if (!empty($container_definition) && (!isset($container_definition['machine_format']) || $container_definition['machine_format'] !== TRUE)) {
|
||||
throw new InvalidArgumentException('The non-optimized format is not supported by this class. Use an optimized machine-readable format instead, e.g. as produced by \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper.');
|
||||
}
|
||||
|
||||
$this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : array();
|
||||
$this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : array();
|
||||
$this->serviceDefinitions = isset($container_definition['services']) ? $container_definition['services'] : array();
|
||||
$this->frozen = isset($container_definition['frozen']) ? $container_definition['frozen'] : FALSE;
|
||||
|
||||
// Register the service_container with itself.
|
||||
$this->services['service_container'] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
// Re-use shared service instance if it exists.
|
||||
if (isset($this->services[$id]) || ($invalid_behavior === ContainerInterface::NULL_ON_INVALID_REFERENCE && array_key_exists($id, $this->services))) {
|
||||
return $this->services[$id];
|
||||
}
|
||||
|
||||
if (isset($this->loading[$id])) {
|
||||
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
|
||||
}
|
||||
|
||||
$definition = isset($this->serviceDefinitions[$id]) ? $this->serviceDefinitions[$id] : NULL;
|
||||
|
||||
if (!$definition && $invalid_behavior === ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
|
||||
if (!$id) {
|
||||
throw new ServiceNotFoundException($id);
|
||||
}
|
||||
|
||||
throw new ServiceNotFoundException($id, NULL, NULL, $this->getServiceAlternatives($id));
|
||||
}
|
||||
|
||||
// In case something else than ContainerInterface::NULL_ON_INVALID_REFERENCE
|
||||
// is used, the actual wanted behavior is to re-try getting the service at a
|
||||
// later point.
|
||||
if (!$definition) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Definition is a keyed array, so [0] is only defined when it is a
|
||||
// serialized string.
|
||||
if (isset($definition[0])) {
|
||||
$definition = unserialize($definition);
|
||||
}
|
||||
|
||||
// Now create the service.
|
||||
$this->loading[$id] = TRUE;
|
||||
|
||||
try {
|
||||
$service = $this->createService($definition, $id);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
unset($this->loading[$id]);
|
||||
unset($this->services[$id]);
|
||||
|
||||
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalid_behavior) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
unset($this->loading[$id]);
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
if (!empty($this->scopedServices)) {
|
||||
throw new LogicException('Resetting the container is not allowed when a scope is active.');
|
||||
}
|
||||
|
||||
$this->services = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a service from a service definition.
|
||||
*
|
||||
* @param array $definition
|
||||
* The service definition to create a service from.
|
||||
* @param string $id
|
||||
* The service identifier, necessary so it can be shared if its public.
|
||||
*
|
||||
* @return object
|
||||
* The service described by the service definition.
|
||||
*
|
||||
* @throws \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* Thrown when the service is a synthetic service.
|
||||
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* Thrown when the configurator callable in $definition['configurator'] is
|
||||
* not actually a callable.
|
||||
* @throws \ReflectionException
|
||||
* Thrown when the service class takes more than 10 parameters to construct,
|
||||
* and cannot be instantiated.
|
||||
*/
|
||||
protected function createService(array $definition, $id) {
|
||||
if (isset($definition['synthetic']) && $definition['synthetic'] === TRUE) {
|
||||
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The service container does not know how to construct this service. The service will need to be set before it is first used.', $id));
|
||||
}
|
||||
|
||||
$arguments = array();
|
||||
if (isset($definition['arguments'])) {
|
||||
$arguments = $definition['arguments'];
|
||||
|
||||
if ($arguments instanceof \stdClass) {
|
||||
$arguments = $this->resolveServicesAndParameters($arguments);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['file'])) {
|
||||
$file = $this->frozen ? $definition['file'] : current($this->resolveServicesAndParameters(array($definition['file'])));
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
if (isset($definition['factory'])) {
|
||||
$factory = $definition['factory'];
|
||||
if (is_array($factory)) {
|
||||
$factory = $this->resolveServicesAndParameters(array($factory[0], $factory[1]));
|
||||
}
|
||||
elseif (!is_string($factory)) {
|
||||
throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory', $id));
|
||||
}
|
||||
|
||||
$service = call_user_func_array($factory, $arguments);
|
||||
}
|
||||
else {
|
||||
$class = $this->frozen ? $definition['class'] : current($this->resolveServicesAndParameters(array($definition['class'])));
|
||||
$length = isset($definition['arguments_count']) ? $definition['arguments_count'] : count($arguments);
|
||||
|
||||
// Optimize class instantiation for services with up to 10 parameters as
|
||||
// ReflectionClass is noticeably slow.
|
||||
switch ($length) {
|
||||
case 0:
|
||||
$service = new $class();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$service = new $class($arguments[0]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$service = new $class($arguments[0], $arguments[1]);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2]);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9]);
|
||||
break;
|
||||
|
||||
default:
|
||||
$r = new \ReflectionClass($class);
|
||||
$service = $r->newInstanceArgs($arguments);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Share the service if it is public.
|
||||
if (!isset($definition['public']) || $definition['public'] !== FALSE) {
|
||||
// Forward compatibility fix for Symfony 2.8 update.
|
||||
if (!isset($definition['shared']) || $definition['shared'] !== FALSE) {
|
||||
$this->services[$id] = $service;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['calls'])) {
|
||||
foreach ($definition['calls'] as $call) {
|
||||
$method = $call[0];
|
||||
$arguments = array();
|
||||
if (!empty($call[1])) {
|
||||
$arguments = $call[1];
|
||||
if ($arguments instanceof \stdClass) {
|
||||
$arguments = $this->resolveServicesAndParameters($arguments);
|
||||
}
|
||||
}
|
||||
call_user_func_array(array($service, $method), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['properties'])) {
|
||||
if ($definition['properties'] instanceof \stdClass) {
|
||||
$definition['properties'] = $this->resolveServicesAndParameters($definition['properties']);
|
||||
}
|
||||
foreach ($definition['properties'] as $key => $value) {
|
||||
$service->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['configurator'])) {
|
||||
$callable = $definition['configurator'];
|
||||
if (is_array($callable)) {
|
||||
$callable = $this->resolveServicesAndParameters($callable);
|
||||
}
|
||||
|
||||
if (!is_callable($callable)) {
|
||||
throw new InvalidArgumentException(sprintf('The configurator for class "%s" is not a callable.', get_class($service)));
|
||||
}
|
||||
|
||||
call_user_func($callable, $service);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($id, $service, $scope = ContainerInterface::SCOPE_CONTAINER) {
|
||||
if (!in_array($scope, array('container', 'request')) || ('request' === $scope && 'request' !== $id)) {
|
||||
@trigger_error('The concept of container scopes is deprecated since version 2.8 and will be removed in 3.0. Omit the third parameter.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->services[$id] = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($id) {
|
||||
return isset($this->aliases[$id]) || isset($this->services[$id]) || isset($this->serviceDefinitions[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParameter($name) {
|
||||
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
|
||||
if (!$name) {
|
||||
throw new ParameterNotFoundException($name);
|
||||
}
|
||||
|
||||
throw new ParameterNotFoundException($name, NULL, NULL, NULL, $this->getParameterAlternatives($name));
|
||||
}
|
||||
|
||||
return $this->parameters[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasParameter($name) {
|
||||
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setParameter($name, $value) {
|
||||
if ($this->frozen) {
|
||||
throw new LogicException('Impossible to call set() on a frozen ParameterBag.');
|
||||
}
|
||||
|
||||
$this->parameters[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function initialized($id) {
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves arguments that represent services or variables to the real values.
|
||||
*
|
||||
* @param array|\stdClass $arguments
|
||||
* The arguments to resolve.
|
||||
*
|
||||
* @return array
|
||||
* The resolved arguments.
|
||||
*
|
||||
* @throws \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* If a parameter/service could not be resolved.
|
||||
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* If an unknown type is met while resolving parameters and services.
|
||||
*/
|
||||
protected function resolveServicesAndParameters($arguments) {
|
||||
// Check if this collection needs to be resolved.
|
||||
if ($arguments instanceof \stdClass) {
|
||||
if ($arguments->type !== 'collection') {
|
||||
throw new InvalidArgumentException(sprintf('Undefined type "%s" while resolving parameters and services.', $arguments->type));
|
||||
}
|
||||
// In case there is nothing to resolve, we are done here.
|
||||
if (!$arguments->resolve) {
|
||||
return $arguments->value;
|
||||
}
|
||||
$arguments = $arguments->value;
|
||||
}
|
||||
|
||||
// Process the arguments.
|
||||
foreach ($arguments as $key => $argument) {
|
||||
// For this machine-optimized format, only \stdClass arguments are
|
||||
// processed and resolved. All other values are kept as is.
|
||||
if ($argument instanceof \stdClass) {
|
||||
$type = $argument->type;
|
||||
|
||||
// Check for parameter.
|
||||
if ($type == 'parameter') {
|
||||
$name = $argument->name;
|
||||
if (!isset($this->parameters[$name])) {
|
||||
$arguments[$key] = $this->getParameter($name);
|
||||
// This can never be reached as getParameter() throws an Exception,
|
||||
// because we already checked that the parameter is not set above.
|
||||
}
|
||||
|
||||
// Update argument.
|
||||
$argument = $arguments[$key] = $this->parameters[$name];
|
||||
|
||||
// In case there is not a machine readable value (e.g. a service)
|
||||
// behind this resolved parameter, continue.
|
||||
if (!($argument instanceof \stdClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fall through.
|
||||
$type = $argument->type;
|
||||
}
|
||||
|
||||
// Create a service.
|
||||
if ($type == 'service') {
|
||||
$id = $argument->id;
|
||||
|
||||
// Does the service already exist?
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
if (isset($this->services[$id])) {
|
||||
$arguments[$key] = $this->services[$id];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Return the service.
|
||||
$arguments[$key] = $this->get($id, $argument->invalidBehavior);
|
||||
|
||||
continue;
|
||||
}
|
||||
// Create private service.
|
||||
elseif ($type == 'private_service') {
|
||||
$id = $argument->id;
|
||||
|
||||
// Does the private service already exist.
|
||||
if (isset($this->privateServices[$id])) {
|
||||
$arguments[$key] = $this->privateServices[$id];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the private service.
|
||||
$arguments[$key] = $this->createService($argument->value, $id);
|
||||
if ($argument->shared) {
|
||||
$this->privateServices[$id] = $arguments[$key];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
// Check for collection.
|
||||
elseif ($type == 'collection') {
|
||||
$value = $argument->value;
|
||||
|
||||
// Does this collection need resolving?
|
||||
if ($argument->resolve) {
|
||||
$arguments[$key] = $this->resolveServicesAndParameters($value);
|
||||
}
|
||||
else {
|
||||
$arguments[$key] = $value;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type !== NULL) {
|
||||
throw new InvalidArgumentException(sprintf('Undefined type "%s" while resolving parameters and services.', $type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides alternatives for a given array and key.
|
||||
*
|
||||
* @param string $search_key
|
||||
* The search key to get alternatives for.
|
||||
* @param array $keys
|
||||
* The search space to search for alternatives in.
|
||||
*
|
||||
* @return string[]
|
||||
* An array of strings with suitable alternatives.
|
||||
*/
|
||||
protected function getAlternatives($search_key, array $keys) {
|
||||
$alternatives = array();
|
||||
foreach ($keys as $key) {
|
||||
$lev = levenshtein($search_key, $key);
|
||||
if ($lev <= strlen($search_key) / 3 || strpos($key, $search_key) !== FALSE) {
|
||||
$alternatives[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $alternatives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides alternatives in case a service was not found.
|
||||
*
|
||||
* @param string $id
|
||||
* The service to get alternatives for.
|
||||
*
|
||||
* @return string[]
|
||||
* An array of strings with suitable alternatives.
|
||||
*/
|
||||
protected function getServiceAlternatives($id) {
|
||||
$all_service_keys = array_unique(array_merge(array_keys($this->services), array_keys($this->serviceDefinitions)));
|
||||
return $this->getAlternatives($id, $all_service_keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides alternatives in case a parameter was not found.
|
||||
*
|
||||
* @param string $name
|
||||
* The parameter to get alternatives for.
|
||||
*
|
||||
* @return string[]
|
||||
* An array of strings with suitable alternatives.
|
||||
*/
|
||||
protected function getParameterAlternatives($name) {
|
||||
return $this->getAlternatives($name, array_keys($this->parameters));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function enterScope($name) {
|
||||
if ('request' !== $name) {
|
||||
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function leaveScope($name) {
|
||||
if ('request' !== $name) {
|
||||
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addScope(ScopeInterface $scope) {
|
||||
|
||||
$name = $scope->getName();
|
||||
if ('request' !== $name) {
|
||||
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasScope($name) {
|
||||
if ('request' !== $name) {
|
||||
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isScopeActive($name) {
|
||||
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
throw new \BadMethodCallException(sprintf("'%s' is not supported by Drupal 8.", __FUNCTION__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all defined service IDs.
|
||||
*
|
||||
* @return array
|
||||
* An array of all defined service IDs.
|
||||
*/
|
||||
public function getServiceIds() {
|
||||
return array_keys($this->serviceDefinitions + $this->services);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that cloning doesn't work.
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,517 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Dumper\Dumper;
|
||||
use Symfony\Component\ExpressionLanguage\Expression;
|
||||
|
||||
/**
|
||||
* OptimizedPhpArrayDumper dumps a service container as a serialized PHP array.
|
||||
*
|
||||
* The format of this dumper is very similar to the internal structure of the
|
||||
* ContainerBuilder, but based on PHP arrays and \stdClass objects instead of
|
||||
* rich value objects for performance reasons.
|
||||
*
|
||||
* By removing the abstraction and optimizing some cases like deep collections,
|
||||
* fewer classes need to be loaded, fewer function calls need to be executed and
|
||||
* fewer run time checks need to be made.
|
||||
*
|
||||
* In addition to that, this container dumper treats private services as
|
||||
* strictly private with their own private services storage, whereas in the
|
||||
* Symfony service container builder and PHP dumper, shared private services can
|
||||
* still be retrieved via get() from the container.
|
||||
*
|
||||
* It is machine-optimized, for a human-readable version based on this one see
|
||||
* \Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper.
|
||||
*
|
||||
* @see \Drupal\Component\DependencyInjection\Container
|
||||
*/
|
||||
class OptimizedPhpArrayDumper extends Dumper {
|
||||
|
||||
/**
|
||||
* Whether to serialize service definitions or not.
|
||||
*
|
||||
* Service definitions are serialized by default to avoid having to
|
||||
* unserialize the whole container on loading time, which improves early
|
||||
* bootstrap performance for e.g. the page cache.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $serialize = TRUE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dump(array $options = array()) {
|
||||
return serialize($this->getArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the service container definition as a PHP array.
|
||||
*
|
||||
* @return array
|
||||
* A PHP array representation of the service container.
|
||||
*/
|
||||
public function getArray() {
|
||||
$definition = array();
|
||||
$this->aliases = $this->getAliases();
|
||||
$definition['aliases'] = $this->getAliases();
|
||||
$definition['parameters'] = $this->getParameters();
|
||||
$definition['services'] = $this->getServiceDefinitions();
|
||||
$definition['frozen'] = $this->container->isFrozen();
|
||||
$definition['machine_format'] = $this->supportsMachineFormat();
|
||||
return $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the aliases as a PHP array.
|
||||
*
|
||||
* @return array
|
||||
* The aliases.
|
||||
*/
|
||||
protected function getAliases() {
|
||||
$alias_definitions = array();
|
||||
|
||||
$aliases = $this->container->getAliases();
|
||||
foreach ($aliases as $alias => $id) {
|
||||
$id = (string) $id;
|
||||
while (isset($aliases[$id])) {
|
||||
$id = (string) $aliases[$id];
|
||||
}
|
||||
$alias_definitions[$alias] = $id;
|
||||
}
|
||||
|
||||
return $alias_definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets parameters of the container as a PHP array.
|
||||
*
|
||||
* @return array
|
||||
* The escaped and prepared parameters of the container.
|
||||
*/
|
||||
protected function getParameters() {
|
||||
if (!$this->container->getParameterBag()->all()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$parameters = $this->container->getParameterBag()->all();
|
||||
$is_frozen = $this->container->isFrozen();
|
||||
return $this->prepareParameters($parameters, $is_frozen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets services of the container as a PHP array.
|
||||
*
|
||||
* @return array
|
||||
* The service definitions.
|
||||
*/
|
||||
protected function getServiceDefinitions() {
|
||||
if (!$this->container->getDefinitions()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$services = array();
|
||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||
// Only store public service definitions, references to shared private
|
||||
// services are handled in ::getReferenceCall().
|
||||
if ($definition->isPublic()) {
|
||||
$service_definition = $this->getServiceDefinition($definition);
|
||||
$services[$id] = $this->serialize ? serialize($service_definition) : $service_definition;
|
||||
}
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares parameters for the PHP array dumping.
|
||||
*
|
||||
* @param array $parameters
|
||||
* An array of parameters.
|
||||
* @param bool $escape
|
||||
* Whether keys with '%' should be escaped or not.
|
||||
*
|
||||
* @return array
|
||||
* An array of prepared parameters.
|
||||
*/
|
||||
protected function prepareParameters(array $parameters, $escape = TRUE) {
|
||||
$filtered = array();
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$value = $this->prepareParameters($value, $escape);
|
||||
}
|
||||
elseif ($value instanceof Reference) {
|
||||
$value = $this->dumpValue($value);
|
||||
}
|
||||
|
||||
$filtered[$key] = $value;
|
||||
}
|
||||
|
||||
return $escape ? $this->escape($filtered) : $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes parameters.
|
||||
*
|
||||
* @param array $parameters
|
||||
* The parameters to escape for '%' characters.
|
||||
*
|
||||
* @return array
|
||||
* The escaped parameters.
|
||||
*/
|
||||
protected function escape(array $parameters) {
|
||||
$args = array();
|
||||
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$args[$key] = $this->escape($value);
|
||||
}
|
||||
elseif (is_string($value)) {
|
||||
$args[$key] = str_replace('%', '%%', $value);
|
||||
}
|
||||
else {
|
||||
$args[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a service definition as PHP array.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $definition
|
||||
* The definition to process.
|
||||
*
|
||||
* @return array
|
||||
* The service definition as PHP array.
|
||||
*
|
||||
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* Thrown when the definition is marked as decorated, or with an explicit
|
||||
* scope different from SCOPE_CONTAINER and SCOPE_PROTOTYPE.
|
||||
*/
|
||||
protected function getServiceDefinition(Definition $definition) {
|
||||
$service = array();
|
||||
if ($definition->getClass()) {
|
||||
$service['class'] = $definition->getClass();
|
||||
}
|
||||
|
||||
if (!$definition->isPublic()) {
|
||||
$service['public'] = FALSE;
|
||||
}
|
||||
|
||||
if ($definition->getFile()) {
|
||||
$service['file'] = $definition->getFile();
|
||||
}
|
||||
|
||||
if ($definition->isSynthetic()) {
|
||||
$service['synthetic'] = TRUE;
|
||||
}
|
||||
|
||||
if ($definition->isLazy()) {
|
||||
$service['lazy'] = TRUE;
|
||||
}
|
||||
|
||||
if ($definition->getArguments()) {
|
||||
$arguments = $definition->getArguments();
|
||||
$service['arguments'] = $this->dumpCollection($arguments);
|
||||
$service['arguments_count'] = count($arguments);
|
||||
}
|
||||
else {
|
||||
$service['arguments_count'] = 0;
|
||||
}
|
||||
|
||||
if ($definition->getProperties()) {
|
||||
$service['properties'] = $this->dumpCollection($definition->getProperties());
|
||||
}
|
||||
|
||||
if ($definition->getMethodCalls()) {
|
||||
$service['calls'] = $this->dumpMethodCalls($definition->getMethodCalls());
|
||||
}
|
||||
|
||||
if (($scope = $definition->getScope()) !== ContainerInterface::SCOPE_CONTAINER) {
|
||||
if ($scope === ContainerInterface::SCOPE_PROTOTYPE) {
|
||||
// Scope prototype has been replaced with 'shared' => FALSE.
|
||||
// This is a Symfony 2.8 forward compatibility fix.
|
||||
// Reference: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#dependencyinjection
|
||||
$service['shared'] = FALSE;
|
||||
}
|
||||
else {
|
||||
throw new InvalidArgumentException("The 'scope' definition is deprecated in Symfony 3.0 and not supported by Drupal 8.");
|
||||
}
|
||||
}
|
||||
|
||||
// By default services are shared, so just provide the flag, when needed.
|
||||
if ($definition->isShared() === FALSE) {
|
||||
$service['shared'] = $definition->isShared();
|
||||
}
|
||||
|
||||
if (($decorated = $definition->getDecoratedService()) !== NULL) {
|
||||
throw new InvalidArgumentException("The 'decorated' definition is not supported by the Drupal 8 run-time container. The Container Builder should have resolved that during the DecoratorServicePass compiler pass.");
|
||||
}
|
||||
|
||||
if ($callable = $definition->getFactory()) {
|
||||
$service['factory'] = $this->dumpCallable($callable);
|
||||
}
|
||||
|
||||
if ($callable = $definition->getConfigurator()) {
|
||||
$service['configurator'] = $this->dumpCallable($callable);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps method calls to a PHP array.
|
||||
*
|
||||
* @param array $calls
|
||||
* An array of method calls.
|
||||
*
|
||||
* @return array
|
||||
* The PHP array representation of the method calls.
|
||||
*/
|
||||
protected function dumpMethodCalls(array $calls) {
|
||||
$code = array();
|
||||
|
||||
foreach ($calls as $key => $call) {
|
||||
$method = $call[0];
|
||||
$arguments = array();
|
||||
if (!empty($call[1])) {
|
||||
$arguments = $this->dumpCollection($call[1]);
|
||||
}
|
||||
|
||||
$code[$key] = [$method, $arguments];
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dumps a collection to a PHP array.
|
||||
*
|
||||
* @param mixed $collection
|
||||
* A collection to process.
|
||||
* @param bool &$resolve
|
||||
* Used for passing the information to the caller whether the given
|
||||
* collection needed to be resolved or not. This is used for optimizing
|
||||
* deep arrays that don't need to be traversed.
|
||||
*
|
||||
* @return \stdClass|array
|
||||
* The collection in a suitable format.
|
||||
*/
|
||||
protected function dumpCollection($collection, &$resolve = FALSE) {
|
||||
$code = array();
|
||||
|
||||
foreach ($collection as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$resolve_collection = FALSE;
|
||||
$code[$key] = $this->dumpCollection($value, $resolve_collection);
|
||||
|
||||
if ($resolve_collection) {
|
||||
$resolve = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (is_object($value)) {
|
||||
$resolve = TRUE;
|
||||
}
|
||||
$code[$key] = $this->dumpValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$resolve) {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'type' => 'collection',
|
||||
'value' => $code,
|
||||
'resolve' => $resolve,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps callable to a PHP array.
|
||||
*
|
||||
* @param array|callable $callable
|
||||
* The callable to process.
|
||||
*
|
||||
* @return callable
|
||||
* The processed callable.
|
||||
*/
|
||||
protected function dumpCallable($callable) {
|
||||
if (is_array($callable)) {
|
||||
$callable[0] = $this->dumpValue($callable[0]);
|
||||
$callable = array($callable[0], $callable[1]);
|
||||
}
|
||||
|
||||
return $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a private service definition in a suitable format.
|
||||
*
|
||||
* @param string $id
|
||||
* The ID of the service to get a private definition for.
|
||||
* @param \Symfony\Component\DependencyInjection\Definition $definition
|
||||
* The definition to process.
|
||||
* @param bool $shared
|
||||
* (optional) Whether the service will be shared with others.
|
||||
* By default this parameter is FALSE.
|
||||
*
|
||||
* @return \stdClass
|
||||
* A very lightweight private service value object.
|
||||
*/
|
||||
protected function getPrivateServiceCall($id, Definition $definition, $shared = FALSE) {
|
||||
$service_definition = $this->getServiceDefinition($definition);
|
||||
if (!$id) {
|
||||
$hash = hash('sha1', serialize($service_definition));
|
||||
$id = 'private__' . $hash;
|
||||
}
|
||||
return (object) array(
|
||||
'type' => 'private_service',
|
||||
'id' => $id,
|
||||
'value' => $service_definition,
|
||||
'shared' => $shared,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the value to PHP array format.
|
||||
*
|
||||
* @param mixed $value
|
||||
* The value to dump.
|
||||
*
|
||||
* @return mixed
|
||||
* The dumped value in a suitable format.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
* When trying to dump object or resource.
|
||||
*/
|
||||
protected function dumpValue($value) {
|
||||
if (is_array($value)) {
|
||||
$code = array();
|
||||
foreach ($value as $k => $v) {
|
||||
$code[$k] = $this->dumpValue($v);
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
elseif ($value instanceof Reference) {
|
||||
return $this->getReferenceCall((string) $value, $value);
|
||||
}
|
||||
elseif ($value instanceof Definition) {
|
||||
return $this->getPrivateServiceCall(NULL, $value);
|
||||
}
|
||||
elseif ($value instanceof Parameter) {
|
||||
return $this->getParameterCall((string) $value);
|
||||
}
|
||||
elseif ($value instanceof Expression) {
|
||||
throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
|
||||
}
|
||||
elseif (is_object($value)) {
|
||||
// Drupal specific: Instantiated objects have a _serviceId parameter.
|
||||
if (isset($value->_serviceId)) {
|
||||
return $this->getReferenceCall($value->_serviceId);
|
||||
}
|
||||
throw new RuntimeException('Unable to dump a service container if a parameter is an object without _serviceId.');
|
||||
}
|
||||
elseif (is_resource($value)) {
|
||||
throw new RuntimeException('Unable to dump a service container if a parameter is a resource.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a service reference for a reference in a suitable PHP array format.
|
||||
*
|
||||
* The main difference is that this function treats references to private
|
||||
* services differently and returns a private service reference instead of
|
||||
* a normal reference.
|
||||
*
|
||||
* @param string $id
|
||||
* The ID of the service to get a reference for.
|
||||
* @param \Symfony\Component\DependencyInjection\Reference|null $reference
|
||||
* (optional) The reference object to process; needed to get the invalid
|
||||
* behavior value.
|
||||
*
|
||||
* @return string|\stdClass
|
||||
* A suitable representation of the service reference.
|
||||
*/
|
||||
protected function getReferenceCall($id, Reference $reference = NULL) {
|
||||
$invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
|
||||
if ($reference !== NULL) {
|
||||
$invalid_behavior = $reference->getInvalidBehavior();
|
||||
}
|
||||
|
||||
// Private shared service.
|
||||
if (isset($this->aliases[$id])) {
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
$definition = $this->container->getDefinition($id);
|
||||
if (!$definition->isPublic()) {
|
||||
// The ContainerBuilder does not share a private service, but this means a
|
||||
// new service is instantiated every time. Use a private shared service to
|
||||
// circumvent the problem.
|
||||
return $this->getPrivateServiceCall($id, $definition, TRUE);
|
||||
}
|
||||
|
||||
return $this->getServiceCall($id, $invalid_behavior);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a service reference for an ID in a suitable PHP array format.
|
||||
*
|
||||
* @param string $id
|
||||
* The ID of the service to get a reference for.
|
||||
* @param int $invalid_behavior
|
||||
* (optional) The invalid behavior of the service.
|
||||
*
|
||||
* @return string|\stdClass
|
||||
* A suitable representation of the service reference.
|
||||
*/
|
||||
protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
|
||||
return (object) array(
|
||||
'type' => 'service',
|
||||
'id' => $id,
|
||||
'invalidBehavior' => $invalid_behavior,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a parameter reference in a suitable PHP array format.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the parameter to get a reference for.
|
||||
*
|
||||
* @return string|\stdClass
|
||||
* A suitable representation of the parameter reference.
|
||||
*/
|
||||
protected function getParameterCall($name) {
|
||||
return (object) array(
|
||||
'type' => 'parameter',
|
||||
'name' => $name,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this supports the machine-optimized format or not.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if this supports machine-optimized format, FALSE otherwise.
|
||||
*/
|
||||
protected function supportsMachineFormat() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\DependencyInjection\Dumper;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* PhpArrayDumper dumps a service container as a PHP array.
|
||||
*
|
||||
* The format of this dumper is a human-readable serialized PHP array, which is
|
||||
* very similar to the YAML based format, but based on PHP arrays instead of
|
||||
* YAML strings.
|
||||
*
|
||||
* It is human-readable, for a machine-optimized version based on this one see
|
||||
* \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper.
|
||||
*
|
||||
* @see \Drupal\Component\DependencyInjection\PhpArrayContainer
|
||||
*/
|
||||
class PhpArrayDumper extends OptimizedPhpArrayDumper {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getArray() {
|
||||
$this->serialize = FALSE;
|
||||
return parent::getArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function dumpCollection($collection, &$resolve = FALSE) {
|
||||
$code = array();
|
||||
|
||||
foreach ($collection as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$code[$key] = $this->dumpCollection($value);
|
||||
}
|
||||
else {
|
||||
$code[$key] = $this->dumpValue($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getServiceCall($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
|
||||
if ($invalid_behavior !== ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
|
||||
return '@?' . $id;
|
||||
}
|
||||
|
||||
return '@' . $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getParameterCall($name) {
|
||||
return '%' . $name . '%';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function supportsMachineFormat() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/DependencyInjection/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/DependencyInjection/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Provides a container optimized for Drupal's needs.
|
||||
*
|
||||
* This container implementation is compatible with the default Symfony
|
||||
* dependency injection container and similar to the Symfony ContainerBuilder
|
||||
* class, but optimized for speed.
|
||||
*
|
||||
* It is based on a human-readable PHP array container definition with a
|
||||
* structure very similar to the YAML container definition.
|
||||
*
|
||||
* @see \Drupal\Component\DependencyInjection\Container
|
||||
* @see \Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper
|
||||
* @see \Drupal\Component\DependencyInjection\DependencySerializationTrait
|
||||
*
|
||||
* @ingroup container
|
||||
*/
|
||||
class PhpArrayContainer extends Container {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct(array $container_definition = array()) {
|
||||
if (isset($container_definition['machine_format']) && $container_definition['machine_format'] === TRUE) {
|
||||
throw new InvalidArgumentException('The machine-optimized format is not supported by this class. Use a human-readable format instead, e.g. as produced by \Drupal\Component\DependencyInjection\Dumper\PhpArrayDumper.');
|
||||
}
|
||||
|
||||
// Do not call the parent's constructor as it would bail on the
|
||||
// machine-optimized format.
|
||||
$this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : array();
|
||||
$this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : array();
|
||||
$this->serviceDefinitions = isset($container_definition['services']) ? $container_definition['services'] : array();
|
||||
$this->frozen = isset($container_definition['frozen']) ? $container_definition['frozen'] : FALSE;
|
||||
|
||||
// Register the service_container with itself.
|
||||
$this->services['service_container'] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createService(array $definition, $id) {
|
||||
// This method is a verbatim copy of
|
||||
// \Drupal\Component\DependencyInjection\Container::createService
|
||||
// except for the following difference:
|
||||
// - There are no instanceof checks on \stdClass, which are used in the
|
||||
// parent class to avoid resolving services and parameters when it is
|
||||
// known from dumping that there is nothing to resolve.
|
||||
if (isset($definition['synthetic']) && $definition['synthetic'] === TRUE) {
|
||||
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The service container does not know how to construct this service. The service will need to be set before it is first used.', $id));
|
||||
}
|
||||
|
||||
$arguments = array();
|
||||
if (isset($definition['arguments'])) {
|
||||
$arguments = $this->resolveServicesAndParameters($definition['arguments']);
|
||||
}
|
||||
|
||||
if (isset($definition['file'])) {
|
||||
$file = $this->frozen ? $definition['file'] : current($this->resolveServicesAndParameters(array($definition['file'])));
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
if (isset($definition['factory'])) {
|
||||
$factory = $definition['factory'];
|
||||
if (is_array($factory)) {
|
||||
$factory = $this->resolveServicesAndParameters(array($factory[0], $factory[1]));
|
||||
}
|
||||
elseif (!is_string($factory)) {
|
||||
throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory', $id));
|
||||
}
|
||||
|
||||
$service = call_user_func_array($factory, $arguments);
|
||||
}
|
||||
else {
|
||||
$class = $this->frozen ? $definition['class'] : current($this->resolveServicesAndParameters(array($definition['class'])));
|
||||
$length = isset($definition['arguments_count']) ? $definition['arguments_count'] : count($arguments);
|
||||
|
||||
// Optimize class instantiation for services with up to 10 parameters as
|
||||
// reflection is noticeably slow.
|
||||
switch ($length) {
|
||||
case 0:
|
||||
$service = new $class();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$service = new $class($arguments[0]);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$service = new $class($arguments[0], $arguments[1]);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2]);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
|
||||
break;
|
||||
|
||||
case 7:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7]);
|
||||
break;
|
||||
|
||||
case 9:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8]);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
$service = new $class($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6], $arguments[7], $arguments[8], $arguments[9]);
|
||||
break;
|
||||
|
||||
default:
|
||||
$r = new \ReflectionClass($class);
|
||||
$service = $r->newInstanceArgs($arguments);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Share the service if it is public.
|
||||
if (!isset($definition['public']) || $definition['public'] !== FALSE) {
|
||||
// Forward compatibility fix for Symfony 2.8 update.
|
||||
if (!isset($definition['shared']) || $definition['shared'] !== FALSE) {
|
||||
$this->services[$id] = $service;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['calls'])) {
|
||||
foreach ($definition['calls'] as $call) {
|
||||
$method = $call[0];
|
||||
$arguments = array();
|
||||
if (!empty($call[1])) {
|
||||
$arguments = $call[1];
|
||||
$arguments = $this->resolveServicesAndParameters($arguments);
|
||||
}
|
||||
call_user_func_array(array($service, $method), $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['properties'])) {
|
||||
$definition['properties'] = $this->resolveServicesAndParameters($definition['properties']);
|
||||
foreach ($definition['properties'] as $key => $value) {
|
||||
$service->{$key} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($definition['configurator'])) {
|
||||
$callable = $definition['configurator'];
|
||||
if (is_array($callable)) {
|
||||
$callable = $this->resolveServicesAndParameters($callable);
|
||||
}
|
||||
|
||||
if (!is_callable($callable)) {
|
||||
throw new InvalidArgumentException(sprintf('The configurator for class "%s" is not a callable.', get_class($service)));
|
||||
}
|
||||
|
||||
call_user_func($callable, $service);
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function resolveServicesAndParameters($arguments) {
|
||||
// This method is different from the parent method only for the following
|
||||
// cases:
|
||||
// - A service is denoted by '@service' and not by a \stdClass object.
|
||||
// - A parameter is denoted by '%parameter%' and not by a \stdClass object.
|
||||
// - The depth of the tree representing the arguments is not known in
|
||||
// advance, so it needs to be fully traversed recursively.
|
||||
foreach ($arguments as $key => $argument) {
|
||||
if ($argument instanceof \stdClass) {
|
||||
$type = $argument->type;
|
||||
|
||||
// Private services are a special flavor: In case a private service is
|
||||
// only used by one other service, the ContainerBuilder uses a
|
||||
// Definition object as an argument, which does not have an ID set.
|
||||
// Therefore the format uses a \stdClass object to store the definition
|
||||
// and to be able to create the service on the fly.
|
||||
//
|
||||
// Note: When constructing a private service by hand, 'id' must be set.
|
||||
//
|
||||
// The PhpArrayDumper just uses the hash of the private service
|
||||
// definition to generate a unique ID.
|
||||
//
|
||||
// @see \Drupal\Component\DependecyInjection\Dumper\OptimizedPhpArrayDumper::getPrivateServiceCall
|
||||
if ($type == 'private_service') {
|
||||
$id = $argument->id;
|
||||
|
||||
// Check if the private service already exists - in case it is shared.
|
||||
if (!empty($argument->shared) && isset($this->privateServices[$id])) {
|
||||
$arguments[$key] = $this->privateServices[$id];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create a private service from a service definition.
|
||||
$arguments[$key] = $this->createService($argument->value, $id);
|
||||
if (!empty($argument->shared)) {
|
||||
$this->privateServices[$id] = $arguments[$key];
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type !== NULL) {
|
||||
throw new InvalidArgumentException("Undefined type '$type' while resolving parameters and services.");
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($argument)) {
|
||||
$arguments[$key] = $this->resolveServicesAndParameters($argument);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_string($argument)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Resolve parameters.
|
||||
if ($argument[0] === '%') {
|
||||
$name = substr($argument, 1, -1);
|
||||
if (!isset($this->parameters[$name])) {
|
||||
$arguments[$key] = $this->getParameter($name);
|
||||
// This can never be reached as getParameter() throws an Exception,
|
||||
// because we already checked that the parameter is not set above.
|
||||
}
|
||||
$argument = $this->parameters[$name];
|
||||
$arguments[$key] = $argument;
|
||||
}
|
||||
|
||||
// Resolve services.
|
||||
if ($argument[0] === '@') {
|
||||
$id = substr($argument, 1);
|
||||
$invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
if ($id[0] === '?') {
|
||||
$id = substr($id, 1);
|
||||
$invalid_behavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
|
||||
}
|
||||
if (isset($this->services[$id])) {
|
||||
$arguments[$key] = $this->services[$id];
|
||||
}
|
||||
else {
|
||||
$arguments[$key] = $this->get($id, $invalid_behavior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
}
|
12
web/core/lib/Drupal/Component/DependencyInjection/README.txt
Normal file
12
web/core/lib/Drupal/Component/DependencyInjection/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Dependency Injection Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group DependencyInjection
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"name": "drupal/core-dependency-injection",
|
||||
"description": "Dependency Injection container optimized for Drupal's needs.",
|
||||
"keywords": ["drupal", "dependency injection"],
|
||||
"type": "library",
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/drupal",
|
||||
"irc": "irc://irc.freenode.net/drupal-contribute",
|
||||
"source": "https://www.drupal.org/project/drupal/git-instructions"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/dependency-injection": "~2.8"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/expression-language": "For using expressions in service container configuration"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\DependencyInjection\\": ""
|
||||
}
|
||||
}
|
||||
}
|
172
web/core/lib/Drupal/Component/Diff/Diff.php
Normal file
172
web/core/lib/Drupal/Component/Diff/Diff.php
Normal file
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff;
|
||||
|
||||
use Drupal\Component\Diff\Engine\DiffEngine;
|
||||
|
||||
/**
|
||||
* Class representing a 'diff' between two sequences of strings.
|
||||
* @todo document
|
||||
* @subpackage DifferenceEngine
|
||||
*
|
||||
* Copied from https://www.drupal.org/project/diff which was based PHP diff
|
||||
* engine for phpwiki. (Taken from phpwiki-1.3.3) The original code in phpwiki
|
||||
* was copyright (C) 2000, 2001 Geoffrey T. Dairiki <dairiki@dairiki.org> and
|
||||
* licensed under GPL.
|
||||
*/
|
||||
class Diff {
|
||||
|
||||
/**
|
||||
* The list of differences as an array of diff operations.
|
||||
*
|
||||
* @var \Drupal\Component\Diff\Engine\DiffOp[]
|
||||
*/
|
||||
protected $edits;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Computes diff between sequences of strings.
|
||||
*
|
||||
* @param $from_lines array An array of strings.
|
||||
* (Typically these are lines from a file.)
|
||||
* @param $to_lines array An array of strings.
|
||||
*/
|
||||
public function __construct($from_lines, $to_lines) {
|
||||
$eng = new DiffEngine();
|
||||
$this->edits = $eng->diff($from_lines, $to_lines);
|
||||
//$this->_check($from_lines, $to_lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute reversed Diff.
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* $diff = new Diff($lines1, $lines2);
|
||||
* $rev = $diff->reverse();
|
||||
* @return object A Diff object representing the inverse of the
|
||||
* original diff.
|
||||
*/
|
||||
public function reverse() {
|
||||
$rev = $this;
|
||||
$rev->edits = array();
|
||||
foreach ($this->edits as $edit) {
|
||||
$rev->edits[] = $edit->reverse();
|
||||
}
|
||||
return $rev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for empty diff.
|
||||
*
|
||||
* @return bool True iff two sequences were identical.
|
||||
*/
|
||||
public function isEmpty() {
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->type != 'copy') {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the length of the Longest Common Subsequence (LCS).
|
||||
*
|
||||
* This is mostly for diagnostic purposed.
|
||||
*
|
||||
* @return int The length of the LCS.
|
||||
*/
|
||||
public function lcs() {
|
||||
$lcs = 0;
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->type == 'copy') {
|
||||
$lcs += sizeof($edit->orig);
|
||||
}
|
||||
}
|
||||
return $lcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the original set of lines.
|
||||
*
|
||||
* This reconstructs the $from_lines parameter passed to the
|
||||
* constructor.
|
||||
*
|
||||
* @return array The original sequence of strings.
|
||||
*/
|
||||
public function orig() {
|
||||
$lines = array();
|
||||
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->orig) {
|
||||
array_splice($lines, sizeof($lines), 0, $edit->orig);
|
||||
}
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the closing set of lines.
|
||||
*
|
||||
* This reconstructs the $to_lines parameter passed to the
|
||||
* constructor.
|
||||
*
|
||||
* @return array The sequence of strings.
|
||||
*/
|
||||
public function closing() {
|
||||
$lines = array();
|
||||
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->closing) {
|
||||
array_splice($lines, sizeof($lines), 0, $edit->closing);
|
||||
}
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a Diff for validity.
|
||||
*
|
||||
* This is here only for debugging purposes.
|
||||
*/
|
||||
public function check($from_lines, $to_lines) {
|
||||
if (serialize($from_lines) != serialize($this->orig())) {
|
||||
trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
|
||||
}
|
||||
if (serialize($to_lines) != serialize($this->closing())) {
|
||||
trigger_error("Reconstructed closing doesn't match", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$rev = $this->reverse();
|
||||
if (serialize($to_lines) != serialize($rev->orig())) {
|
||||
trigger_error("Reversed original doesn't match", E_USER_ERROR);
|
||||
}
|
||||
if (serialize($from_lines) != serialize($rev->closing())) {
|
||||
trigger_error("Reversed closing doesn't match", E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
$prevtype = 'none';
|
||||
foreach ($this->edits as $edit) {
|
||||
if ( $prevtype == $edit->type ) {
|
||||
trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
|
||||
}
|
||||
$prevtype = $edit->type;
|
||||
}
|
||||
|
||||
$lcs = $this->lcs();
|
||||
trigger_error('Diff okay: LCS = ' . $lcs, E_USER_NOTICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of differences as an array of diff operations.
|
||||
*
|
||||
* @return \Drupal\Component\Diff\Engine\DiffOp[]
|
||||
* The list of differences as an array of diff operations.
|
||||
*/
|
||||
public function getEdits() {
|
||||
return $this->edits;
|
||||
}
|
||||
|
||||
}
|
197
web/core/lib/Drupal/Component/Diff/DiffFormatter.php
Normal file
197
web/core/lib/Drupal/Component/Diff/DiffFormatter.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff;
|
||||
|
||||
use Drupal\Component\Diff\Engine\DiffOpCopy;
|
||||
|
||||
/**
|
||||
* A class to format Diffs
|
||||
*
|
||||
* This class formats the diff in classic diff format.
|
||||
* It is intended that this class be customized via inheritance,
|
||||
* to obtain fancier outputs.
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffFormatter {
|
||||
/**
|
||||
* Should a block header be shown?
|
||||
*/
|
||||
public $show_header = TRUE;
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*
|
||||
* This should be left at zero for this class, but subclasses
|
||||
* may want to set this to other values.
|
||||
*/
|
||||
public $leading_context_lines = 0;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*
|
||||
* This should be left at zero for this class, but subclasses
|
||||
* may want to set this to other values.
|
||||
*/
|
||||
public $trailing_context_lines = 0;
|
||||
|
||||
/**
|
||||
* The line stats.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $line_stats = array(
|
||||
'counter' => array('x' => 0, 'y' => 0),
|
||||
'offset' => array('x' => 0, 'y' => 0),
|
||||
);
|
||||
|
||||
/**
|
||||
* Format a diff.
|
||||
*
|
||||
* @param \Drupal\Component\Diff\Diff $diff
|
||||
* A Diff object.
|
||||
*
|
||||
* @return string
|
||||
* The formatted output.
|
||||
*/
|
||||
public function format(Diff $diff) {
|
||||
$xi = $yi = 1;
|
||||
$block = FALSE;
|
||||
$context = array();
|
||||
|
||||
$nlead = $this->leading_context_lines;
|
||||
$ntrail = $this->trailing_context_lines;
|
||||
|
||||
$this->_start_diff();
|
||||
|
||||
foreach ($diff->getEdits() as $edit) {
|
||||
if ($edit->type == 'copy') {
|
||||
if (is_array($block)) {
|
||||
if (sizeof($edit->orig) <= $nlead + $ntrail) {
|
||||
$block[] = $edit;
|
||||
}
|
||||
else {
|
||||
if ($ntrail) {
|
||||
$context = array_slice($edit->orig, 0, $ntrail);
|
||||
$block[] = new DiffOpCopy($context);
|
||||
}
|
||||
$this->_block($x0, $ntrail + $xi - $x0, $y0, $ntrail + $yi - $y0, $block);
|
||||
$block = FALSE;
|
||||
}
|
||||
}
|
||||
$context = $edit->orig;
|
||||
}
|
||||
else {
|
||||
if (!is_array($block)) {
|
||||
$context = array_slice($context, sizeof($context) - $nlead);
|
||||
$x0 = $xi - sizeof($context);
|
||||
$y0 = $yi - sizeof($context);
|
||||
$block = array();
|
||||
if ($context) {
|
||||
$block[] = new DiffOpCopy($context);
|
||||
}
|
||||
}
|
||||
$block[] = $edit;
|
||||
}
|
||||
|
||||
if ($edit->orig) {
|
||||
$xi += sizeof($edit->orig);
|
||||
}
|
||||
if ($edit->closing) {
|
||||
$yi += sizeof($edit->closing);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($block)) {
|
||||
$this->_block($x0, $xi - $x0, $y0, $yi - $y0, $block);
|
||||
}
|
||||
$end = $this->_end_diff();
|
||||
|
||||
if (!empty($xi)) {
|
||||
$this->line_stats['counter']['x'] += $xi;
|
||||
}
|
||||
if (!empty($yi)) {
|
||||
$this->line_stats['counter']['y'] += $yi;
|
||||
}
|
||||
|
||||
return $end;
|
||||
}
|
||||
|
||||
protected function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) {
|
||||
$this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen));
|
||||
foreach ($edits as $edit) {
|
||||
if ($edit->type == 'copy') {
|
||||
$this->_context($edit->orig);
|
||||
}
|
||||
elseif ($edit->type == 'add') {
|
||||
$this->_added($edit->closing);
|
||||
}
|
||||
elseif ($edit->type == 'delete') {
|
||||
$this->_deleted($edit->orig);
|
||||
}
|
||||
elseif ($edit->type == 'change') {
|
||||
$this->_changed($edit->orig, $edit->closing);
|
||||
}
|
||||
else {
|
||||
trigger_error('Unknown edit type', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
$this->_end_block();
|
||||
}
|
||||
|
||||
protected function _start_diff() {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
protected function _end_diff() {
|
||||
$val = ob_get_contents();
|
||||
ob_end_clean();
|
||||
return $val;
|
||||
}
|
||||
|
||||
protected function _block_header($xbeg, $xlen, $ybeg, $ylen) {
|
||||
if ($xlen > 1) {
|
||||
$xbeg .= "," . ($xbeg + $xlen - 1);
|
||||
}
|
||||
if ($ylen > 1) {
|
||||
$ybeg .= "," . ($ybeg + $ylen - 1);
|
||||
}
|
||||
|
||||
return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
|
||||
}
|
||||
|
||||
protected function _start_block($header) {
|
||||
if ($this->show_header) {
|
||||
echo $header . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function _end_block() {
|
||||
}
|
||||
|
||||
protected function _lines($lines, $prefix = ' ') {
|
||||
foreach ($lines as $line) {
|
||||
echo "$prefix $line\n";
|
||||
}
|
||||
}
|
||||
|
||||
protected function _context($lines) {
|
||||
$this->_lines($lines);
|
||||
}
|
||||
|
||||
protected function _added($lines) {
|
||||
$this->_lines($lines, '>');
|
||||
}
|
||||
|
||||
protected function _deleted($lines) {
|
||||
$this->_lines($lines, '<');
|
||||
}
|
||||
|
||||
protected function _changed($orig, $closing) {
|
||||
$this->_deleted($orig);
|
||||
echo "---\n";
|
||||
$this->_added($closing);
|
||||
}
|
||||
|
||||
}
|
457
web/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
Normal file
457
web/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
Normal file
|
@ -0,0 +1,457 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Class used internally by Diff to actually compute the diffs.
|
||||
*
|
||||
* The algorithm used here is mostly lifted from the perl module
|
||||
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
|
||||
* http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
|
||||
*
|
||||
* More ideas are taken from:
|
||||
* http://www.ics.uci.edu/~eppstein/161/960229.html
|
||||
*
|
||||
* Some ideas (and a bit of code) are from analyze.c, from GNU
|
||||
* diffutils-2.7, which can be found at:
|
||||
* ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
|
||||
*
|
||||
* closingly, some ideas (subdivision by NCHUNKS > 2, and some optimizations)
|
||||
* are my own.
|
||||
*
|
||||
* Line length limits for robustness added by Tim Starling, 2005-08-31
|
||||
*
|
||||
* @author Geoffrey T. Dairiki, Tim Starling
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffEngine {
|
||||
|
||||
const USE_ASSERTS = FALSE;
|
||||
|
||||
const MAX_XREF_LENGTH = 10000;
|
||||
|
||||
public function diff($from_lines, $to_lines) {
|
||||
|
||||
$n_from = sizeof($from_lines);
|
||||
$n_to = sizeof($to_lines);
|
||||
|
||||
$this->xchanged = $this->ychanged = array();
|
||||
$this->xv = $this->yv = array();
|
||||
$this->xind = $this->yind = array();
|
||||
unset($this->seq);
|
||||
unset($this->in_seq);
|
||||
unset($this->lcs);
|
||||
|
||||
// Skip leading common lines.
|
||||
for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
|
||||
if ($from_lines[$skip] !== $to_lines[$skip]) {
|
||||
break;
|
||||
}
|
||||
$this->xchanged[$skip] = $this->ychanged[$skip] = FALSE;
|
||||
}
|
||||
// Skip trailing common lines.
|
||||
$xi = $n_from;
|
||||
$yi = $n_to;
|
||||
for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
|
||||
if ($from_lines[$xi] !== $to_lines[$yi]) {
|
||||
break;
|
||||
}
|
||||
$this->xchanged[$xi] = $this->ychanged[$yi] = FALSE;
|
||||
}
|
||||
|
||||
// Ignore lines which do not exist in both files.
|
||||
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
|
||||
$xhash[$this->_line_hash($from_lines[$xi])] = 1;
|
||||
}
|
||||
|
||||
for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
|
||||
$line = $to_lines[$yi];
|
||||
if ($this->ychanged[$yi] = empty($xhash[$this->_line_hash($line)])) {
|
||||
continue;
|
||||
}
|
||||
$yhash[$this->_line_hash($line)] = 1;
|
||||
$this->yv[] = $line;
|
||||
$this->yind[] = $yi;
|
||||
}
|
||||
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
|
||||
$line = $from_lines[$xi];
|
||||
if ($this->xchanged[$xi] = empty($yhash[$this->_line_hash($line)])) {
|
||||
continue;
|
||||
}
|
||||
$this->xv[] = $line;
|
||||
$this->xind[] = $xi;
|
||||
}
|
||||
|
||||
// Find the LCS.
|
||||
$this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv));
|
||||
|
||||
// Merge edits when possible
|
||||
$this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
|
||||
$this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
|
||||
|
||||
// Compute the edit operations.
|
||||
$edits = array();
|
||||
$xi = $yi = 0;
|
||||
while ($xi < $n_from || $yi < $n_to) {
|
||||
$this::USE_ASSERTS && assert($yi < $n_to || $this->xchanged[$xi]);
|
||||
$this::USE_ASSERTS && assert($xi < $n_from || $this->ychanged[$yi]);
|
||||
|
||||
// Skip matching "snake".
|
||||
$copy = array();
|
||||
while ( $xi < $n_from && $yi < $n_to && !$this->xchanged[$xi] && !$this->ychanged[$yi]) {
|
||||
$copy[] = $from_lines[$xi++];
|
||||
++$yi;
|
||||
}
|
||||
if ($copy) {
|
||||
$edits[] = new DiffOpCopy($copy);
|
||||
}
|
||||
// Find deletes & adds.
|
||||
$delete = array();
|
||||
while ($xi < $n_from && $this->xchanged[$xi]) {
|
||||
$delete[] = $from_lines[$xi++];
|
||||
}
|
||||
$add = array();
|
||||
while ($yi < $n_to && $this->ychanged[$yi]) {
|
||||
$add[] = $to_lines[$yi++];
|
||||
}
|
||||
if ($delete && $add) {
|
||||
$edits[] = new DiffOpChange($delete, $add);
|
||||
}
|
||||
elseif ($delete) {
|
||||
$edits[] = new DiffOpDelete($delete);
|
||||
}
|
||||
elseif ($add) {
|
||||
$edits[] = new DiffOpAdd($add);
|
||||
}
|
||||
}
|
||||
return $edits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the whole line if it's small enough, or the MD5 hash otherwise.
|
||||
*/
|
||||
protected function _line_hash($line) {
|
||||
if (Unicode::strlen($line) > $this::MAX_XREF_LENGTH) {
|
||||
return md5($line);
|
||||
}
|
||||
else {
|
||||
return $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Divide the Largest Common Subsequence (LCS) of the sequences
|
||||
* [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
|
||||
* sized segments.
|
||||
*
|
||||
* Returns (LCS, PTS). LCS is the length of the LCS. PTS is an
|
||||
* array of NCHUNKS+1 (X, Y) indexes giving the diving points between
|
||||
* sub sequences. The first sub-sequence is contained in [X0, X1),
|
||||
* [Y0, Y1), the second in [X1, X2), [Y1, Y2) and so on. Note
|
||||
* that (X0, Y0) == (XOFF, YOFF) and
|
||||
* (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
|
||||
*
|
||||
* This function assumes that the first lines of the specified portions
|
||||
* of the two files do not match, and likewise that the last lines do not
|
||||
* match. The caller must trim matching lines from the beginning and end
|
||||
* of the portions it is going to specify.
|
||||
*/
|
||||
protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) {
|
||||
$flip = FALSE;
|
||||
|
||||
if ($xlim - $xoff > $ylim - $yoff) {
|
||||
// Things seems faster (I'm not sure I understand why)
|
||||
// when the shortest sequence in X.
|
||||
$flip = TRUE;
|
||||
list($xoff, $xlim, $yoff, $ylim) = array($yoff, $ylim, $xoff, $xlim);
|
||||
}
|
||||
|
||||
if ($flip) {
|
||||
for ($i = $ylim - 1; $i >= $yoff; $i--) {
|
||||
$ymatches[$this->xv[$i]][] = $i;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for ($i = $ylim - 1; $i >= $yoff; $i--) {
|
||||
$ymatches[$this->yv[$i]][] = $i;
|
||||
}
|
||||
}
|
||||
$this->lcs = 0;
|
||||
$this->seq[0] = $yoff - 1;
|
||||
$this->in_seq = array();
|
||||
$ymids[0] = array();
|
||||
|
||||
$numer = $xlim - $xoff + $nchunks - 1;
|
||||
$x = $xoff;
|
||||
for ($chunk = 0; $chunk < $nchunks; $chunk++) {
|
||||
if ($chunk > 0) {
|
||||
for ($i = 0; $i <= $this->lcs; $i++) {
|
||||
$ymids[$i][$chunk - 1] = $this->seq[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $chunk) / $nchunks);
|
||||
for ( ; $x < $x1; $x++) {
|
||||
$line = $flip ? $this->yv[$x] : $this->xv[$x];
|
||||
if (empty($ymatches[$line])) {
|
||||
continue;
|
||||
}
|
||||
$matches = $ymatches[$line];
|
||||
reset($matches);
|
||||
while (list ($junk, $y) = each($matches)) {
|
||||
if (empty($this->in_seq[$y])) {
|
||||
$k = $this->_lcs_pos($y);
|
||||
$this::USE_ASSERTS && assert($k > 0);
|
||||
$ymids[$k] = $ymids[$k - 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (list ($junk, $y) = each($matches)) {
|
||||
if ($y > $this->seq[$k - 1]) {
|
||||
$this::USE_ASSERTS && assert($y < $this->seq[$k]);
|
||||
// Optimization: this is a common case:
|
||||
// next match is just replacing previous match.
|
||||
$this->in_seq[$this->seq[$k]] = FALSE;
|
||||
$this->seq[$k] = $y;
|
||||
$this->in_seq[$y] = 1;
|
||||
}
|
||||
elseif (empty($this->in_seq[$y])) {
|
||||
$k = $this->_lcs_pos($y);
|
||||
$this::USE_ASSERTS && assert($k > 0);
|
||||
$ymids[$k] = $ymids[$k - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
|
||||
$ymid = $ymids[$this->lcs];
|
||||
for ($n = 0; $n < $nchunks - 1; $n++) {
|
||||
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
|
||||
$y1 = $ymid[$n] + 1;
|
||||
$seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
|
||||
}
|
||||
$seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
|
||||
|
||||
return array($this->lcs, $seps);
|
||||
}
|
||||
|
||||
protected function _lcs_pos($ypos) {
|
||||
|
||||
$end = $this->lcs;
|
||||
if ($end == 0 || $ypos > $this->seq[$end]) {
|
||||
$this->seq[++$this->lcs] = $ypos;
|
||||
$this->in_seq[$ypos] = 1;
|
||||
return $this->lcs;
|
||||
}
|
||||
|
||||
$beg = 1;
|
||||
while ($beg < $end) {
|
||||
$mid = (int)(($beg + $end) / 2);
|
||||
if ($ypos > $this->seq[$mid]) {
|
||||
$beg = $mid + 1;
|
||||
}
|
||||
else {
|
||||
$end = $mid;
|
||||
}
|
||||
}
|
||||
|
||||
$this::USE_ASSERTS && assert($ypos != $this->seq[$end]);
|
||||
|
||||
$this->in_seq[$this->seq[$end]] = FALSE;
|
||||
$this->seq[$end] = $ypos;
|
||||
$this->in_seq[$ypos] = 1;
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find LCS of two sequences.
|
||||
*
|
||||
* The results are recorded in the vectors $this->{x,y}changed[], by
|
||||
* storing a 1 in the element for each line that is an insertion
|
||||
* or deletion (ie. is not in the LCS).
|
||||
*
|
||||
* The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
|
||||
*
|
||||
* Note that XLIM, YLIM are exclusive bounds.
|
||||
* All line numbers are origin-0 and discarded lines are not counted.
|
||||
*/
|
||||
protected function _compareseq($xoff, $xlim, $yoff, $ylim) {
|
||||
|
||||
// Slide down the bottom initial diagonal.
|
||||
while ($xoff < $xlim && $yoff < $ylim && $this->xv[$xoff] == $this->yv[$yoff]) {
|
||||
++$xoff;
|
||||
++$yoff;
|
||||
}
|
||||
|
||||
// Slide up the top initial diagonal.
|
||||
while ($xlim > $xoff && $ylim > $yoff && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
|
||||
--$xlim;
|
||||
--$ylim;
|
||||
}
|
||||
|
||||
if ($xoff == $xlim || $yoff == $ylim) {
|
||||
$lcs = 0;
|
||||
}
|
||||
else {
|
||||
// This is ad hoc but seems to work well.
|
||||
//$nchunks = sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5);
|
||||
//$nchunks = max(2, min(8, (int)$nchunks));
|
||||
$nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1;
|
||||
list($lcs, $seps)
|
||||
= $this->_diag($xoff, $xlim, $yoff, $ylim, $nchunks);
|
||||
}
|
||||
|
||||
if ($lcs == 0) {
|
||||
// X and Y sequences have no common subsequence:
|
||||
// mark all changed.
|
||||
while ($yoff < $ylim) {
|
||||
$this->ychanged[$this->yind[$yoff++]] = 1;
|
||||
}
|
||||
while ($xoff < $xlim) {
|
||||
$this->xchanged[$this->xind[$xoff++]] = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Use the partitions to split this problem into subproblems.
|
||||
reset($seps);
|
||||
$pt1 = $seps[0];
|
||||
while ($pt2 = next($seps)) {
|
||||
$this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
|
||||
$pt1 = $pt2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust inserts/deletes of identical lines to join changes
|
||||
* as much as possible.
|
||||
*
|
||||
* We do something when a run of changed lines include a
|
||||
* line at one end and has an excluded, identical line at the other.
|
||||
* We are free to choose which identical line is included.
|
||||
* `compareseq' usually chooses the one at the beginning,
|
||||
* but usually it is cleaner to consider the following identical line
|
||||
* to be the "change".
|
||||
*
|
||||
* This is extracted verbatim from analyze.c (GNU diffutils-2.7).
|
||||
*/
|
||||
protected function _shift_boundaries($lines, &$changed, $other_changed) {
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
$this::USE_ASSERTS && assert('sizeof($lines) == sizeof($changed)');
|
||||
$len = sizeof($lines);
|
||||
$other_len = sizeof($other_changed);
|
||||
|
||||
while (1) {
|
||||
/*
|
||||
* Scan forwards to find beginning of another run of changes.
|
||||
* Also keep track of the corresponding point in the other file.
|
||||
*
|
||||
* Throughout this code, $i and $j are adjusted together so that
|
||||
* the first $i elements of $changed and the first $j elements
|
||||
* of $other_changed both contain the same number of zeros
|
||||
* (unchanged lines).
|
||||
* Furthermore, $j is always kept so that $j == $other_len or
|
||||
* $other_changed[$j] == FALSE.
|
||||
*/
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
while ($i < $len && !$changed[$i]) {
|
||||
$this::USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
|
||||
$i++;
|
||||
$j++;
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i == $len) {
|
||||
break;
|
||||
}
|
||||
$start = $i;
|
||||
|
||||
// Find the end of this run of changes.
|
||||
while (++$i < $len && $changed[$i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
/*
|
||||
* Record the length of this run of changes, so that
|
||||
* we can later determine whether the run has grown.
|
||||
*/
|
||||
$runlength = $i - $start;
|
||||
|
||||
/*
|
||||
* Move the changed region back, so long as the
|
||||
* previous unchanged line matches the last changed one.
|
||||
* This merges with previous changed regions.
|
||||
*/
|
||||
while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) {
|
||||
$changed[--$start] = 1;
|
||||
$changed[--$i] = FALSE;
|
||||
while ($start > 0 && $changed[$start - 1]) {
|
||||
$start--;
|
||||
}
|
||||
$this::USE_ASSERTS && assert('$j > 0');
|
||||
while ($other_changed[--$j]) {
|
||||
continue;
|
||||
}
|
||||
$this::USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
|
||||
}
|
||||
|
||||
/*
|
||||
* Set CORRESPONDING to the end of the changed run, at the last
|
||||
* point where it corresponds to a changed run in the other file.
|
||||
* CORRESPONDING == LEN means no such point has been found.
|
||||
*/
|
||||
$corresponding = $j < $other_len ? $i : $len;
|
||||
|
||||
/*
|
||||
* Move the changed region forward, so long as the
|
||||
* first changed line matches the following unchanged one.
|
||||
* This merges with following changed regions.
|
||||
* Do this second, so that if there are no merges,
|
||||
* the changed region is moved forward as far as possible.
|
||||
*/
|
||||
while ($i < $len && $lines[$start] == $lines[$i]) {
|
||||
$changed[$start++] = FALSE;
|
||||
$changed[$i++] = 1;
|
||||
while ($i < $len && $changed[$i]) {
|
||||
$i++;
|
||||
}
|
||||
$this::USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
|
||||
$j++;
|
||||
if ($j < $other_len && $other_changed[$j]) {
|
||||
$corresponding = $i;
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ($runlength != $i - $start);
|
||||
|
||||
/*
|
||||
* If possible, move the fully-merged run of changes
|
||||
* back to a corresponding run in the other file.
|
||||
*/
|
||||
while ($corresponding < $i) {
|
||||
$changed[--$start] = 1;
|
||||
$changed[--$i] = 0;
|
||||
$this::USE_ASSERTS && assert('$j > 0');
|
||||
while ($other_changed[--$j]) {
|
||||
continue;
|
||||
}
|
||||
$this::USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
27
web/core/lib/Drupal/Component/Diff/Engine/DiffOp.php
Normal file
27
web/core/lib/Drupal/Component/Diff/Engine/DiffOp.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffOp {
|
||||
public $type;
|
||||
public $orig;
|
||||
public $closing;
|
||||
|
||||
public function reverse() {
|
||||
trigger_error('pure virtual', E_USER_ERROR);
|
||||
}
|
||||
|
||||
public function norig() {
|
||||
return $this->orig ? sizeof($this->orig) : 0;
|
||||
}
|
||||
|
||||
public function nclosing() {
|
||||
return $this->closing ? sizeof($this->closing) : 0;
|
||||
}
|
||||
|
||||
}
|
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpAdd.php
Normal file
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpAdd.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffOpAdd extends DiffOp {
|
||||
public $type = 'add';
|
||||
|
||||
public function __construct($lines) {
|
||||
$this->closing = $lines;
|
||||
$this->orig = FALSE;
|
||||
}
|
||||
|
||||
public function reverse() {
|
||||
return new DiffOpDelete($this->closing);
|
||||
}
|
||||
|
||||
}
|
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpChange.php
Normal file
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpChange.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffOpChange extends DiffOp {
|
||||
public $type = 'change';
|
||||
|
||||
public function __construct($orig, $closing) {
|
||||
$this->orig = $orig;
|
||||
$this->closing = $closing;
|
||||
}
|
||||
|
||||
public function reverse() {
|
||||
return new DiffOpChange($this->closing, $this->orig);
|
||||
}
|
||||
|
||||
}
|
25
web/core/lib/Drupal/Component/Diff/Engine/DiffOpCopy.php
Normal file
25
web/core/lib/Drupal/Component/Diff/Engine/DiffOpCopy.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffOpCopy extends DiffOp {
|
||||
public $type = 'copy';
|
||||
|
||||
public function __construct($orig, $closing = FALSE) {
|
||||
if (!is_array($closing)) {
|
||||
$closing = $orig;
|
||||
}
|
||||
$this->orig = $orig;
|
||||
$this->closing = $closing;
|
||||
}
|
||||
|
||||
public function reverse() {
|
||||
return new DiffOpCopy($this->closing, $this->orig);
|
||||
}
|
||||
|
||||
}
|
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpDelete.php
Normal file
22
web/core/lib/Drupal/Component/Diff/Engine/DiffOpDelete.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class DiffOpDelete extends DiffOp {
|
||||
public $type = 'delete';
|
||||
|
||||
public function __construct($lines) {
|
||||
$this->orig = $lines;
|
||||
$this->closing = FALSE;
|
||||
}
|
||||
|
||||
public function reverse() {
|
||||
return new DiffOpAdd($this->orig);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff\Engine;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class HWLDFWordAccumulator {
|
||||
|
||||
/**
|
||||
* An iso-8859-x non-breaking space.
|
||||
*/
|
||||
const NBSP = ' ';
|
||||
|
||||
protected $lines = array();
|
||||
|
||||
protected $line = '';
|
||||
|
||||
protected $group = '';
|
||||
|
||||
protected $tag = '';
|
||||
|
||||
protected function _flushGroup($new_tag) {
|
||||
if ($this->group !== '') {
|
||||
if ($this->tag == 'mark') {
|
||||
$this->line = $this->line . '<span class="diffchange">' . $this->group . '</span>';
|
||||
}
|
||||
else {
|
||||
$this->line = $this->line . $this->group;
|
||||
}
|
||||
}
|
||||
$this->group = '';
|
||||
$this->tag = $new_tag;
|
||||
}
|
||||
|
||||
protected function _flushLine($new_tag) {
|
||||
$this->_flushGroup($new_tag);
|
||||
if ($this->line != '') {
|
||||
array_push($this->lines, $this->line);
|
||||
}
|
||||
else {
|
||||
// make empty lines visible by inserting an NBSP
|
||||
array_push($this->lines, $this::NBSP);
|
||||
}
|
||||
$this->line = '';
|
||||
}
|
||||
|
||||
public function addWords($words, $tag = '') {
|
||||
if ($tag != $this->tag) {
|
||||
$this->_flushGroup($tag);
|
||||
}
|
||||
foreach ($words as $word) {
|
||||
// new-line should only come as first char of word.
|
||||
if ($word == '') {
|
||||
continue;
|
||||
}
|
||||
if ($word[0] == "\n") {
|
||||
$this->_flushLine($tag);
|
||||
$word = Unicode::substr($word, 1);
|
||||
}
|
||||
assert(!strstr($word, "\n"));
|
||||
$this->group .= $word;
|
||||
}
|
||||
}
|
||||
|
||||
public function getLines() {
|
||||
$this->_flushLine('~done');
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Diff/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Diff/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
56
web/core/lib/Drupal/Component/Diff/MappedDiff.php
Normal file
56
web/core/lib/Drupal/Component/Diff/MappedDiff.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff;
|
||||
|
||||
/**
|
||||
* FIXME: bad name.
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class MappedDiff extends Diff {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Computes diff between sequences of strings.
|
||||
*
|
||||
* This can be used to compute things like
|
||||
* case-insensitive diffs, or diffs which ignore
|
||||
* changes in white-space.
|
||||
*
|
||||
* @param $from_lines array An array of strings.
|
||||
* (Typically these are lines from a file.)
|
||||
* @param $to_lines array An array of strings.
|
||||
* @param $mapped_from_lines array This array should
|
||||
* have the same size number of elements as $from_lines.
|
||||
* The elements in $mapped_from_lines and
|
||||
* $mapped_to_lines are what is actually compared
|
||||
* when computing the diff.
|
||||
* @param $mapped_to_lines array This array should
|
||||
* have the same number of elements as $to_lines.
|
||||
*/
|
||||
public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines) {
|
||||
|
||||
assert(sizeof($from_lines) == sizeof($mapped_from_lines));
|
||||
assert(sizeof($to_lines) == sizeof($mapped_to_lines));
|
||||
|
||||
parent::__construct($mapped_from_lines, $mapped_to_lines);
|
||||
|
||||
$xi = $yi = 0;
|
||||
for ($i = 0; $i < sizeof($this->edits); $i++) {
|
||||
$orig = &$this->edits[$i]->orig;
|
||||
if (is_array($orig)) {
|
||||
$orig = array_slice($from_lines, $xi, sizeof($orig));
|
||||
$xi += sizeof($orig);
|
||||
}
|
||||
|
||||
$closing = &$this->edits[$i]->closing;
|
||||
if (is_array($closing)) {
|
||||
$closing = array_slice($to_lines, $yi, sizeof($closing));
|
||||
$yi += sizeof($closing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
web/core/lib/Drupal/Component/Diff/README.txt
Normal file
12
web/core/lib/Drupal/Component/Diff/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Diff Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Diff/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Diff/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Diff
|
82
web/core/lib/Drupal/Component/Diff/WordLevelDiff.php
Normal file
82
web/core/lib/Drupal/Component/Diff/WordLevelDiff.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Diff;
|
||||
|
||||
use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* @todo document
|
||||
* @private
|
||||
* @subpackage DifferenceEngine
|
||||
*/
|
||||
class WordLevelDiff extends MappedDiff {
|
||||
|
||||
const MAX_LINE_LENGTH = 10000;
|
||||
|
||||
public function __construct($orig_lines, $closing_lines) {
|
||||
list($orig_words, $orig_stripped) = $this->_split($orig_lines);
|
||||
list($closing_words, $closing_stripped) = $this->_split($closing_lines);
|
||||
|
||||
parent::__construct($orig_words, $closing_words, $orig_stripped, $closing_stripped);
|
||||
}
|
||||
|
||||
protected function _split($lines) {
|
||||
$words = array();
|
||||
$stripped = array();
|
||||
$first = TRUE;
|
||||
foreach ($lines as $line) {
|
||||
// If the line is too long, just pretend the entire line is one big word
|
||||
// This prevents resource exhaustion problems
|
||||
if ( $first ) {
|
||||
$first = FALSE;
|
||||
}
|
||||
else {
|
||||
$words[] = "\n";
|
||||
$stripped[] = "\n";
|
||||
}
|
||||
if (Unicode::strlen($line) > $this::MAX_LINE_LENGTH) {
|
||||
$words[] = $line;
|
||||
$stripped[] = $line;
|
||||
}
|
||||
else {
|
||||
if (preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs', $line, $m)) {
|
||||
$words = array_merge($words, $m[0]);
|
||||
$stripped = array_merge($stripped, $m[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array($words, $stripped);
|
||||
}
|
||||
|
||||
public function orig() {
|
||||
$orig = new HWLDFWordAccumulator();
|
||||
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->type == 'copy') {
|
||||
$orig->addWords($edit->orig);
|
||||
}
|
||||
elseif ($edit->orig) {
|
||||
$orig->addWords($edit->orig, 'mark');
|
||||
}
|
||||
}
|
||||
$lines = $orig->getLines();
|
||||
return $lines;
|
||||
}
|
||||
|
||||
public function closing() {
|
||||
$closing = new HWLDFWordAccumulator();
|
||||
|
||||
foreach ($this->edits as $edit) {
|
||||
if ($edit->type == 'copy') {
|
||||
$closing->addWords($edit->closing);
|
||||
}
|
||||
elseif ($edit->closing) {
|
||||
$closing->addWords($edit->closing, 'mark');
|
||||
}
|
||||
}
|
||||
$lines = $closing->getLines();
|
||||
return $lines;
|
||||
}
|
||||
|
||||
}
|
16
web/core/lib/Drupal/Component/Diff/composer.json
Normal file
16
web/core/lib/Drupal/Component/Diff/composer.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "drupal/core-diff",
|
||||
"description": "Diff.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"drupal/utility": "~8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Diff\\": ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Discovery;
|
||||
|
||||
/**
|
||||
* Interface for classes providing a type of discovery.
|
||||
*/
|
||||
interface DiscoverableInterface {
|
||||
|
||||
/**
|
||||
* Returns an array of discoverable items.
|
||||
*
|
||||
* @return array
|
||||
* An array of discovered data keyed by provider.
|
||||
*
|
||||
* @throws \Drupal\Component\Discovery\DiscoveryException
|
||||
* Exception thrown if there is a problem during discovery.
|
||||
*/
|
||||
public function findAll();
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Discovery;
|
||||
|
||||
/**
|
||||
* Exception thrown during discovery if the data is invalid.
|
||||
*/
|
||||
class DiscoveryException extends \RuntimeException {
|
||||
}
|
339
web/core/lib/Drupal/Component/Discovery/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Discovery/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/Discovery/README.txt
Normal file
12
web/core/lib/Drupal/Component/Discovery/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Discovery Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Discovery/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Discovery/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Discovery
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Discovery;
|
||||
|
||||
use Drupal\Component\FileSystem\RegexDirectoryIterator;
|
||||
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
|
||||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
|
||||
/**
|
||||
* Discovers multiple YAML files in a set of directories.
|
||||
*/
|
||||
class YamlDirectoryDiscovery implements DiscoverableInterface {
|
||||
|
||||
/**
|
||||
* Defines the key in the discovered data where the file path is stored.
|
||||
*/
|
||||
const FILE_KEY = '_discovered_file_path';
|
||||
|
||||
/**
|
||||
* An array of directories to scan, keyed by the provider.
|
||||
*
|
||||
* The value can either be a string or an array of strings. The string values
|
||||
* should be the path of a directory to scan.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $directories = [];
|
||||
|
||||
/**
|
||||
* The suffix for the file cache key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fileCacheKeySuffix;
|
||||
|
||||
/**
|
||||
* The key contained in the discovered data that identifies it.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $idKey;
|
||||
|
||||
/**
|
||||
* Constructs a YamlDirectoryDiscovery object.
|
||||
*
|
||||
* @param array $directories
|
||||
* An array of directories to scan, keyed by the provider. The value can
|
||||
* either be a string or an array of strings. The string values should be
|
||||
* the path of a directory to scan.
|
||||
* @param string $file_cache_key_suffix
|
||||
* The file cache key suffix. This should be unique for each type of
|
||||
* discovery.
|
||||
* @param string $key
|
||||
* (optional) The key contained in the discovered data that identifies it.
|
||||
* Defaults to 'id'.
|
||||
*/
|
||||
public function __construct(array $directories, $file_cache_key_suffix, $key = 'id') {
|
||||
$this->directories = $directories;
|
||||
$this->fileCacheKeySuffix = $file_cache_key_suffix;
|
||||
$this->idKey = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findAll() {
|
||||
$all = array();
|
||||
|
||||
$files = $this->findFiles();
|
||||
|
||||
$file_cache = FileCacheFactory::get('yaml_discovery:' . $this->fileCacheKeySuffix);
|
||||
|
||||
// Try to load from the file cache first.
|
||||
foreach ($file_cache->getMultiple(array_keys($files)) as $file => $data) {
|
||||
$all[$files[$file]][$this->getIdentifier($file, $data)] = $data;
|
||||
unset($files[$file]);
|
||||
}
|
||||
|
||||
// If there are files left that were not returned from the cache, load and
|
||||
// parse them now. This list was flipped above and is keyed by filename.
|
||||
if ($files) {
|
||||
foreach ($files as $file => $provider) {
|
||||
// If a file is empty or its contents are commented out, return an empty
|
||||
// array instead of NULL for type consistency.
|
||||
try {
|
||||
$data = Yaml::decode(file_get_contents($file)) ?: [];
|
||||
}
|
||||
catch (InvalidDataTypeException $e) {
|
||||
throw new DiscoveryException("The $file contains invalid YAML", 0, $e);
|
||||
}
|
||||
$data[static::FILE_KEY] = $file;
|
||||
$all[$provider][$this->getIdentifier($file, $data)] = $data;
|
||||
$file_cache->set($file, $data);
|
||||
}
|
||||
}
|
||||
|
||||
return $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier from the data.
|
||||
*
|
||||
* @param string $file
|
||||
* The filename.
|
||||
* @param array $data
|
||||
* The data from the YAML file.
|
||||
*
|
||||
* @return string
|
||||
* The identifier from the data.
|
||||
*/
|
||||
protected function getIdentifier($file, array $data) {
|
||||
if (!isset($data[$this->idKey])) {
|
||||
throw new DiscoveryException("The $file contains no data in the identifier key '{$this->idKey}'");
|
||||
}
|
||||
return $data[$this->idKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of providers keyed by file path.
|
||||
*
|
||||
* @return array
|
||||
* An array of providers keyed by file path.
|
||||
*/
|
||||
protected function findFiles() {
|
||||
$file_list = [];
|
||||
foreach ($this->directories as $provider => $directories) {
|
||||
$directories = (array) $directories;
|
||||
foreach ($directories as $directory) {
|
||||
if (is_dir($directory)) {
|
||||
/** @var \SplFileInfo $fileInfo */
|
||||
foreach ($this->getDirectoryIterator($directory) as $fileInfo) {
|
||||
$file_list[$fileInfo->getPathname()] = $provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $file_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an iterator to loop over the files in the provided directory.
|
||||
*
|
||||
* This method exists so that it is easy to replace this functionality in a
|
||||
* class that extends this one. For example, it could be used to make the scan
|
||||
* recursive.
|
||||
*
|
||||
* @param string $directory
|
||||
* The directory to scan.
|
||||
*
|
||||
* @return \Traversable
|
||||
* An \Traversable object or array where the values are \SplFileInfo
|
||||
* objects.
|
||||
*/
|
||||
protected function getDirectoryIterator($directory) {
|
||||
return new RegexDirectoryIterator($directory, '/\.yml$/i');
|
||||
}
|
||||
|
||||
}
|
99
web/core/lib/Drupal/Component/Discovery/YamlDiscovery.php
Normal file
99
web/core/lib/Drupal/Component/Discovery/YamlDiscovery.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Discovery;
|
||||
|
||||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\Component\FileCache\FileCacheFactory;
|
||||
|
||||
/**
|
||||
* Provides discovery for YAML files within a given set of directories.
|
||||
*/
|
||||
class YamlDiscovery implements DiscoverableInterface {
|
||||
|
||||
/**
|
||||
* The base filename to look for in each directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* An array of directories to scan, keyed by the provider.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $directories = array();
|
||||
|
||||
/**
|
||||
* Constructs a YamlDiscovery object.
|
||||
*
|
||||
* @param string $name
|
||||
* The base filename to look for in each directory. The format will be
|
||||
* $provider.$name.yml.
|
||||
* @param array $directories
|
||||
* An array of directories to scan, keyed by the provider.
|
||||
*/
|
||||
public function __construct($name, array $directories) {
|
||||
$this->name = $name;
|
||||
$this->directories = $directories;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findAll() {
|
||||
$all = array();
|
||||
|
||||
$files = $this->findFiles();
|
||||
$provider_by_files = array_flip($files);
|
||||
|
||||
$file_cache = FileCacheFactory::get('yaml_discovery:' . $this->name);
|
||||
|
||||
// Try to load from the file cache first.
|
||||
foreach ($file_cache->getMultiple($files) as $file => $data) {
|
||||
$all[$provider_by_files[$file]] = $data;
|
||||
unset($provider_by_files[$file]);
|
||||
}
|
||||
|
||||
// If there are files left that were not returned from the cache, load and
|
||||
// parse them now. This list was flipped above and is keyed by filename.
|
||||
if ($provider_by_files) {
|
||||
foreach ($provider_by_files as $file => $provider) {
|
||||
// If a file is empty or its contents are commented out, return an empty
|
||||
// array instead of NULL for type consistency.
|
||||
$all[$provider] = $this->decode($file);
|
||||
$file_cache->set($file, $all[$provider]);
|
||||
}
|
||||
}
|
||||
|
||||
return $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a YAML file.
|
||||
*
|
||||
* @param string $file
|
||||
* Yaml file path.
|
||||
* @return array
|
||||
*/
|
||||
protected function decode($file) {
|
||||
return Yaml::decode(file_get_contents($file)) ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of file paths, keyed by provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function findFiles() {
|
||||
$files = array();
|
||||
foreach ($this->directories as $provider => $directory) {
|
||||
$file = $directory . '/' . $provider . '.' . $this->name . '.yml';
|
||||
if (file_exists($file)) {
|
||||
$files[$provider] = $file;
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
}
|
17
web/core/lib/Drupal/Component/Discovery/composer.json
Normal file
17
web/core/lib/Drupal/Component/Discovery/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "drupal/core-discovery",
|
||||
"description": "Discovery.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"drupal/core-filecache": "~8.2",
|
||||
"drupal/core-serialization": "~8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Discovery\\": ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,262 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\EventDispatcher;
|
||||
|
||||
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* A performance optimized container aware event dispatcher.
|
||||
*
|
||||
* This version of the event dispatcher contains the following optimizations
|
||||
* in comparison to the Symfony event dispatcher component:
|
||||
*
|
||||
* <dl>
|
||||
* <dt>Faster instantiation of the event dispatcher service</dt>
|
||||
* <dd>
|
||||
* Instead of calling <code>addSubscriberService</code> once for each
|
||||
* subscriber, a precompiled array of listener definitions is passed
|
||||
* directly to the constructor. This is faster by roughly an order of
|
||||
* magnitude. The listeners are collected and prepared using a compiler
|
||||
* pass.
|
||||
* </dd>
|
||||
* <dt>Lazy instantiation of listeners</dt>
|
||||
* <dd>
|
||||
* Services are only retrieved from the container just before invocation.
|
||||
* Especially when dispatching the KernelEvents::REQUEST event, this leads
|
||||
* to a more timely invocation of the first listener. Overall dispatch
|
||||
* runtime is not affected by this change though.
|
||||
* </dd>
|
||||
* </dl>
|
||||
*/
|
||||
class ContainerAwareEventDispatcher implements EventDispatcherInterface {
|
||||
|
||||
/**
|
||||
* The service container.
|
||||
*
|
||||
* @var \Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* Listener definitions.
|
||||
*
|
||||
* A nested array of listener definitions keyed by event name and priority.
|
||||
* A listener definition is an associative array with one of the following key
|
||||
* value pairs:
|
||||
* - callable: A callable listener
|
||||
* - service: An array of the form [service id, method]
|
||||
*
|
||||
* A service entry will be resolved to a callable only just before its
|
||||
* invocation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listeners;
|
||||
|
||||
/**
|
||||
* Whether listeners need to be sorted prior to dispatch, keyed by event name.
|
||||
*
|
||||
* @var TRUE[]
|
||||
*/
|
||||
protected $unsorted;
|
||||
|
||||
/**
|
||||
* Constructs a container aware event dispatcher.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\IntrospectableContainerInterface $container
|
||||
* The service container.
|
||||
* @param array $listeners
|
||||
* A nested array of listener definitions keyed by event name and priority.
|
||||
* The array is expected to be ordered by priority. A listener definition is
|
||||
* an associative array with one of the following key value pairs:
|
||||
* - callable: A callable listener
|
||||
* - service: An array of the form [service id, method]
|
||||
* A service entry will be resolved to a callable only just before its
|
||||
* invocation.
|
||||
*/
|
||||
public function __construct(IntrospectableContainerInterface $container, array $listeners = []) {
|
||||
$this->container = $container;
|
||||
$this->listeners = $listeners;
|
||||
$this->unsorted = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch($event_name, Event $event = NULL) {
|
||||
if ($event === NULL) {
|
||||
$event = new Event();
|
||||
}
|
||||
|
||||
$event->setDispatcher($this);
|
||||
$event->setName($event_name);
|
||||
|
||||
if (isset($this->listeners[$event_name])) {
|
||||
// Sort listeners if necessary.
|
||||
if (isset($this->unsorted[$event_name])) {
|
||||
krsort($this->listeners[$event_name]);
|
||||
unset($this->unsorted[$event_name]);
|
||||
}
|
||||
|
||||
// Invoke listeners and resolve callables if necessary.
|
||||
foreach ($this->listeners[$event_name] as $priority => &$definitions) {
|
||||
foreach ($definitions as $key => &$definition) {
|
||||
if (!isset($definition['callable'])) {
|
||||
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
|
||||
}
|
||||
|
||||
$definition['callable']($event, $event_name, $this);
|
||||
if ($event->isPropagationStopped()) {
|
||||
return $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListeners($event_name = NULL) {
|
||||
$result = [];
|
||||
|
||||
if ($event_name === NULL) {
|
||||
// If event name was omitted, collect all listeners of all events.
|
||||
foreach (array_keys($this->listeners) as $event_name) {
|
||||
$listeners = $this->getListeners($event_name);
|
||||
if (!empty($listeners)) {
|
||||
$result[$event_name] = $listeners;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (isset($this->listeners[$event_name])) {
|
||||
// Sort listeners if necessary.
|
||||
if (isset($this->unsorted[$event_name])) {
|
||||
krsort($this->listeners[$event_name]);
|
||||
unset($this->unsorted[$event_name]);
|
||||
}
|
||||
|
||||
// Collect listeners and resolve callables if necessary.
|
||||
foreach ($this->listeners[$event_name] as $priority => &$definitions) {
|
||||
foreach ($definitions as $key => &$definition) {
|
||||
if (!isset($definition['callable'])) {
|
||||
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
|
||||
}
|
||||
|
||||
$result[] = $definition['callable'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getListenerPriority($eventName, $listener) {
|
||||
// Parts copied from \Symfony\Component\EventDispatcher, that's why you see
|
||||
// a yoda condition here.
|
||||
if (!isset($this->listeners[$eventName])) {
|
||||
return;
|
||||
}
|
||||
foreach ($this->listeners[$eventName] as $priority => $listeners) {
|
||||
if (FALSE !== ($key = array_search(['callable' => $listener], $listeners, TRUE))) {
|
||||
return $priority;
|
||||
}
|
||||
}
|
||||
// Resolve service definitions if the listener has not been found so far.
|
||||
foreach ($this->listeners[$eventName] as $priority => &$definitions) {
|
||||
foreach ($definitions as $key => &$definition) {
|
||||
if (!isset($definition['callable'])) {
|
||||
// Once the callable is retrieved we keep it for subsequent method
|
||||
// invocations on this class.
|
||||
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
|
||||
if ($definition['callable'] === $listener) {
|
||||
return $priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasListeners($event_name = NULL) {
|
||||
return (bool) count($this->getListeners($event_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addListener($event_name, $listener, $priority = 0) {
|
||||
$this->listeners[$event_name][$priority][] = ['callable' => $listener];
|
||||
$this->unsorted[$event_name] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeListener($event_name, $listener) {
|
||||
if (!isset($this->listeners[$event_name])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->listeners[$event_name] as $priority => $definitions) {
|
||||
foreach ($definitions as $key => $definition) {
|
||||
if (!isset($definition['callable'])) {
|
||||
if (!$this->container->initialized($definition['service'][0])) {
|
||||
continue;
|
||||
}
|
||||
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
|
||||
}
|
||||
|
||||
if ($definition['callable'] === $listener) {
|
||||
unset($this->listeners[$event_name][$priority][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addSubscriber(EventSubscriberInterface $subscriber) {
|
||||
foreach ($subscriber->getSubscribedEvents() as $event_name => $params) {
|
||||
if (is_string($params)) {
|
||||
$this->addListener($event_name, array($subscriber, $params));
|
||||
}
|
||||
elseif (is_string($params[0])) {
|
||||
$this->addListener($event_name, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
|
||||
}
|
||||
else {
|
||||
foreach ($params as $listener) {
|
||||
$this->addListener($event_name, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeSubscriber(EventSubscriberInterface $subscriber) {
|
||||
foreach ($subscriber->getSubscribedEvents() as $event_name => $params) {
|
||||
if (is_array($params) && is_array($params[0])) {
|
||||
foreach ($params as $listener) {
|
||||
$this->removeListener($event_name, array($subscriber, $listener[0]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->removeListener($event_name, array($subscriber, is_string($params) ? $params : $params[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/EventDispatcher/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/EventDispatcher/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/EventDispatcher/README.txt
Normal file
12
web/core/lib/Drupal/Component/EventDispatcher/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal EventDispatcher Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/EventDispatcher/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/EventDispatcher/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group EventDispatcher
|
17
web/core/lib/Drupal/Component/EventDispatcher/composer.json
Normal file
17
web/core/lib/Drupal/Component/EventDispatcher/composer.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "drupal/core-event-dispatcher",
|
||||
"description": "EventDispatcher.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"symfony/dependency-injection": "~2.8",
|
||||
"symfony/event-dispatcher": "~2.7"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\EventDispatcher\\": ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* APCu backend for the file cache.
|
||||
*/
|
||||
class ApcuFileCacheBackend implements FileCacheBackendInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fetch(array $cids) {
|
||||
return apcu_fetch($cids);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function store($cid, $data) {
|
||||
apcu_store($cid, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
apcu_delete($cid);
|
||||
}
|
||||
|
||||
}
|
160
web/core/lib/Drupal/Component/FileCache/FileCache.php
Normal file
160
web/core/lib/Drupal/Component/FileCache/FileCache.php
Normal file
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* Allows to cache data based on file modification dates.
|
||||
*/
|
||||
class FileCache implements FileCacheInterface {
|
||||
|
||||
/**
|
||||
* Prefix that is used for cache entries.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $prefix;
|
||||
|
||||
/**
|
||||
* Static cache that contains already loaded cache entries.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $cached = [];
|
||||
|
||||
/**
|
||||
* The collection identifier of this cache.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
* The cache backend backing this FileCache object.
|
||||
*
|
||||
* @var \Drupal\Component\FileCache\FileCacheBackendInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Constructs a FileCache object.
|
||||
*
|
||||
* @param string $prefix
|
||||
* The cache prefix.
|
||||
* @param string $collection
|
||||
* A collection identifier to ensure that the same files could be cached for
|
||||
* different purposes without clashing.
|
||||
* @param string|null $cache_backend_class
|
||||
* (optional) The class that should be used as cache backend.
|
||||
* @param array $cache_backend_configuration
|
||||
* (optional) The configuration for the backend class.
|
||||
*/
|
||||
public function __construct($prefix, $collection, $cache_backend_class = NULL, array $cache_backend_configuration = []) {
|
||||
|
||||
if (empty($prefix)) {
|
||||
throw new \InvalidArgumentException('Required prefix configuration is missing');
|
||||
}
|
||||
|
||||
$this->prefix = $prefix;
|
||||
$this->collection = $collection;
|
||||
|
||||
if (isset($cache_backend_class)) {
|
||||
$this->cache = new $cache_backend_class($cache_backend_configuration);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($filepath) {
|
||||
$filepaths = [$filepath];
|
||||
$cached = $this->getMultiple($filepaths);
|
||||
return isset($cached[$filepath]) ? $cached[$filepath] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(array $filepaths) {
|
||||
$file_data = [];
|
||||
$remaining_cids = [];
|
||||
|
||||
// First load from the static cache what we can.
|
||||
foreach ($filepaths as $filepath) {
|
||||
if (!file_exists($filepath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$realpath = realpath($filepath);
|
||||
// If the file exists but realpath returns nothing, it is using a stream
|
||||
// wrapper, those are not supported.
|
||||
if (empty($realpath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cid = $this->prefix . ':' . $this->collection . ':' . $realpath;
|
||||
if (isset(static::$cached[$cid]) && static::$cached[$cid]['mtime'] == filemtime($filepath)) {
|
||||
$file_data[$filepath] = static::$cached[$cid]['data'];
|
||||
}
|
||||
else {
|
||||
// Collect a list of cache IDs that we still need to fetch from cache
|
||||
// backend.
|
||||
$remaining_cids[$cid] = $filepath;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any cache IDs left to fetch from the cache backend.
|
||||
if ($remaining_cids && $this->cache) {
|
||||
$cache_results = $this->cache->fetch(array_keys($remaining_cids)) ?: [];
|
||||
foreach ($cache_results as $cid => $cached) {
|
||||
$filepath = $remaining_cids[$cid];
|
||||
if ($cached['mtime'] == filemtime($filepath)) {
|
||||
$file_data[$cached['filepath']] = $cached['data'];
|
||||
static::$cached[$cid] = $cached;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $file_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($filepath, $data) {
|
||||
$realpath = realpath($filepath);
|
||||
$cached = [
|
||||
'mtime' => filemtime($filepath),
|
||||
'filepath' => $filepath,
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
$cid = $this->prefix . ':' . $this->collection . ':' . $realpath;
|
||||
static::$cached[$cid] = $cached;
|
||||
if ($this->cache) {
|
||||
$this->cache->store($cid, $cached);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($filepath) {
|
||||
$realpath = realpath($filepath);
|
||||
$cid = $this->prefix . ':' . $this->collection . ':' . $realpath;
|
||||
|
||||
unset(static::$cached[$cid]);
|
||||
if ($this->cache) {
|
||||
$this->cache->delete($cid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the static cache.
|
||||
*
|
||||
* @todo Replace this once https://www.drupal.org/node/2260187 is in.
|
||||
*/
|
||||
public static function reset() {
|
||||
static::$cached = [];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* Defines an interface inspired by APCu for FileCache backends.
|
||||
*/
|
||||
interface FileCacheBackendInterface {
|
||||
|
||||
/**
|
||||
* Fetches data from the cache backend.
|
||||
*
|
||||
* @param array $cids
|
||||
* The cache IDs to fetch.
|
||||
*
|
||||
* @return array
|
||||
* An array containing cache entries keyed by cache ID.
|
||||
*/
|
||||
public function fetch(array $cids);
|
||||
|
||||
/**
|
||||
* Stores data into a cache backend.
|
||||
*
|
||||
* @param string $cid
|
||||
* The cache ID to store data to.
|
||||
* @param mixed $data
|
||||
* The data to store.
|
||||
*/
|
||||
public function store($cid, $data);
|
||||
|
||||
/**
|
||||
* Deletes data from a cache backend.
|
||||
*
|
||||
* @param string $cid
|
||||
* The cache ID to delete.
|
||||
*/
|
||||
public function delete($cid);
|
||||
|
||||
}
|
119
web/core/lib/Drupal/Component/FileCache/FileCacheFactory.php
Normal file
119
web/core/lib/Drupal/Component/FileCache/FileCacheFactory.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* Creates a FileCache object.
|
||||
*/
|
||||
class FileCacheFactory {
|
||||
|
||||
/**
|
||||
* The configuration key to disable FileCache completely.
|
||||
*/
|
||||
const DISABLE_CACHE = 'file_cache_disable';
|
||||
|
||||
/**
|
||||
* The configuration used to create FileCache objects.
|
||||
*
|
||||
* @var array $configuration
|
||||
*/
|
||||
protected static $configuration;
|
||||
|
||||
/**
|
||||
* The cache prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $prefix;
|
||||
|
||||
/**
|
||||
* Instantiates a FileCache object for a given collection identifier.
|
||||
*
|
||||
* @param string $collection
|
||||
* The collection identifier for this FileCache.
|
||||
* @param array $default_configuration
|
||||
* (optional) The default configuration for this FileCache collection. This
|
||||
* can be used to e.g. specify default usage of a FileCache class.
|
||||
*
|
||||
* @return \Drupal\Component\FileCache\FileCacheInterface
|
||||
* The initialized FileCache object.
|
||||
*/
|
||||
public static function get($collection, $default_configuration = []) {
|
||||
// If there is a special key in the configuration, disable FileCache completely.
|
||||
if (!empty(static::$configuration[static::DISABLE_CACHE])) {
|
||||
return new NullFileCache('', '');
|
||||
}
|
||||
|
||||
$configuration = [];
|
||||
|
||||
// Check for a collection specific setting first.
|
||||
if (isset(static::$configuration[$collection])) {
|
||||
$configuration += static::$configuration[$collection];
|
||||
}
|
||||
// Then check if a default configuration has been provided.
|
||||
if (!empty($default_configuration)) {
|
||||
$configuration += $default_configuration;
|
||||
}
|
||||
// Last check if a default setting has been provided.
|
||||
if (isset(static::$configuration['default'])) {
|
||||
$configuration += static::$configuration['default'];
|
||||
}
|
||||
|
||||
// Ensure that all properties are set.
|
||||
$fallback_configuration = [
|
||||
'class' => '\Drupal\Component\FileCache\FileCache',
|
||||
'collection' => $collection,
|
||||
'cache_backend_class' => NULL,
|
||||
'cache_backend_configuration' => [],
|
||||
];
|
||||
|
||||
$configuration = $configuration + $fallback_configuration;
|
||||
|
||||
$class = $configuration['class'];
|
||||
return new $class(static::getPrefix(), $configuration['collection'], $configuration['cache_backend_class'], $configuration['cache_backend_configuration']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration used for constructing future file cache objects.
|
||||
*
|
||||
* @return array
|
||||
* The configuration that is used.
|
||||
*/
|
||||
public static function getConfiguration() {
|
||||
return static::$configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration to use for constructing future file cache objects.
|
||||
*
|
||||
* @param array $configuration
|
||||
* The configuration to use.
|
||||
*/
|
||||
public static function setConfiguration($configuration) {
|
||||
static::$configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cache prefix.
|
||||
*
|
||||
* @return string
|
||||
* The cache prefix.
|
||||
*/
|
||||
public static function getPrefix() {
|
||||
return static::$prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cache prefix that should be used.
|
||||
*
|
||||
* Should be set to a secure, unique key to prevent cache pollution by a
|
||||
* third party.
|
||||
*
|
||||
* @param string $prefix
|
||||
* The cache prefix.
|
||||
*/
|
||||
public static function setPrefix($prefix) {
|
||||
static::$prefix = $prefix;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* Interface for objects that allow caching file data.
|
||||
*
|
||||
* Parsing YAML, annotations or similar data out of files can be a
|
||||
* time-consuming process, especially since those files usually don't change
|
||||
* and identical data is parsed over and over again.
|
||||
*
|
||||
* File cache is a self-contained caching layer for such processing, that relies
|
||||
* on the file modification to ensure that cached data is still up to date and
|
||||
* does not need to be invalidated externally.
|
||||
*/
|
||||
interface FileCacheInterface {
|
||||
|
||||
/**
|
||||
* Gets data based on a filename.
|
||||
*
|
||||
* @param string $filepath
|
||||
* Path of the file that the cached data is based on.
|
||||
*
|
||||
* @return mixed|null
|
||||
* The data that was persisted with set() or NULL if there is no data
|
||||
* or the file has been modified.
|
||||
*/
|
||||
public function get($filepath);
|
||||
|
||||
/**
|
||||
* Gets data based on filenames.
|
||||
*
|
||||
* @param string[] $filepaths
|
||||
* List of file paths used as cache identifiers.
|
||||
*
|
||||
* @return array
|
||||
* List of cached data keyed by the passed in file paths.
|
||||
*/
|
||||
public function getMultiple(array $filepaths);
|
||||
|
||||
/**
|
||||
* Stores data based on a filename.
|
||||
*
|
||||
* @param string $filepath
|
||||
* Path of the file that the cached data is based on.
|
||||
* @param mixed $data
|
||||
* The data that should be cached.
|
||||
*/
|
||||
public function set($filepath, $data);
|
||||
|
||||
/**
|
||||
* Deletes data from the cache.
|
||||
*
|
||||
* @param string $filepath
|
||||
* Path of the file that the cached data is based on.
|
||||
*/
|
||||
public function delete($filepath);
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/FileCache/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/FileCache/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
53
web/core/lib/Drupal/Component/FileCache/NullFileCache.php
Normal file
53
web/core/lib/Drupal/Component/FileCache/NullFileCache.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileCache;
|
||||
|
||||
/**
|
||||
* Null implementation for the file cache.
|
||||
*/
|
||||
class NullFileCache implements FileCacheInterface {
|
||||
|
||||
/**
|
||||
* Constructs a FileCache object.
|
||||
*
|
||||
* @param string $prefix
|
||||
* A prefix that is used as a prefix, should be set to a secure, unique key
|
||||
* to prevent cache pollution by a third party.
|
||||
* @param string $collection
|
||||
* A collection identifier to ensure that the same files could be cached for
|
||||
* different purposes without clashing.
|
||||
* @param string|null $cache_backend_class
|
||||
* (optional) The class that should be used as cache backend.
|
||||
* @param array $cache_backend_configuration
|
||||
* (optional) The configuration for the backend class.
|
||||
*/
|
||||
public function __construct($prefix, $collection, $cache_backend_class = NULL, array $cache_backend_configuration = []) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($filepath) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(array $filepaths) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($filepath, $data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($filepath) {
|
||||
}
|
||||
|
||||
}
|
12
web/core/lib/Drupal/Component/FileCache/README.txt
Normal file
12
web/core/lib/Drupal/Component/FileCache/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal FileCache Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/FileCache/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/FileCache/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group FileCache
|
15
web/core/lib/Drupal/Component/FileCache/composer.json
Normal file
15
web/core/lib/Drupal/Component/FileCache/composer.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "drupal/core-file-cache",
|
||||
"description": "FileCache.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\FileCache\\": ""
|
||||
}
|
||||
}
|
||||
}
|
46
web/core/lib/Drupal/Component/FileSystem/FileSystem.php
Normal file
46
web/core/lib/Drupal/Component/FileSystem/FileSystem.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileSystem;
|
||||
|
||||
/**
|
||||
* Provides file system functions.
|
||||
*/
|
||||
class FileSystem {
|
||||
|
||||
/**
|
||||
* Discovers a writable system-appropriate temporary directory.
|
||||
*
|
||||
* @return string|false
|
||||
* A string containing the path to the temporary directory, or FALSE if no
|
||||
* suitable temporary directory can be found.
|
||||
*/
|
||||
public static function getOsTemporaryDirectory() {
|
||||
$directories = array();
|
||||
|
||||
// Has PHP been set with an upload_tmp_dir?
|
||||
if (ini_get('upload_tmp_dir')) {
|
||||
$directories[] = ini_get('upload_tmp_dir');
|
||||
}
|
||||
|
||||
// Operating system specific dirs.
|
||||
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
||||
$directories[] = 'c:\\windows\\temp';
|
||||
$directories[] = 'c:\\winnt\\temp';
|
||||
}
|
||||
else {
|
||||
$directories[] = '/tmp';
|
||||
}
|
||||
// PHP may be able to find an alternative tmp directory.
|
||||
$directories[] = sys_get_temp_dir();
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (is_dir($directory) && is_writable($directory)) {
|
||||
// Both sys_get_temp_dir() and ini_get('upload_tmp_dir') can return paths
|
||||
// with a trailing directory separator.
|
||||
return rtrim($directory, DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/FileSystem/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/FileSystem/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/FileSystem/README.txt
Normal file
12
web/core/lib/Drupal/Component/FileSystem/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal FileSystem Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\FileSystem;
|
||||
|
||||
/**
|
||||
* Iterates over files whose names match a regular expression in a directory.
|
||||
*/
|
||||
class RegexDirectoryIterator extends \FilterIterator {
|
||||
|
||||
/**
|
||||
* The regular expression to match.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $regex;
|
||||
|
||||
/**
|
||||
* RegexDirectoryIterator constructor.
|
||||
*
|
||||
* @param string $path
|
||||
* The path to scan.
|
||||
* @param string $regex
|
||||
* The regular expression to match, including delimiters. For example,
|
||||
* /\.yml$/ would list only files ending in .yml.
|
||||
*/
|
||||
public function __construct($path, $regex) {
|
||||
// Use FilesystemIterator to not iterate over the the . and .. directories.
|
||||
$iterator = new \FilesystemIterator($path);
|
||||
parent::__construct($iterator);
|
||||
$this->regex = $regex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements \FilterIterator::accept().
|
||||
*/
|
||||
public function accept() {
|
||||
/** @var \SplFileInfo $file_info */
|
||||
$file_info = $this->getInnerIterator()->current();
|
||||
return $file_info->isFile() && preg_match($this->regex, $file_info->getFilename());
|
||||
}
|
||||
|
||||
}
|
18
web/core/lib/Drupal/Component/FileSystem/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/FileSystem/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group FileSystem
|
15
web/core/lib/Drupal/Component/FileSystem/composer.json
Normal file
15
web/core/lib/Drupal/Component/FileSystem/composer.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "drupal/core-filesystem",
|
||||
"description": "FileSystem.",
|
||||
"keywords": ["drupal"],
|
||||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\FileSystem\\": ""
|
||||
}
|
||||
}
|
||||
}
|
339
web/core/lib/Drupal/Component/Gettext/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Gettext/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
563
web/core/lib/Drupal/Component/Gettext/PoHeader.php
Normal file
563
web/core/lib/Drupal/Component/Gettext/PoHeader.php
Normal file
|
@ -0,0 +1,563 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Gettext PO header handler.
|
||||
*
|
||||
* Possible Gettext PO header elements are explained in
|
||||
* http://www.gnu.org/software/gettext/manual/gettext.html#Header-Entry,
|
||||
* but we only support a subset of these directly.
|
||||
*
|
||||
* Example header:
|
||||
*
|
||||
* "Project-Id-Version: Drupal core (7.11)\n"
|
||||
* "POT-Creation-Date: 2012-02-12 22:59+0000\n"
|
||||
* "PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
|
||||
* "Language-Team: Catalan\n"
|
||||
* "MIME-Version: 1.0\n"
|
||||
* "Content-Type: text/plain; charset=utf-8\n"
|
||||
* "Content-Transfer-Encoding: 8bit\n"
|
||||
* "Plural-Forms: nplurals=2; plural=(n>1);\n"
|
||||
*/
|
||||
class PoHeader {
|
||||
|
||||
/**
|
||||
* Language code.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_langcode;
|
||||
|
||||
/**
|
||||
* Formula for the plural form.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_pluralForms;
|
||||
|
||||
/**
|
||||
* Author(s) of the file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_authors;
|
||||
|
||||
/**
|
||||
* Date the po file got created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_po_date;
|
||||
|
||||
/**
|
||||
* Human readable language name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_languageName;
|
||||
|
||||
/**
|
||||
* Name of the project the translation belongs to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_projectName;
|
||||
|
||||
/**
|
||||
* Constructor, creates a PoHeader with default values.
|
||||
*
|
||||
* @param string $langcode
|
||||
* Language code.
|
||||
*/
|
||||
public function __construct($langcode = NULL) {
|
||||
$this->_langcode = $langcode;
|
||||
// Ignore errors when run during site installation before
|
||||
// date_default_timezone_set() is called.
|
||||
$this->_po_date = @date("Y-m-d H:iO");
|
||||
$this->_pluralForms = 'nplurals=2; plural=(n > 1);';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plural form.
|
||||
*
|
||||
* @return string
|
||||
* Plural form component from the header, for example:
|
||||
* 'nplurals=2; plural=(n > 1);'.
|
||||
*/
|
||||
function getPluralForms() {
|
||||
return $this->_pluralForms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the human readable language name.
|
||||
*
|
||||
* @param string $languageName
|
||||
* Human readable language name.
|
||||
*/
|
||||
function setLanguageName($languageName) {
|
||||
$this->_languageName = $languageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the human readable language name.
|
||||
*
|
||||
* @return string
|
||||
* The human readable language name.
|
||||
*/
|
||||
function getLanguageName() {
|
||||
return $this->_languageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the project name.
|
||||
*
|
||||
* @param string $projectName
|
||||
* Human readable project name.
|
||||
*/
|
||||
function setProjectName($projectName) {
|
||||
$this->_projectName = $projectName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the project name.
|
||||
*
|
||||
* @return string
|
||||
* The human readable project name.
|
||||
*/
|
||||
function getProjectName() {
|
||||
return $this->_projectName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate internal values from a string.
|
||||
*
|
||||
* @param string $header
|
||||
* Full header string with key-value pairs.
|
||||
*/
|
||||
public function setFromString($header) {
|
||||
// Get an array of all header values for processing.
|
||||
$values = $this->parseHeader($header);
|
||||
|
||||
// There is only one value relevant for our header implementation when
|
||||
// reading, and that is the plural formula.
|
||||
if (!empty($values['Plural-Forms'])) {
|
||||
$this->_pluralForms = $values['Plural-Forms'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a Gettext PO formatted header string based on data set earlier.
|
||||
*/
|
||||
public function __toString() {
|
||||
$output = '';
|
||||
|
||||
$isTemplate = empty($this->_languageName);
|
||||
|
||||
$output .= '# ' . ($isTemplate ? 'LANGUAGE' : $this->_languageName) . ' translation of ' . ($isTemplate ? 'PROJECT' : $this->_projectName) . "\n";
|
||||
if (!empty($this->_authors)) {
|
||||
$output .= '# Generated by ' . implode("\n# ", $this->_authors) . "\n";
|
||||
}
|
||||
$output .= "#\n";
|
||||
|
||||
// Add the actual header information.
|
||||
$output .= "msgid \"\"\n";
|
||||
$output .= "msgstr \"\"\n";
|
||||
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
|
||||
$output .= "\"POT-Creation-Date: " . $this->_po_date . "\\n\"\n";
|
||||
$output .= "\"PO-Revision-Date: " . $this->_po_date . "\\n\"\n";
|
||||
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
|
||||
$output .= "\"MIME-Version: 1.0\\n\"\n";
|
||||
$output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
|
||||
$output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
|
||||
$output .= "\"Plural-Forms: " . $this->_pluralForms . "\\n\"\n";
|
||||
$output .= "\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Plural-Forms entry from a Gettext Portable Object file header.
|
||||
*
|
||||
* @param string $pluralforms
|
||||
* The Plural-Forms entry value.
|
||||
*
|
||||
* @return
|
||||
* An indexed array of parsed plural formula data. Containing:
|
||||
* - 'nplurals': The number of plural forms defined by the plural formula.
|
||||
* - 'plurals': Array of plural positions keyed by plural value.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
function parsePluralForms($pluralforms) {
|
||||
$plurals = array();
|
||||
// First, delete all whitespace.
|
||||
$pluralforms = strtr($pluralforms, array(" " => "", "\t" => ""));
|
||||
|
||||
// Select the parts that define nplurals and plural.
|
||||
$nplurals = strstr($pluralforms, "nplurals=");
|
||||
if (strpos($nplurals, ";")) {
|
||||
// We want the string from the 10th char, because "nplurals=" length is 9.
|
||||
$nplurals = substr($nplurals, 9, strpos($nplurals, ";") - 9);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
$plural = strstr($pluralforms, "plural=");
|
||||
if (strpos($plural, ";")) {
|
||||
// We want the string from the 8th char, because "plural=" length is 7.
|
||||
$plural = substr($plural, 7, strpos($plural, ";") - 7);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// If the number of plurals is zero, we return a default result.
|
||||
if ($nplurals == 0) {
|
||||
return array($nplurals, array('default' => 0));
|
||||
}
|
||||
|
||||
// Calculate possible plural positions of different plural values. All known
|
||||
// plural formula's are repetitive above 100.
|
||||
// For data compression we store the last position the array value
|
||||
// changes and store it as default.
|
||||
$element_stack = $this->parseArithmetic($plural);
|
||||
if ($element_stack !== FALSE) {
|
||||
for ($i = 0; $i <= 199; $i++) {
|
||||
$plurals[$i] = $this->evaluatePlural($element_stack, $i);
|
||||
}
|
||||
$default = $plurals[$i - 1];
|
||||
$plurals = array_filter($plurals, function ($value) use ($default) {
|
||||
return ($value != $default);
|
||||
});
|
||||
$plurals['default'] = $default;
|
||||
|
||||
return array($nplurals, $plurals);
|
||||
}
|
||||
else {
|
||||
throw new \Exception('The plural formula could not be parsed.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Gettext Portable Object file header.
|
||||
*
|
||||
* @param string $header
|
||||
* A string containing the complete header.
|
||||
*
|
||||
* @return array
|
||||
* An associative array of key-value pairs.
|
||||
*/
|
||||
private function parseHeader($header) {
|
||||
$header_parsed = array();
|
||||
$lines = array_map('trim', explode("\n", $header));
|
||||
foreach ($lines as $line) {
|
||||
if ($line) {
|
||||
list($tag, $contents) = explode(":", $line, 2);
|
||||
$header_parsed[trim($tag)] = trim($contents);
|
||||
}
|
||||
}
|
||||
return $header_parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and sanitizes an arithmetic formula into a plural element stack.
|
||||
*
|
||||
* While parsing, we ensure, that the operators have the right
|
||||
* precedence and associativity.
|
||||
*
|
||||
* @param string $string
|
||||
* A string containing the arithmetic formula.
|
||||
*
|
||||
* @return
|
||||
* A stack of values and operations to be evaluated.
|
||||
*/
|
||||
private function parseArithmetic($string) {
|
||||
// Operator precedence table.
|
||||
$precedence = array("(" => -1, ")" => -1, "?" => 1, ":" => 1, "||" => 3, "&&" => 4, "==" => 5, "!=" => 5, "<" => 6, ">" => 6, "<=" => 6, ">=" => 6, "+" => 7, "-" => 7, "*" => 8, "/" => 8, "%" => 8);
|
||||
// Right associativity.
|
||||
$right_associativity = array("?" => 1, ":" => 1);
|
||||
|
||||
$tokens = $this->tokenizeFormula($string);
|
||||
|
||||
// Parse by converting into infix notation then back into postfix
|
||||
// Operator stack - holds math operators and symbols.
|
||||
$operator_stack = array();
|
||||
// Element Stack - holds data to be operated on.
|
||||
$element_stack = array();
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
$current_token = $token;
|
||||
|
||||
// Numbers and the $n variable are simply pushed into $element_stack.
|
||||
if (is_numeric($token)) {
|
||||
$element_stack[] = $current_token;
|
||||
}
|
||||
elseif ($current_token == "n") {
|
||||
$element_stack[] = '$n';
|
||||
}
|
||||
elseif ($current_token == "(") {
|
||||
$operator_stack[] = $current_token;
|
||||
}
|
||||
elseif ($current_token == ")") {
|
||||
$topop = array_pop($operator_stack);
|
||||
while (isset($topop) && ($topop != "(")) {
|
||||
$element_stack[] = $topop;
|
||||
$topop = array_pop($operator_stack);
|
||||
}
|
||||
}
|
||||
elseif (!empty($precedence[$current_token])) {
|
||||
// If it's an operator, then pop from $operator_stack into
|
||||
// $element_stack until the precedence in $operator_stack is less
|
||||
// than current, then push into $operator_stack.
|
||||
$topop = array_pop($operator_stack);
|
||||
while (isset($topop) && ($precedence[$topop] >= $precedence[$current_token]) && !(($precedence[$topop] == $precedence[$current_token]) && !empty($right_associativity[$topop]) && !empty($right_associativity[$current_token]))) {
|
||||
$element_stack[] = $topop;
|
||||
$topop = array_pop($operator_stack);
|
||||
}
|
||||
if ($topop) {
|
||||
// Return element to top.
|
||||
$operator_stack[] = $topop;
|
||||
}
|
||||
// Parentheses are not needed.
|
||||
$operator_stack[] = $current_token;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Flush operator stack.
|
||||
$topop = array_pop($operator_stack);
|
||||
while ($topop != NULL) {
|
||||
$element_stack[] = $topop;
|
||||
$topop = array_pop($operator_stack);
|
||||
}
|
||||
$return = $element_stack;
|
||||
|
||||
// Now validate stack.
|
||||
$previous_size = count($element_stack) + 1;
|
||||
while (count($element_stack) < $previous_size) {
|
||||
$previous_size = count($element_stack);
|
||||
for ($i = 2; $i < count($element_stack); $i++) {
|
||||
$op = $element_stack[$i];
|
||||
if (!empty($precedence[$op])) {
|
||||
if ($op == ":") {
|
||||
$f = $element_stack[$i - 2] . "):" . $element_stack[$i - 1] . ")";
|
||||
}
|
||||
elseif ($op == "?") {
|
||||
$f = "(" . $element_stack[$i - 2] . "?(" . $element_stack[$i - 1];
|
||||
}
|
||||
else {
|
||||
$f = "(" . $element_stack[$i - 2] . $op . $element_stack[$i - 1] . ")";
|
||||
}
|
||||
array_splice($element_stack, $i - 2, 3, $f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If only one element is left, the number of operators is appropriate.
|
||||
return count($element_stack) == 1 ? $return : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tokenize the formula.
|
||||
*
|
||||
* @param string $formula
|
||||
* A string containing the arithmetic formula.
|
||||
*
|
||||
* @return array
|
||||
* List of arithmetic tokens identified in the formula.
|
||||
*/
|
||||
private function tokenizeFormula($formula) {
|
||||
$formula = str_replace(" ", "", $formula);
|
||||
$tokens = array();
|
||||
for ($i = 0; $i < strlen($formula); $i++) {
|
||||
if (is_numeric($formula[$i])) {
|
||||
$num = $formula[$i];
|
||||
$j = $i + 1;
|
||||
while ($j < strlen($formula) && is_numeric($formula[$j])) {
|
||||
$num .= $formula[$j];
|
||||
$j++;
|
||||
}
|
||||
$i = $j - 1;
|
||||
$tokens[] = $num;
|
||||
}
|
||||
elseif ($pos = strpos(" =<>!&|", $formula[$i])) {
|
||||
$next = $formula[$i + 1];
|
||||
switch ($pos) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
if ($next == '=') {
|
||||
$tokens[] = $formula[$i] . '=';
|
||||
$i++;
|
||||
}
|
||||
else {
|
||||
$tokens[] = $formula[$i];
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ($next == '&') {
|
||||
$tokens[] = '&&';
|
||||
$i++;
|
||||
}
|
||||
else {
|
||||
$tokens[] = $formula[$i];
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if ($next == '|') {
|
||||
$tokens[] = '||';
|
||||
$i++;
|
||||
}
|
||||
else {
|
||||
$tokens[] = $formula[$i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$tokens[] = $formula[$i];
|
||||
}
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the plural element stack using a plural value.
|
||||
*
|
||||
* Using an element stack, which represents a plural formula, we calculate
|
||||
* which plural string should be used for a given plural value.
|
||||
*
|
||||
* An example of plural formula parting and evaluation:
|
||||
* Plural formula: 'n!=1'
|
||||
* This formula is parsed by parseArithmetic() to a stack (array) of elements:
|
||||
* array(
|
||||
* 0 => '$n',
|
||||
* 1 => '1',
|
||||
* 2 => '!=',
|
||||
* );
|
||||
* The evaluatePlural() method evaluates the $element_stack using the plural
|
||||
* value $n. Before the actual evaluation, the '$n' in the array is replaced
|
||||
* by the value of $n.
|
||||
* For example: $n = 2 results in:
|
||||
* array(
|
||||
* 0 => '2',
|
||||
* 1 => '1',
|
||||
* 2 => '!=',
|
||||
* );
|
||||
* The stack is processed until only one element is (the result) is left. In
|
||||
* every iteration the top elements of the stack, up until the first operator,
|
||||
* are evaluated. After evaluation the arguments and the operator itself are
|
||||
* removed and replaced by the evaluation result. This is typically 2
|
||||
* arguments and 1 element for the operator.
|
||||
* Because the operator is '!=' the example stack is evaluated as:
|
||||
* $f = (int) 2 != 1;
|
||||
* The resulting stack is:
|
||||
* array(
|
||||
* 0 => 1,
|
||||
* );
|
||||
* With only one element left in the stack (the final result) the loop is
|
||||
* terminated and the result is returned.
|
||||
*
|
||||
* @param array $element_stack
|
||||
* Array of plural formula values and operators create by parseArithmetic().
|
||||
* @param int $n
|
||||
* The @count number for which we are determining the right plural position.
|
||||
*
|
||||
* @return int
|
||||
* Number of the plural string to be used for the given plural value.
|
||||
*
|
||||
* @see parseArithmetic()
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function evaluatePlural($element_stack, $n) {
|
||||
$count = count($element_stack);
|
||||
$limit = $count;
|
||||
// Replace the '$n' value in the formula by the plural value.
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($element_stack[$i] === '$n') {
|
||||
$element_stack[$i] = $n;
|
||||
}
|
||||
}
|
||||
|
||||
// We process the stack until only one element is (the result) is left.
|
||||
// We limit the number of evaluation cycles to prevent an endless loop in
|
||||
// case the stack contains an error.
|
||||
while (isset($element_stack[1])) {
|
||||
for ($i = 2; $i < $count; $i++) {
|
||||
// There's no point in checking non-symbols. Also, switch(TRUE) would
|
||||
// match any case and so it would break.
|
||||
if (is_bool($element_stack[$i]) || is_numeric($element_stack[$i])) {
|
||||
continue;
|
||||
}
|
||||
$f = NULL;
|
||||
$length = 3;
|
||||
$delta = 2;
|
||||
switch ($element_stack[$i]) {
|
||||
case '==':
|
||||
$f = $element_stack[$i - 2] == $element_stack[$i - 1];
|
||||
break;
|
||||
case '!=':
|
||||
$f = $element_stack[$i - 2] != $element_stack[$i - 1];
|
||||
break;
|
||||
case '<=':
|
||||
$f = $element_stack[$i - 2] <= $element_stack[$i - 1];
|
||||
break;
|
||||
case '>=':
|
||||
$f = $element_stack[$i - 2] >= $element_stack[$i - 1];
|
||||
break;
|
||||
case '<':
|
||||
$f = $element_stack[$i - 2] < $element_stack[$i - 1];
|
||||
break;
|
||||
case '>':
|
||||
$f = $element_stack[$i - 2] > $element_stack[$i - 1];
|
||||
break;
|
||||
case '+':
|
||||
$f = $element_stack[$i - 2] + $element_stack[$i - 1];
|
||||
break;
|
||||
case '-':
|
||||
$f = $element_stack[$i - 2] - $element_stack[$i - 1];
|
||||
break;
|
||||
case '*':
|
||||
$f = $element_stack[$i - 2] * $element_stack[$i - 1];
|
||||
break;
|
||||
case '/':
|
||||
$f = $element_stack[$i - 2] / $element_stack[$i - 1];
|
||||
break;
|
||||
case '%':
|
||||
$f = $element_stack[$i - 2] % $element_stack[$i - 1];
|
||||
break;
|
||||
case '&&':
|
||||
$f = $element_stack[$i - 2] && $element_stack[$i - 1];
|
||||
break;
|
||||
case '||':
|
||||
$f = $element_stack[$i - 2] || $element_stack[$i - 1];
|
||||
break;
|
||||
case ':':
|
||||
$f = $element_stack[$i - 3] ? $element_stack[$i - 2] : $element_stack[$i - 1];
|
||||
// This operator has 3 preceding elements, instead of the default 2.
|
||||
$length = 5;
|
||||
$delta = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
// If the element is an operator we remove the processed elements and
|
||||
// store the result.
|
||||
if (isset($f)) {
|
||||
array_splice($element_stack, $i - $delta, $length, $f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$limit) {
|
||||
throw new \Exception('The plural formula could not be evaluated.');
|
||||
}
|
||||
return (int) $element_stack[0];
|
||||
}
|
||||
|
||||
}
|
282
web/core/lib/Drupal/Component/Gettext/PoItem.php
Normal file
282
web/core/lib/Drupal/Component/Gettext/PoItem.php
Normal file
|
@ -0,0 +1,282 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* PoItem handles one translation.
|
||||
*
|
||||
* @todo: This class contains some really old legacy code.
|
||||
* @see https://www.drupal.org/node/1637662
|
||||
*/
|
||||
class PoItem {
|
||||
|
||||
/**
|
||||
* The language code this translation is in.
|
||||
*
|
||||
* @car string
|
||||
*/
|
||||
private $_langcode;
|
||||
|
||||
/**
|
||||
* The context this translation belongs to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_context = '';
|
||||
|
||||
/**
|
||||
* The source string or array of strings if it has plurals.
|
||||
*
|
||||
* @var string or array
|
||||
* @see $_plural
|
||||
*/
|
||||
private $_source;
|
||||
|
||||
/**
|
||||
* Flag indicating if this translation has plurals.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_plural;
|
||||
|
||||
/**
|
||||
* The comment of this translation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_comment;
|
||||
|
||||
/**
|
||||
* The translation string or array of strings if it has plurals.
|
||||
*
|
||||
* @var string or array
|
||||
* @see $_plural
|
||||
*/
|
||||
private $_translation;
|
||||
|
||||
/**
|
||||
* Gets the language code of the currently used language.
|
||||
*
|
||||
* @return string with langcode
|
||||
*/
|
||||
function getLangcode() {
|
||||
return $this->_langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the language code of the current language.
|
||||
*
|
||||
* @param string $langcode
|
||||
*/
|
||||
function setLangcode($langcode) {
|
||||
$this->_langcode = $langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the context this translation belongs to.
|
||||
*
|
||||
* @return string $context
|
||||
*/
|
||||
function getContext() {
|
||||
return $this->_context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the context this translation belongs to.
|
||||
*
|
||||
* @param string $context
|
||||
*/
|
||||
function setContext($context) {
|
||||
$this->_context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source string or the array of strings if the translation has
|
||||
* plurals.
|
||||
*
|
||||
* @return string or array $translation
|
||||
*/
|
||||
function getSource() {
|
||||
return $this->_source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source string or the array of strings if the translation has
|
||||
* plurals.
|
||||
*
|
||||
* @param string or array $source
|
||||
*/
|
||||
function setSource($source) {
|
||||
$this->_source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translation string or the array of strings if the translation has
|
||||
* plurals.
|
||||
*
|
||||
* @return string or array $translation
|
||||
*/
|
||||
function getTranslation() {
|
||||
return $this->_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the translation string or the array of strings if the translation has
|
||||
* plurals.
|
||||
*
|
||||
* @param string or array $translation
|
||||
*/
|
||||
function setTranslation($translation) {
|
||||
$this->_translation = $translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the translation has plural values.
|
||||
*
|
||||
* @param bool $plural
|
||||
*/
|
||||
function setPlural($plural) {
|
||||
$this->_plural = $plural;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the translation has plural values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isPlural() {
|
||||
return $this->_plural;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the comment of this translation.
|
||||
*
|
||||
* @return String $comment
|
||||
*/
|
||||
function getComment() {
|
||||
return $this->_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the comment of this translation.
|
||||
*
|
||||
* @param string $comment
|
||||
*/
|
||||
function setComment($comment) {
|
||||
$this->_comment = $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the PoItem from a structured array.
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
public function setFromArray(array $values = array()) {
|
||||
if (isset($values['context'])) {
|
||||
$this->setContext($values['context']);
|
||||
}
|
||||
if (isset($values['source'])) {
|
||||
$this->setSource($values['source']);
|
||||
}
|
||||
if (isset($values['translation'])) {
|
||||
$this->setTranslation($values['translation']);
|
||||
}
|
||||
if (isset($values['comment'])) {
|
||||
$this->setComment($values['comment']);
|
||||
}
|
||||
if (isset($this->_source) &&
|
||||
strpos($this->_source, LOCALE_PLURAL_DELIMITER) !== FALSE) {
|
||||
$this->setSource(explode(LOCALE_PLURAL_DELIMITER, $this->_source));
|
||||
$this->setTranslation(explode(LOCALE_PLURAL_DELIMITER, $this->_translation));
|
||||
$this->setPlural(count($this->_source) > 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the PoItem as a string.
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->formatItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the POItem as a string.
|
||||
*/
|
||||
private function formatItem() {
|
||||
$output = '';
|
||||
|
||||
// Format string context.
|
||||
if (!empty($this->_context)) {
|
||||
$output .= 'msgctxt ' . $this->formatString($this->_context);
|
||||
}
|
||||
|
||||
// Format translation.
|
||||
if ($this->_plural) {
|
||||
$output .= $this->formatPlural();
|
||||
}
|
||||
else {
|
||||
$output .= $this->formatSingular();
|
||||
}
|
||||
|
||||
// Add one empty line to separate the translations.
|
||||
$output .= "\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a plural translation.
|
||||
*/
|
||||
private function formatPlural() {
|
||||
$output = '';
|
||||
|
||||
// Format source strings.
|
||||
$output .= 'msgid ' . $this->formatString($this->_source[0]);
|
||||
$output .= 'msgid_plural ' . $this->formatString($this->_source[1]);
|
||||
|
||||
foreach ($this->_translation as $i => $trans) {
|
||||
if (isset($this->_translation[$i])) {
|
||||
$output .= 'msgstr[' . $i . '] ' . $this->formatString($trans);
|
||||
}
|
||||
else {
|
||||
$output .= 'msgstr[' . $i . '] ""' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a singular translation.
|
||||
*/
|
||||
private function formatSingular() {
|
||||
$output = '';
|
||||
$output .= 'msgid ' . $this->formatString($this->_source);
|
||||
$output .= 'msgstr ' . (isset($this->_translation) ? $this->formatString($this->_translation) : '""');
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string for output on multiple lines.
|
||||
*/
|
||||
private function formatString($string) {
|
||||
// Escape characters for processing.
|
||||
$string = addcslashes($string, "\0..\37\\\"");
|
||||
|
||||
// Always include a line break after the explicit \n line breaks from
|
||||
// the source string. Otherwise wrap at 70 chars to accommodate the extra
|
||||
// format overhead too.
|
||||
$parts = explode("\n", wordwrap(str_replace('\n', "\\n\n", $string), 70, " \n"));
|
||||
|
||||
// Multiline string should be exported starting with a "" and newline to
|
||||
// have all lines aligned on the same column.
|
||||
if (count($parts) > 1) {
|
||||
return "\"\"\n\"" . implode("\"\n\"", $parts) . "\"\n";
|
||||
}
|
||||
// Single line strings are output on the same line.
|
||||
else {
|
||||
return "\"$parts[0]\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
87
web/core/lib/Drupal/Component/Gettext/PoMemoryWriter.php
Normal file
87
web/core/lib/Drupal/Component/Gettext/PoMemoryWriter.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Defines a Gettext PO memory writer, to be used by the installer.
|
||||
*/
|
||||
class PoMemoryWriter implements PoWriterInterface {
|
||||
|
||||
/**
|
||||
* Array to hold all PoItem elements.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_items;
|
||||
|
||||
/**
|
||||
* Constructor, initialize empty items.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->_items = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeItem(PoItem $item) {
|
||||
if (is_array($item->getSource())) {
|
||||
$item->setSource(implode(LOCALE_PLURAL_DELIMITER, $item->getSource()));
|
||||
$item->setTranslation(implode(LOCALE_PLURAL_DELIMITER, $item->getTranslation()));
|
||||
}
|
||||
$context = $item->getContext();
|
||||
$this->_items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeItems(PoReaderInterface $reader, $count = -1) {
|
||||
$forever = $count == -1;
|
||||
while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
|
||||
$this->writeItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all stored PoItem's.
|
||||
*
|
||||
* @return array PoItem
|
||||
*/
|
||||
public function getData() {
|
||||
return $this->_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoMetadataInterface:setLangcode().
|
||||
*
|
||||
* Not implemented. Not relevant for the MemoryWriter.
|
||||
*/
|
||||
function setLangcode($langcode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoMetadataInterface:getLangcode().
|
||||
*
|
||||
* Not implemented. Not relevant for the MemoryWriter.
|
||||
*/
|
||||
function getLangcode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoMetadataInterface:getHeader().
|
||||
*
|
||||
* Not implemented. Not relevant for the MemoryWriter.
|
||||
*/
|
||||
function getHeader() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoMetadataInterface:setHeader().
|
||||
*
|
||||
* Not implemented. Not relevant for the MemoryWriter.
|
||||
*/
|
||||
function setHeader(PoHeader $header) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Methods required for both reader and writer implementations.
|
||||
*
|
||||
* @see \Drupal\Component\Gettext\PoReaderInterface
|
||||
* @see \Drupal\Component\Gettext\PoWriterInterface
|
||||
*/
|
||||
interface PoMetadataInterface {
|
||||
|
||||
/**
|
||||
* Set language code.
|
||||
*
|
||||
* @param string $langcode
|
||||
* Language code string.
|
||||
*/
|
||||
public function setLangcode($langcode);
|
||||
|
||||
/**
|
||||
* Get language code.
|
||||
*
|
||||
* @return string
|
||||
* Language code string.
|
||||
*/
|
||||
public function getLangcode();
|
||||
|
||||
/**
|
||||
* Set header metadata.
|
||||
*
|
||||
* @param \Drupal\Component\Gettext\PoHeader $header
|
||||
* Header object representing metadata in a PO header.
|
||||
*/
|
||||
public function setHeader(PoHeader $header);
|
||||
|
||||
/**
|
||||
* Get header metadata.
|
||||
*
|
||||
* @return \Drupal\Component\Gettext\PoHeader $header
|
||||
* Header instance representing metadata in a PO header.
|
||||
*/
|
||||
public function getHeader();
|
||||
|
||||
}
|
18
web/core/lib/Drupal/Component/Gettext/PoReaderInterface.php
Normal file
18
web/core/lib/Drupal/Component/Gettext/PoReaderInterface.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Shared interface definition for all Gettext PO Readers.
|
||||
*/
|
||||
interface PoReaderInterface extends PoMetadataInterface {
|
||||
|
||||
/**
|
||||
* Reads and returns a PoItem (source/translation pair).
|
||||
*
|
||||
* @return \Drupal\Component\Gettext\PoItem
|
||||
* Wrapper for item data instance.
|
||||
*/
|
||||
public function readItem();
|
||||
|
||||
}
|
39
web/core/lib/Drupal/Component/Gettext/PoStreamInterface.php
Normal file
39
web/core/lib/Drupal/Component/Gettext/PoStreamInterface.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Common functions for file/stream based PO readers/writers.
|
||||
*
|
||||
* @see PoReaderInterface
|
||||
* @see PoWriterInterface
|
||||
*/
|
||||
interface PoStreamInterface {
|
||||
|
||||
/**
|
||||
* Open the stream. Set the URI for the stream earlier with setURI().
|
||||
*/
|
||||
public function open();
|
||||
|
||||
/**
|
||||
* Close the stream.
|
||||
*/
|
||||
public function close();
|
||||
|
||||
/**
|
||||
* Gets the URI of the PO stream that is being read or written.
|
||||
*
|
||||
* @return
|
||||
* URI string for this stream.
|
||||
*/
|
||||
public function getURI();
|
||||
|
||||
/**
|
||||
* Set the URI of the PO stream that is going to be read or written.
|
||||
*
|
||||
* @param $uri
|
||||
* URI string to set for this stream.
|
||||
*/
|
||||
public function setURI($uri);
|
||||
|
||||
}
|
594
web/core/lib/Drupal/Component/Gettext/PoStreamReader.php
Normal file
594
web/core/lib/Drupal/Component/Gettext/PoStreamReader.php
Normal file
|
@ -0,0 +1,594 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Implements Gettext PO stream reader.
|
||||
*
|
||||
* The PO file format parsing is implemented according to the documentation at
|
||||
* http://www.gnu.org/software/gettext/manual/gettext.html#PO-Files
|
||||
*/
|
||||
class PoStreamReader implements PoStreamInterface, PoReaderInterface {
|
||||
|
||||
/**
|
||||
* Source line number of the stream being parsed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_line_number = 0;
|
||||
|
||||
/**
|
||||
* Parser context for the stream reader state machine.
|
||||
*
|
||||
* Possible contexts are:
|
||||
* - 'COMMENT' (#)
|
||||
* - 'MSGID' (msgid)
|
||||
* - 'MSGID_PLURAL' (msgid_plural)
|
||||
* - 'MSGCTXT' (msgctxt)
|
||||
* - 'MSGSTR' (msgstr or msgstr[])
|
||||
* - 'MSGSTR_ARR' (msgstr_arg)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_context = 'COMMENT';
|
||||
|
||||
/**
|
||||
* Current entry being read. Incomplete.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_current_item = array();
|
||||
|
||||
/**
|
||||
* Current plural index for plural translations.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_current_plural_index = 0;
|
||||
|
||||
/**
|
||||
* URI of the PO stream that is being read.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_uri = '';
|
||||
|
||||
/**
|
||||
* Language code for the PO stream being read.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_langcode = NULL;
|
||||
|
||||
/**
|
||||
* File handle of the current PO stream.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $_fd;
|
||||
|
||||
/**
|
||||
* The PO stream header.
|
||||
*
|
||||
* @var \Drupal\Component\Gettext\PoHeader
|
||||
*/
|
||||
private $_header;
|
||||
|
||||
/**
|
||||
* Object wrapper for the last read source/translation pair.
|
||||
*
|
||||
* @var \Drupal\Component\Gettext\PoItem
|
||||
*/
|
||||
private $_last_item;
|
||||
|
||||
/**
|
||||
* Indicator of whether the stream reading is finished.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_finished;
|
||||
|
||||
/**
|
||||
* Array of translated error strings recorded on reading this stream so far.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_errors;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLangcode() {
|
||||
return $this->_langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLangcode($langcode) {
|
||||
$this->_langcode = $langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getHeader() {
|
||||
return $this->_header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoMetadataInterface::setHeader().
|
||||
*
|
||||
* Not applicable to stream reading and therefore not implemented.
|
||||
*/
|
||||
public function setHeader(PoHeader $header) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getURI() {
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setURI($uri) {
|
||||
$this->_uri = $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoStreamInterface::open().
|
||||
*
|
||||
* Opens the stream and reads the header. The stream is ready for reading
|
||||
* items after.
|
||||
*
|
||||
* @throws Exception
|
||||
* If the URI is not yet set.
|
||||
*/
|
||||
public function open() {
|
||||
if (!empty($this->_uri)) {
|
||||
$this->_fd = fopen($this->_uri, 'rb');
|
||||
$this->readHeader();
|
||||
}
|
||||
else {
|
||||
throw new \Exception('Cannot open stream without URI set.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoStreamInterface::close().
|
||||
*
|
||||
* @throws Exception
|
||||
* If the stream is not open.
|
||||
*/
|
||||
public function close() {
|
||||
if ($this->_fd) {
|
||||
fclose($this->_fd);
|
||||
}
|
||||
else {
|
||||
throw new \Exception('Cannot close stream that is not open.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function readItem() {
|
||||
// Clear out the last item.
|
||||
$this->_last_item = NULL;
|
||||
|
||||
// Read until finished with the stream or a complete item was identified.
|
||||
while (!$this->_finished && is_null($this->_last_item)) {
|
||||
$this->readLine();
|
||||
}
|
||||
|
||||
return $this->_last_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the seek position for the current PO stream.
|
||||
*
|
||||
* @param int $seek
|
||||
* The new seek position to set.
|
||||
*/
|
||||
public function setSeek($seek) {
|
||||
fseek($this->_fd, $seek);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pointer position of the current PO stream.
|
||||
*/
|
||||
public function getSeek() {
|
||||
return ftell($this->_fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the header from the PO stream.
|
||||
*
|
||||
* The header is a special case PoItem, using the empty string as source and
|
||||
* key-value pairs as translation. We just reuse the item reader logic to
|
||||
* read the header.
|
||||
*/
|
||||
private function readHeader() {
|
||||
$item = $this->readItem();
|
||||
// Handle the case properly when the .po file is empty (0 bytes).
|
||||
if (!$item) {
|
||||
return;
|
||||
}
|
||||
$header = new PoHeader();
|
||||
$header->setFromString(trim($item->getTranslation()));
|
||||
$this->_header = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a line from the PO stream and stores data internally.
|
||||
*
|
||||
* Expands $this->_current_item based on new data for the current item. If
|
||||
* this line ends the current item, it is saved with setItemFromArray() with
|
||||
* data from $this->_current_item.
|
||||
*
|
||||
* An internal state machine is maintained in this reader using
|
||||
* $this->_context as the reading state. PO items are in between COMMENT
|
||||
* states (when items have at least one line or comment in between them) or
|
||||
* indicated by MSGSTR or MSGSTR_ARR followed immediately by an MSGID or
|
||||
* MSGCTXT (when items closely follow each other).
|
||||
*
|
||||
* @return
|
||||
* FALSE if an error was logged, NULL otherwise. The errors are considered
|
||||
* non-blocking, so reading can continue, while the errors are collected
|
||||
* for later presentation.
|
||||
*/
|
||||
private function readLine() {
|
||||
// Read a line and set the stream finished indicator if it was not
|
||||
// possible anymore.
|
||||
$line = fgets($this->_fd);
|
||||
$this->_finished = ($line === FALSE);
|
||||
|
||||
if (!$this->_finished) {
|
||||
|
||||
if ($this->_line_number == 0) {
|
||||
// The first line might come with a UTF-8 BOM, which should be removed.
|
||||
$line = str_replace("\xEF\xBB\xBF", '', $line);
|
||||
// Current plurality for 'msgstr[]'.
|
||||
$this->_current_plural_index = 0;
|
||||
}
|
||||
|
||||
// Track the line number for error reporting.
|
||||
$this->_line_number++;
|
||||
|
||||
// Initialize common values for error logging.
|
||||
$log_vars = array(
|
||||
'%uri' => $this->getURI(),
|
||||
'%line' => $this->_line_number,
|
||||
);
|
||||
|
||||
// Trim away the linefeed. \\n might appear at the end of the string if
|
||||
// another line continuing the same string follows. We can remove that.
|
||||
$line = trim(strtr($line, array("\\\n" => "")));
|
||||
|
||||
if (!strncmp('#', $line, 1)) {
|
||||
// Lines starting with '#' are comments.
|
||||
|
||||
if ($this->_context == 'COMMENT') {
|
||||
// Already in comment context, add to current comment.
|
||||
$this->_current_item['#'][] = substr($line, 1);
|
||||
}
|
||||
elseif (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
|
||||
// We are currently in string context, save current item.
|
||||
$this->setItemFromArray($this->_current_item);
|
||||
|
||||
// Start a new entry for the comment.
|
||||
$this->_current_item = array();
|
||||
$this->_current_item['#'][] = substr($line, 1);
|
||||
|
||||
$this->_context = 'COMMENT';
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// A comment following any other context is a syntax error.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr" was expected but not found on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
elseif (!strncmp('msgid_plural', $line, 12)) {
|
||||
// A plural form for the current source string.
|
||||
|
||||
if ($this->_context != 'MSGID') {
|
||||
// A plural form can only be added to an msgid directly.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgid_plural" was expected but not found on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Remove 'msgid_plural' and trim away whitespace.
|
||||
$line = trim(substr($line, 12));
|
||||
|
||||
// Only the plural source string is left, parse it.
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// The plural form must be wrapped in quotes.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains a syntax error on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Append the plural source to the current entry.
|
||||
if (is_string($this->_current_item['msgid'])) {
|
||||
// The first value was stored as string. Now we know the context is
|
||||
// plural, it is converted to array.
|
||||
$this->_current_item['msgid'] = array($this->_current_item['msgid']);
|
||||
}
|
||||
$this->_current_item['msgid'][] = $quoted;
|
||||
|
||||
$this->_context = 'MSGID_PLURAL';
|
||||
return;
|
||||
}
|
||||
elseif (!strncmp('msgid', $line, 5)) {
|
||||
// Starting a new message.
|
||||
|
||||
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
|
||||
// We are currently in string context, save current item.
|
||||
$this->setItemFromArray($this->_current_item);
|
||||
|
||||
// Start a new context for the msgid.
|
||||
$this->_current_item = array();
|
||||
}
|
||||
elseif ($this->_context == 'MSGID') {
|
||||
// We are currently already in the context, meaning we passed an id with no data.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgid" is unexpected on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Remove 'msgid' and trim away whitespace.
|
||||
$line = trim(substr($line, 5));
|
||||
|
||||
// Only the message id string is left, parse it.
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// The message id must be wrapped in quotes.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgid" on line %line.', $log_vars, $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_current_item['msgid'] = $quoted;
|
||||
$this->_context = 'MSGID';
|
||||
return;
|
||||
}
|
||||
elseif (!strncmp('msgctxt', $line, 7)) {
|
||||
// Starting a new context.
|
||||
|
||||
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
|
||||
// We are currently in string context, save current item.
|
||||
$this->setItemFromArray($this->_current_item);
|
||||
$this->_current_item = array();
|
||||
}
|
||||
elseif (!empty($this->_current_item['msgctxt'])) {
|
||||
// A context cannot apply to another context.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgctxt" is unexpected on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Remove 'msgctxt' and trim away whitespaces.
|
||||
$line = trim(substr($line, 7));
|
||||
|
||||
// Only the msgctxt string is left, parse it.
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// The context string must be quoted.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgctxt" on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_current_item['msgctxt'] = $quoted;
|
||||
|
||||
$this->_context = 'MSGCTXT';
|
||||
return;
|
||||
}
|
||||
elseif (!strncmp('msgstr[', $line, 7)) {
|
||||
// A message string for a specific plurality.
|
||||
|
||||
if (($this->_context != 'MSGID') &&
|
||||
($this->_context != 'MSGCTXT') &&
|
||||
($this->_context != 'MSGID_PLURAL') &&
|
||||
($this->_context != 'MSGSTR_ARR')) {
|
||||
// Plural message strings must come after msgid, msgxtxt,
|
||||
// msgid_plural, or other msgstr[] entries.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr[]" is unexpected on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Ensure the plurality is terminated.
|
||||
if (strpos($line, ']') === FALSE) {
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Extract the plurality.
|
||||
$frombracket = strstr($line, '[');
|
||||
$this->_current_plural_index = substr($frombracket, 1, strpos($frombracket, ']') - 1);
|
||||
|
||||
// Skip to the next whitespace and trim away any further whitespace,
|
||||
// bringing $line to the message text only.
|
||||
$line = trim(strstr($line, " "));
|
||||
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// The string must be quoted.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr[]" on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
if (!isset($this->_current_item['msgstr']) || !is_array($this->_current_item['msgstr'])) {
|
||||
$this->_current_item['msgstr'] = array();
|
||||
}
|
||||
|
||||
$this->_current_item['msgstr'][$this->_current_plural_index] = $quoted;
|
||||
|
||||
$this->_context = 'MSGSTR_ARR';
|
||||
return;
|
||||
}
|
||||
elseif (!strncmp("msgstr", $line, 6)) {
|
||||
// A string pair for an msgid (with optional context).
|
||||
|
||||
if (($this->_context != 'MSGID') && ($this->_context != 'MSGCTXT')) {
|
||||
// Strings are only valid within an id or context scope.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: "msgstr" is unexpected on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Remove 'msgstr' and trim away away whitespaces.
|
||||
$line = trim(substr($line, 6));
|
||||
|
||||
// Only the msgstr string is left, parse it.
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// The string must be quoted.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: invalid format for "msgstr" on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_current_item['msgstr'] = $quoted;
|
||||
|
||||
$this->_context = 'MSGSTR';
|
||||
return;
|
||||
}
|
||||
elseif ($line != '') {
|
||||
// Anything that is not a token may be a continuation of a previous token.
|
||||
|
||||
$quoted = $this->parseQuoted($line);
|
||||
if ($quoted === FALSE) {
|
||||
// This string must be quoted.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: string continuation expected on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Append the string to the current item.
|
||||
if (($this->_context == 'MSGID') || ($this->_context == 'MSGID_PLURAL')) {
|
||||
if (is_array($this->_current_item['msgid'])) {
|
||||
// Add string to last array element for plural sources.
|
||||
$last_index = count($this->_current_item['msgid']) - 1;
|
||||
$this->_current_item['msgid'][$last_index] .= $quoted;
|
||||
}
|
||||
else {
|
||||
// Singular source, just append the string.
|
||||
$this->_current_item['msgid'] .= $quoted;
|
||||
}
|
||||
}
|
||||
elseif ($this->_context == 'MSGCTXT') {
|
||||
// Multiline context name.
|
||||
$this->_current_item['msgctxt'] .= $quoted;
|
||||
}
|
||||
elseif ($this->_context == 'MSGSTR') {
|
||||
// Multiline translation string.
|
||||
$this->_current_item['msgstr'] .= $quoted;
|
||||
}
|
||||
elseif ($this->_context == 'MSGSTR_ARR') {
|
||||
// Multiline plural translation string.
|
||||
$this->_current_item['msgstr'][$this->_current_plural_index] .= $quoted;
|
||||
}
|
||||
else {
|
||||
// No valid context to append to.
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri contains an error: unexpected string on line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Empty line read or EOF of PO stream, close out the last entry.
|
||||
if (($this->_context == 'MSGSTR') || ($this->_context == 'MSGSTR_ARR')) {
|
||||
$this->setItemFromArray($this->_current_item);
|
||||
$this->_current_item = array();
|
||||
}
|
||||
elseif ($this->_context != 'COMMENT') {
|
||||
$this->_errors[] = SafeMarkup::format('The translation stream %uri ended unexpectedly at line %line.', $log_vars);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the parsed values as a PoItem object.
|
||||
*/
|
||||
public function setItemFromArray($value) {
|
||||
$plural = FALSE;
|
||||
|
||||
$comments = '';
|
||||
if (isset($value['#'])) {
|
||||
$comments = $this->shortenComments($value['#']);
|
||||
}
|
||||
|
||||
if (is_array($value['msgstr'])) {
|
||||
// Sort plural variants by their form index.
|
||||
ksort($value['msgstr']);
|
||||
$plural = TRUE;
|
||||
}
|
||||
|
||||
$item = new PoItem();
|
||||
$item->setContext(isset($value['msgctxt']) ? $value['msgctxt'] : '');
|
||||
$item->setSource($value['msgid']);
|
||||
$item->setTranslation($value['msgstr']);
|
||||
$item->setPlural($plural);
|
||||
$item->setComment($comments);
|
||||
$item->setLangcode($this->_langcode);
|
||||
|
||||
$this->_last_item = $item;
|
||||
|
||||
$this->_context = 'COMMENT';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string in quotes.
|
||||
*
|
||||
* @param $string
|
||||
* A string specified with enclosing quotes.
|
||||
*
|
||||
* @return
|
||||
* The string parsed from inside the quotes.
|
||||
*/
|
||||
function parseQuoted($string) {
|
||||
if (substr($string, 0, 1) != substr($string, -1, 1)) {
|
||||
// Start and end quotes must be the same.
|
||||
return FALSE;
|
||||
}
|
||||
$quote = substr($string, 0, 1);
|
||||
$string = substr($string, 1, -1);
|
||||
if ($quote == '"') {
|
||||
// Double quotes: strip slashes.
|
||||
return stripcslashes($string);
|
||||
}
|
||||
elseif ($quote == "'") {
|
||||
// Simple quote: return as-is.
|
||||
return $string;
|
||||
}
|
||||
else {
|
||||
// Unrecognized quote.
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a short, one-string version of the passed comment array.
|
||||
*
|
||||
* @param $comment
|
||||
* An array of strings containing a comment.
|
||||
*
|
||||
* @return
|
||||
* Short one-string version of the comment.
|
||||
*/
|
||||
private function shortenComments($comment) {
|
||||
$comm = '';
|
||||
while (count($comment)) {
|
||||
$test = $comm . substr(array_shift($comment), 1) . ', ';
|
||||
if (strlen($comm) < 130) {
|
||||
$comm = $test;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return trim(substr($comm, 0, -2));
|
||||
}
|
||||
|
||||
}
|
157
web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php
Normal file
157
web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Defines a Gettext PO stream writer.
|
||||
*/
|
||||
class PoStreamWriter implements PoWriterInterface, PoStreamInterface {
|
||||
|
||||
/**
|
||||
* URI of the PO stream that is being written.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_uri;
|
||||
|
||||
/**
|
||||
* The Gettext PO header.
|
||||
*
|
||||
* @var \Drupal\Component\Gettext\PoHeader
|
||||
*/
|
||||
private $_header;
|
||||
|
||||
/**
|
||||
* File handle of the current PO stream.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $_fd;
|
||||
|
||||
/**
|
||||
* Gets the PO header of the current stream.
|
||||
*
|
||||
* @return \Drupal\Component\Gettext\PoHeader
|
||||
* The Gettext PO header.
|
||||
*/
|
||||
public function getHeader() {
|
||||
return $this->_header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the PO header for the current stream.
|
||||
*
|
||||
* @param \Drupal\Component\Gettext\PoHeader $header
|
||||
* The Gettext PO header to set.
|
||||
*/
|
||||
public function setHeader(PoHeader $header) {
|
||||
$this->_header = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current language code used.
|
||||
*
|
||||
* @return string
|
||||
* The language code.
|
||||
*/
|
||||
public function getLangcode() {
|
||||
return $this->_langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the language code.
|
||||
*
|
||||
* @param string $langcode
|
||||
* The language code.
|
||||
*/
|
||||
public function setLangcode($langcode) {
|
||||
$this->_langcode = $langcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function open() {
|
||||
// Open in write mode. Will overwrite the stream if it already exists.
|
||||
$this->_fd = fopen($this->getURI(), 'w');
|
||||
// Write the header at the start.
|
||||
$this->writeHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoStreamInterface::close().
|
||||
*
|
||||
* @throws Exception
|
||||
* If the stream is not open.
|
||||
*/
|
||||
public function close() {
|
||||
if ($this->_fd) {
|
||||
fclose($this->_fd);
|
||||
}
|
||||
else {
|
||||
throw new Exception('Cannot close stream that is not open.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to the stream.
|
||||
*
|
||||
* @param string $data
|
||||
* Piece of string to write to the stream. If the value is not directly a
|
||||
* string, casting will happen in writing.
|
||||
*
|
||||
* @throws Exception
|
||||
* If writing the data is not possible.
|
||||
*/
|
||||
private function write($data) {
|
||||
$result = fputs($this->_fd, $data);
|
||||
if ($result === FALSE) {
|
||||
throw new Exception('Unable to write data: ' . substr($data, 0, 20));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the PO header to the stream.
|
||||
*/
|
||||
private function writeHeader() {
|
||||
$this->write($this->_header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeItem(PoItem $item) {
|
||||
$this->write($item);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeItems(PoReaderInterface $reader, $count = -1) {
|
||||
$forever = $count == -1;
|
||||
while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
|
||||
$this->writeItem($item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Drupal\Component\Gettext\PoStreamInterface::getURI().
|
||||
*
|
||||
* @throws Exception
|
||||
* If the URI is not set.
|
||||
*/
|
||||
public function getURI() {
|
||||
if (empty($this->_uri)) {
|
||||
throw new Exception('No URI set.');
|
||||
}
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setURI($uri) {
|
||||
$this->_uri = $uri;
|
||||
}
|
||||
|
||||
}
|
29
web/core/lib/Drupal/Component/Gettext/PoWriterInterface.php
Normal file
29
web/core/lib/Drupal/Component/Gettext/PoWriterInterface.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Gettext;
|
||||
|
||||
/**
|
||||
* Shared interface definition for all Gettext PO Writers.
|
||||
*/
|
||||
interface PoWriterInterface extends PoMetadataInterface {
|
||||
|
||||
/**
|
||||
* Writes the given item.
|
||||
*
|
||||
* @param PoItem $item
|
||||
* One specific item to write.
|
||||
*/
|
||||
public function writeItem(PoItem $item);
|
||||
|
||||
/**
|
||||
* Writes all or the given amount of items.
|
||||
*
|
||||
* @param PoReaderInterface $reader
|
||||
* Reader to read PoItems from.
|
||||
* @param $count
|
||||
* Amount of items to read from $reader to write. If -1, all items are
|
||||
* read from $reader.
|
||||
*/
|
||||
public function writeItems(PoReaderInterface $reader, $count = -1);
|
||||
|
||||
}
|
12
web/core/lib/Drupal/Component/Gettext/README.txt
Normal file
12
web/core/lib/Drupal/Component/Gettext/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Gettext Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
18
web/core/lib/Drupal/Component/Gettext/TESTING.txt
Normal file
18
web/core/lib/Drupal/Component/Gettext/TESTING.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
HOW-TO: Test this Drupal component
|
||||
|
||||
In order to test this component, you'll need to get the entire Drupal repo and
|
||||
run the tests there.
|
||||
|
||||
You'll find the tests under core/tests/Drupal/Tests/Component.
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can find more information about running PHPUnit tests with Drupal here:
|
||||
https://www.drupal.org/node/2116263
|
||||
|
||||
Each component in the Drupal\Component namespace has its own annotated test
|
||||
group. You can use this group to run only the tests for this component. Like
|
||||
this:
|
||||
|
||||
$ ./vendor/bin/phpunit -c core --group Gettext
|
20
web/core/lib/Drupal/Component/Gettext/composer.json
Normal file
20
web/core/lib/Drupal/Component/Gettext/composer.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "drupal/core-gettext",
|
||||
"description": "PHP library for reading PO files.",
|
||||
"type": "library",
|
||||
"license": "GPL-2.0+",
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/drupal",
|
||||
"irc": "irc://irc.freenode.net/drupal-contribute",
|
||||
"source": "https://www.drupal.org/project/drupal/git-instructions"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"drupal/core-utility": "~8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Drupal\\Component\\Gettext\\": ""
|
||||
}
|
||||
}
|
||||
}
|
158
web/core/lib/Drupal/Component/Graph/Graph.php
Normal file
158
web/core/lib/Drupal/Component/Graph/Graph.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Component\Graph;
|
||||
|
||||
/**
|
||||
* Directed acyclic graph manipulation.
|
||||
*/
|
||||
class Graph {
|
||||
|
||||
/**
|
||||
* Holds the directed acyclic graph.
|
||||
*/
|
||||
protected $graph;
|
||||
|
||||
/**
|
||||
* Instantiates the depth first search object.
|
||||
*
|
||||
* @param $graph
|
||||
* A three dimensional associated array, with the first keys being the names
|
||||
* of the vertices, these can be strings or numbers. The second key is
|
||||
* 'edges' and the third one are again vertices, each such key representing
|
||||
* an edge. Values of array elements are copied over.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* $graph[1]['edges'][2] = 1;
|
||||
* $graph[2]['edges'][3] = 1;
|
||||
* $graph[2]['edges'][4] = 1;
|
||||
* $graph[3]['edges'][4] = 1;
|
||||
* @endcode
|
||||
*
|
||||
* On return you will also have:
|
||||
* @code
|
||||
* $graph[1]['paths'][2] = 1;
|
||||
* $graph[1]['paths'][3] = 1;
|
||||
* $graph[2]['reverse_paths'][1] = 1;
|
||||
* $graph[3]['reverse_paths'][1] = 1;
|
||||
* @endcode
|
||||
*/
|
||||
public function __construct($graph) {
|
||||
$this->graph = $graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a depth-first search and sort on the directed acyclic graph.
|
||||
*
|
||||
* @return
|
||||
* The given $graph with more secondary keys filled in:
|
||||
* - 'paths': Contains a list of vertices than can be reached on a path from
|
||||
* this vertex.
|
||||
* - 'reverse_paths': Contains a list of vertices that has a path from them
|
||||
* to this vertex.
|
||||
* - 'weight': If there is a path from a vertex to another then the weight of
|
||||
* the latter is higher.
|
||||
* - 'component': Vertices in the same component have the same component
|
||||
* identifier.
|
||||
*/
|
||||
public function searchAndSort() {
|
||||
$state = array(
|
||||
// The order of last visit of the depth first search. This is the reverse
|
||||
// of the topological order if the graph is acyclic.
|
||||
'last_visit_order' => array(),
|
||||
// The components of the graph.
|
||||
'components' => array(),
|
||||
);
|
||||
// Perform the actual search.
|
||||
foreach ($this->graph as $start => $data) {
|
||||
$this->depthFirstSearch($state, $start);
|
||||
}
|
||||
|
||||
// We do such a numbering that every component starts with 0. This is useful
|
||||
// for module installs as we can install every 0 weighted module in one
|
||||
// request, and then every 1 weighted etc.
|
||||
$component_weights = array();
|
||||
|
||||
foreach ($state['last_visit_order'] as $vertex) {
|
||||
$component = $this->graph[$vertex]['component'];
|
||||
if (!isset($component_weights[$component])) {
|
||||
$component_weights[$component] = 0;
|
||||
}
|
||||
$this->graph[$vertex]['weight'] = $component_weights[$component]--;
|
||||
}
|
||||
|
||||
return $this->graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a depth-first search on a graph.
|
||||
*
|
||||
* @param $state
|
||||
* An associative array. The key 'last_visit_order' stores a list of the
|
||||
* vertices visited. The key components stores list of vertices belonging
|
||||
* to the same the component.
|
||||
* @param $start
|
||||
* An arbitrary vertex where we started traversing the graph.
|
||||
* @param $component
|
||||
* The component of the last vertex.
|
||||
*
|
||||
* @see \Drupal\Component\Graph\Graph::searchAndSort()
|
||||
*/
|
||||
protected function depthFirstSearch(&$state, $start, &$component = NULL) {
|
||||
// Assign new component for each new vertex, i.e. when not called recursively.
|
||||
if (!isset($component)) {
|
||||
$component = $start;
|
||||
}
|
||||
// Nothing to do, if we already visited this vertex.
|
||||
if (isset($this->graph[$start]['paths'])) {
|
||||
return;
|
||||
}
|
||||
// Mark $start as visited.
|
||||
$this->graph[$start]['paths'] = array();
|
||||
|
||||
// Assign $start to the current component.
|
||||
$this->graph[$start]['component'] = $component;
|
||||
$state['components'][$component][] = $start;
|
||||
|
||||
// Visit edges of $start.
|
||||
if (isset($this->graph[$start]['edges'])) {
|
||||
foreach ($this->graph[$start]['edges'] as $end => $v) {
|
||||
// Mark that $start can reach $end.
|
||||
$this->graph[$start]['paths'][$end] = $v;
|
||||
|
||||
if (isset($this->graph[$end]['component']) && $component != $this->graph[$end]['component']) {
|
||||
// This vertex already has a component, use that from now on and
|
||||
// reassign all the previously explored vertices.
|
||||
$new_component = $this->graph[$end]['component'];
|
||||
foreach ($state['components'][$component] as $vertex) {
|
||||
$this->graph[$vertex]['component'] = $new_component;
|
||||
$state['components'][$new_component][] = $vertex;
|
||||
}
|
||||
unset($state['components'][$component]);
|
||||
$component = $new_component;
|
||||
}
|
||||
// Only visit existing vertices.
|
||||
if (isset($this->graph[$end])) {
|
||||
// Visit the connected vertex.
|
||||
$this->depthFirstSearch($state, $end, $component);
|
||||
|
||||
// All vertices reachable by $end are also reachable by $start.
|
||||
$this->graph[$start]['paths'] += $this->graph[$end]['paths'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that any other subgraph has been explored, add $start to all reverse
|
||||
// paths.
|
||||
foreach ($this->graph[$start]['paths'] as $end => $v) {
|
||||
if (isset($this->graph[$end])) {
|
||||
$this->graph[$end]['reverse_paths'][$start] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
// Record the order of the last visit. This is the reverse of the
|
||||
// topological order if the graph is acyclic.
|
||||
$state['last_visit_order'][] = $start;
|
||||
}
|
||||
|
||||
}
|
339
web/core/lib/Drupal/Component/Graph/LICENSE.txt
Normal file
339
web/core/lib/Drupal/Component/Graph/LICENSE.txt
Normal file
|
@ -0,0 +1,339 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
12
web/core/lib/Drupal/Component/Graph/README.txt
Normal file
12
web/core/lib/Drupal/Component/Graph/README.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
The Drupal Graph Component
|
||||
|
||||
Thanks for using this Drupal component.
|
||||
|
||||
You can participate in its development on Drupal.org, through our issue system:
|
||||
https://www.drupal.org/project/issues/drupal
|
||||
|
||||
You can get the full Drupal repo here:
|
||||
https://www.drupal.org/project/drupal/git-instructions
|
||||
|
||||
You can browse the full Drupal repo here:
|
||||
http://cgit.drupalcode.org/drupal
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue