125a827e by Jeremy Groot

initial

0 parents
Showing 1000 changed files with 3528 additions and 0 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

1 DB_HOST=localhost
2 DB_NAME=sv-intranet
3 DB_USER=root
4 DB_PASS=<KJad2W5
1
2 # BEGIN WordPress
3 # The directives (lines) between `BEGIN WordPress` and `END WordPress` are
4 # dynamically generated, and should only be modified via WordPress filters.
5 # Any changes to the directives between these markers will be overwritten.
6 <IfModule mod_rewrite.c>
7 RewriteEngine On
8 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
9 RewriteBase /
10 RewriteRule ^index\.php$ - [L]
11 RewriteCond %{REQUEST_FILENAME} !-f
12 RewriteCond %{REQUEST_FILENAME} !-d
13 RewriteRule . /index.php [L]
14 </IfModule>
15
16 # END WordPress
...\ No newline at end of file ...\ No newline at end of file
1 # Load DSL and Setup Up Stages
2 require 'capistrano/setup'
3
4 # Includes default deployment tasks
5 require 'capistrano/deploy'
6
7 # Load tasks from gems
8 # require 'capistrano/composer'
9
10 # Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
11 # Customize this path to change the location of your custom tasks.
12 Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
1 {
2 "require": {
3 "roots/acorn": "^2.1",
4 "vlucas/phpdotenv": "^5.4"
5 }
6 }
This diff could not be displayed because it is too large.
1 function put_svi_database() {
2
3 ssh tenzing_www@db-1 mysqldump -u root sv-intranet | cat > /Users/jeremy/Desktop/sv-intranet.bak.sql \
4 && mysqldump -u root sv-intranet > /Users/jeremy/Desktop/sv-intranet-local-bak.sql \
5 && wp --path=/Users/jeremy/Webserver/sv-intranet/ search-replace 'http://svi.test' 'https://svi-staging.gotenzing.com' --skip-columns=guid \
6 && mysqldump -u root sv-intranet > /Users/jeremy/Desktop/sv-intranet-new.sql \
7 && ssh tenzing_www@db-1 "mysql -u root -e 'drop database IF EXISTS sv-intranet; create database sv-intranet;'" \
8 && cat /Users/jeremy/Desktop/sv-intranet-new.sql | ssh tenzing_www@db-1 'mysql -u root sv-intranet' \
9 && wp --path=/Users/jeremy/Webserver/sv-intranet/ search-replace 'https://svi-staging.gotenzing.com' 'http://svi.test' --skip-columns=guid \
10
11 }
12
13 # function pull_database() {
14
15 # ssh tenzing_www@db-1 mysqldump -u root docterswithoutborders_staging | cat > /Users/jeremy/Desktop/docterswithoutborders_staging.sql \
16 # && mysqldump -u root docterswithoutborders > /Users/jeremy/Desktop/docterswithoutborders.sql.local-bak \
17 # && mysql -u root -e "drop database IF EXISTS docterswithoutborders; create database docterswithoutborders;" \
18 # && mysql -u root docterswithoutborders < /Users/jeremy/Desktop/docterswithoutborders_staging.sql \
19 # && wp --path=/Users/jeremy/Webserver/msf-ca-new/ search-replace 'https://msf-staging.gotenzing.com' 'http://msf.test' --skip-columns=guid \
20
21 # }
...\ No newline at end of file ...\ No newline at end of file
1 set :application, 'explore-the-bruce'
2 set :repo_url, 'git@git.gotenzing.com:Jeremy/explore-the-bruce.git'
3
4 # Branch options
5 # Prompts for the branch name (defaults to current branch)
6 #ask :branch, -> { `git rev-parse --abbrev-ref HEAD`.chomp }
7
8 # Hardcodes branch to always be master
9 # This could be overridden in a stage config file
10 set :branch, "production"
11
12
13 set :keep_releases, 2
14 set :deploy_to, -> { "/var/www/html/#{fetch(:application)}" }
15
16 # Use :debug for more verbose output when troubleshooting
17 set :log_level, :info
18
19 # Put all shared files/directories here (e.g. uploads that need to go on the NFS drive)
20 set :linked_files, fetch(:linked_files, []).push('.env', '.htaccess')
21 set :linked_dirs, fetch(:linked_dirs, []).push('wp-content/wflogs','wp-content/uploads', 'wp-content/storage', 'wp-content/cache')
22
23 # namespace :deploy do
24 # desc 'Sync servers'
25 # task :sync do
26 # on roles(:web), in: :sequence, wait: 5 do
27 # execute("si #{fetch(:application)}")
28 # end
29 # end
30 # end
31
32 # namespace :deploy do
33 # desc 'Sync servers'
34 # task :sync_again do
35 # on roles(:web), in: :sequence, wait: 5 do
36 # execute("si #{fetch(:application)}")
37 # end
38 # end
39 # end
40
41 # namespace :deploy do
42 # desc 'Install composer packages'
43 # task :install_theme_packages do
44 # on roles(:web), in: :sequence, wait: 5 do
45 # execute "cd '#{release_path}'; /usr/bin/php70 /home/tenzing_www/bin/composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader"
46 # end
47 # end
48 # end
49
50 # namespace :deploy do
51 # desc 'Install composer packages'
52 # task :install_theme_packages do
53 # on roles(:web), in: :sequence, wait: 5 do
54 # execute "cd '#{release_path}/wp-content/themes/commonwell-corp'; /usr/bin/php70 /home/tenzing_www/bin/composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader"
55 # end
56 # end
57 # end
58
59
60
61 # Override `git#create_release` to handle submodules
62 # namespace :git do
63 # desc 'Copy repo to releases'
64 # task create_release: :'git:update' do
65 # on roles(:all) do
66 # with fetch(:git_environmental_variables) do
67 # within repo_path do
68 # execute :git, :clone, '-b', fetch(:branch), '--recursive', '.', release_path
69 # end
70 # end
71 # end
72 # end
73 # end
74
75 # The above restart task is not run by default
76 # Uncomment the following line to run it on deploys if needed
77 # after 'deploy:publishing', 'deploy:restart'
78
79 namespace :deploy do
80 desc 'Remove Git Files'
81 task :cleanup do
82 on roles(:web), in: :sequence, wait: 5 do
83 execute "cd '#{release_path}/'; rm -Rf .git/ "
84 end
85 end
86 end
87
88
89
90
91 # namespace :deploy do
92 # desc 'Update WordPress template root paths to point to the new release'
93 # task :update_option_paths do
94 # on roles(:app) do
95 # within fetch(:release_path) do
96 # if test :wp, :core, 'is-installed'
97 # [:stylesheet_root, :template_root].each do |option|
98 # # Only change the value if it's an absolute path
99 # # i.e. The relative path "/themes" must remain unchanged
100 # # Also, the option might not be set, in which case we leave it like that
101 # value = capture :wp, :option, :get, option, raise_on_non_zero_exit: false
102 # if value != '' && value != '/themes'
103 # execute :wp, :option, :set, option, fetch(:release_path).join('web/wp/wp-content/themes')
104 # end
105 # end
106 # end
107 # end
108 # end
109 # end
110 # end
111
112
113
114 # The above update_option_paths task is not run by default
115 # Note that you need to have WP-CLI installed on your server
116 # Uncomment the following line to run it on deploys if needed
117 # after 'deploy:publishing', 'deploy:update_option_paths'
118
119 # after 'deploy:updated', 'deploy:install_theme_packages'
120 # after 'deploy:updated', 'deploy:sync'
121 # after 'deploy:finished', 'deploy:sync_again'
1 set :stage, :production
2 set :branch, "master"
3
4 # Simple Role Syntax
5 # ==================
6 role :web, %w{jeremy@can-1}
7
8
9
10 # you can set custom ssh options
11 # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
12 # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
13 # set it globally
14 # set :ssh_options, {
15 # keys: %w(~/.ssh/id_rsa),
16 # forward_agent: false,
17 # auth_methods: %w(password)
18 # }
19
20 fetch(:default_env).merge!(wp_env: :production)
1 set :application, 'explore-the-bruce-staging'
2 set :branch, "staging"
3
4 # Simple Role Syntax
5 # ==================
6 role :web, %w{jeremy@can-1}
7
8 # you can set custom ssh options
9 # it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
10 # you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
11 # set it globally
12 # set :ssh_options, {
13 # keys: %w(~/.ssh/id_rsa),
14 # forward_agent: false,
15 # auth_methods: %w(password)
16 # }
17
18 fetch(:default_env).merge!(wp_env: :staging)
1 <?php
2 /**
3 * Front to the WordPress application. This file doesn't do anything, but loads
4 * wp-blog-header.php which does and tells WordPress to load the theme.
5 *
6 * @package WordPress
7 */
8
9 /**
10 * Tells WordPress to load the WordPress theme and output it.
11 *
12 * @var bool
13 */
14 define( 'WP_USE_THEMES', true );
15
16 /** Loads the WordPress Environment and Template */
17 require __DIR__ . '/wp-blog-header.php';
This diff is collapsed. Click to expand it.
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta name="viewport" content="width=device-width" />
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <title>WordPress &#8250; ReadMe</title>
7 <link rel="stylesheet" href="wp-admin/css/install.css?ver=20100228" type="text/css" />
8 </head>
9 <body>
10 <h1 id="logo">
11 <a href="https://wordpress.org/"><img alt="WordPress" src="wp-admin/images/wordpress-logo.png" /></a>
12 </h1>
13 <p style="text-align: center">Semantic Personal Publishing Platform</p>
14
15 <h2>First Things First</h2>
16 <p>Welcome. WordPress is a very special project to me. Every developer and contributor adds something unique to the mix, and together we create something beautiful that I am proud to be a part of. Thousands of hours have gone into WordPress, and we are dedicated to making it better every day. Thank you for making it part of your world.</p>
17 <p style="text-align: right">&#8212; Matt Mullenweg</p>
18
19 <h2>Installation: Famous 5-minute install</h2>
20 <ol>
21 <li>Unzip the package in an empty directory and upload everything.</li>
22 <li>Open <span class="file"><a href="wp-admin/install.php">wp-admin/install.php</a></span> in your browser. It will take you through the process to set up a <code>wp-config.php</code> file with your database connection details.
23 <ol>
24 <li>If for some reason this does not work, do not worry. It may not work on all web hosts. Open up <code>wp-config-sample.php</code> with a text editor like WordPad or similar and fill in your database connection details.</li>
25 <li>Save the file as <code>wp-config.php</code> and upload it.</li>
26 <li>Open <span class="file"><a href="wp-admin/install.php">wp-admin/install.php</a></span> in your browser.</li>
27 </ol>
28 </li>
29 <li>Once the configuration file is set up, the installer will set up the tables needed for your site. If there is an error, double check your <code>wp-config.php</code> file, and try again. If it fails again, please go to the <a href="https://wordpress.org/support/forums/">WordPress support forums</a> with as much data as you can gather.</li>
30 <li><strong>If you did not enter a password, note the password given to you.</strong> If you did not provide a username, it will be <code>admin</code>.</li>
31 <li>The installer should then send you to the <a href="wp-login.php">login page</a>. Sign in with the username and password you chose during the installation. If a password was generated for you, you can then click on &#8220;Profile&#8221; to change the password.</li>
32 </ol>
33
34 <h2>Updating</h2>
35 <h3>Using the Automatic Updater</h3>
36 <ol>
37 <li>Open <span class="file"><a href="wp-admin/update-core.php">wp-admin/update-core.php</a></span> in your browser and follow the instructions.</li>
38 <li>You wanted more, perhaps? That&#8217;s it!</li>
39 </ol>
40
41 <h3>Updating Manually</h3>
42 <ol>
43 <li>Before you update anything, make sure you have backup copies of any files you may have modified such as <code>index.php</code>.</li>
44 <li>Delete your old WordPress files, saving ones you&#8217;ve modified.</li>
45 <li>Upload the new files.</li>
46 <li>Point your browser to <span class="file"><a href="wp-admin/upgrade.php">/wp-admin/upgrade.php</a>.</span></li>
47 </ol>
48
49 <h2>Migrating from other systems</h2>
50 <p>WordPress can <a href="https://wordpress.org/support/article/importing-content/">import from a number of systems</a>. First you need to get WordPress installed and working as described above, before using <a href="wp-admin/import.php">our import tools</a>.</p>
51
52 <h2>System Requirements</h2>
53 <ul>
54 <li><a href="https://secure.php.net/">PHP</a> version <strong>5.6.20</strong> or greater.</li>
55 <li><a href="https://www.mysql.com/">MySQL</a> version <strong>5.0</strong> or greater.</li>
56 </ul>
57
58 <h3>Recommendations</h3>
59 <ul>
60 <li><a href="https://secure.php.net/">PHP</a> version <strong>7.4</strong> or greater.</li>
61 <li><a href="https://www.mysql.com/">MySQL</a> version <strong>5.7</strong> or greater OR <a href="https://mariadb.org/">MariaDB</a> version <strong>10.3</strong> or greater.</li>
62 <li>The <a href="https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite</a> Apache module.</li>
63 <li><a href="https://wordpress.org/news/2016/12/moving-toward-ssl/">HTTPS</a> support.</li>
64 <li>A link to <a href="https://wordpress.org/">wordpress.org</a> on your site.</li>
65 </ul>
66
67 <h2>Online Resources</h2>
68 <p>If you have any questions that are not addressed in this document, please take advantage of WordPress&#8217; numerous online resources:</p>
69 <dl>
70 <dt><a href="https://wordpress.org/support/">HelpHub</a></dt>
71 <dd>HelpHub is the encyclopedia of all things WordPress. It is the most comprehensive source of information for WordPress available.</dd>
72 <dt><a href="https://wordpress.org/news/">The WordPress Blog</a></dt>
73 <dd>This is where you&#8217;ll find the latest updates and news related to WordPress. Recent WordPress news appears in your administrative dashboard by default.</dd>
74 <dt><a href="https://planet.wordpress.org/">WordPress Planet</a></dt>
75 <dd>The WordPress Planet is a news aggregator that brings together posts from WordPress blogs around the web.</dd>
76 <dt><a href="https://wordpress.org/support/forums/">WordPress Support Forums</a></dt>
77 <dd>If you&#8217;ve looked everywhere and still cannot find an answer, the support forums are very active and have a large community ready to help. To help them help you be sure to use a descriptive thread title and describe your question in as much detail as possible.</dd>
78 <dt><a href="https://make.wordpress.org/support/handbook/appendix/other-support-locations/introduction-to-irc/">WordPress <abbr>IRC</abbr> (Internet Relay Chat) Channel</a></dt>
79 <dd>There is an online chat channel that is used for discussion among people who use WordPress and occasionally support topics. The above wiki page should point you in the right direction. (<a href="https://web.libera.chat/#wordpress">irc.libera.chat #wordpress</a>)</dd>
80 </dl>
81
82 <h2>Final Notes</h2>
83 <ul>
84 <li>If you have any suggestions, ideas, or comments, or if you (gasp!) found a bug, join us in the <a href="https://wordpress.org/support/forums/">Support Forums</a>.</li>
85 <li>WordPress has a robust plugin <abbr>API</abbr> (Application Programming Interface) that makes extending the code easy. If you are a developer interested in utilizing this, see the <a href="https://developer.wordpress.org/plugins/">Plugin Developer Handbook</a>. You shouldn&#8217;t modify any of the core code.</li>
86 </ul>
87
88 <h2>Share the Love</h2>
89 <p>WordPress has no multi-million dollar marketing campaign or celebrity sponsors, but we do have something even better&#8212;you. If you enjoy WordPress please consider telling a friend, setting it up for someone less knowledgeable than yourself, or writing the author of a media article that overlooks us.</p>
90
91 <p>WordPress is the official continuation of <a href="http://cafelog.com/">b2/caf&#233;log</a>, which came from Michel V. The work has been continued by the <a href="https://wordpress.org/about/">WordPress developers</a>. If you would like to support WordPress, please consider <a href="https://wordpress.org/donate/">donating</a>.</p>
92
93 <h2>License</h2>
94 <p>WordPress is free software, and is released under the terms of the <abbr>GPL</abbr> (GNU General Public License) version 2 or (at your option) any later version. See <a href="license.txt">license.txt</a>.</p>
95
96 </body>
97 </html>
1 <?php
2
3 // autoload.php @generated by Composer
4
5 require_once __DIR__ . '/composer/autoload_real.php';
6
7 return ComposerAutoloaderInit05c31aef1015133fb9677718a400b237::getLoader();
1 ../nesbot/carbon/bin/carbon
...\ No newline at end of file ...\ No newline at end of file
1 ../symfony/error-handler/Resources/bin/patch-type-declarations
...\ No newline at end of file ...\ No newline at end of file
1 ../symfony/var-dumper/Resources/bin/var-dump-server
...\ No newline at end of file ...\ No newline at end of file
1 The MIT License (MIT)
2
3 Copyright (c) 2013-present Benjamin Morel
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy of
6 this software and associated documentation files (the "Software"), to deal in
7 the Software without restriction, including without limitation the rights to
8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 the Software, and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 # Security Policy
2
3 ## Supported Versions
4
5 Only the last two release streams are supported.
6
7 | Version | Supported |
8 | ------- | ------------------ |
9 | 0.9.x | :white_check_mark: |
10 | 0.8.x | :white_check_mark: |
11 | < 0.8 | :x: |
12
13 ## Reporting a Vulnerability
14
15 To report a security vulnerability, please use the
16 [Tidelift security contact](https://tidelift.com/security).
17 Tidelift will coordinate the fix and disclosure.
1 {
2 "name": "brick/math",
3 "description": "Arbitrary-precision arithmetic library",
4 "type": "library",
5 "keywords": [
6 "Brick",
7 "Math",
8 "Arbitrary-precision",
9 "Arithmetic",
10 "BigInteger",
11 "BigDecimal",
12 "BigRational",
13 "Bignum"
14 ],
15 "license": "MIT",
16 "require": {
17 "php": "^7.1 || ^8.0",
18 "ext-json": "*"
19 },
20 "require-dev": {
21 "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0",
22 "php-coveralls/php-coveralls": "^2.2",
23 "vimeo/psalm": "4.9.2"
24 },
25 "autoload": {
26 "psr-4": {
27 "Brick\\Math\\": "src/"
28 }
29 },
30 "autoload-dev": {
31 "psr-4": {
32 "Brick\\Math\\Tests\\": "tests/"
33 }
34 }
35 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 /**
8 * Exception thrown when a division by zero occurs.
9 */
10 class DivisionByZeroException extends MathException
11 {
12 /**
13 * @return DivisionByZeroException
14 *
15 * @psalm-pure
16 */
17 public static function divisionByZero() : DivisionByZeroException
18 {
19 return new self('Division by zero.');
20 }
21
22 /**
23 * @return DivisionByZeroException
24 *
25 * @psalm-pure
26 */
27 public static function modulusMustNotBeZero() : DivisionByZeroException
28 {
29 return new self('The modulus must not be zero.');
30 }
31
32 /**
33 * @return DivisionByZeroException
34 *
35 * @psalm-pure
36 */
37 public static function denominatorMustNotBeZero() : DivisionByZeroException
38 {
39 return new self('The denominator of a rational number cannot be zero.');
40 }
41 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 use Brick\Math\BigInteger;
8
9 /**
10 * Exception thrown when an integer overflow occurs.
11 */
12 class IntegerOverflowException extends MathException
13 {
14 /**
15 * @param BigInteger $value
16 *
17 * @return IntegerOverflowException
18 *
19 * @psalm-pure
20 */
21 public static function toIntOverflow(BigInteger $value) : IntegerOverflowException
22 {
23 $message = '%s is out of range %d to %d and cannot be represented as an integer.';
24
25 return new self(\sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX));
26 }
27 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 /**
8 * Base class for all math exceptions.
9 *
10 * This class is abstract to ensure that only fine-grained exceptions are thrown throughout the code.
11 */
12 class MathException extends \RuntimeException
13 {
14 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 /**
8 * Exception thrown when attempting to perform an unsupported operation, such as a square root, on a negative number.
9 */
10 class NegativeNumberException extends MathException
11 {
12 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 /**
8 * Exception thrown when attempting to create a number from a string with an invalid format.
9 */
10 class NumberFormatException extends MathException
11 {
12 /**
13 * @param string $char The failing character.
14 *
15 * @return NumberFormatException
16 *
17 * @psalm-pure
18 */
19 public static function charNotInAlphabet(string $char) : self
20 {
21 $ord = \ord($char);
22
23 if ($ord < 32 || $ord > 126) {
24 $char = \strtoupper(\dechex($ord));
25
26 if ($ord < 10) {
27 $char = '0' . $char;
28 }
29 } else {
30 $char = '"' . $char . '"';
31 }
32
33 return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char));
34 }
35 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Exception;
6
7 /**
8 * Exception thrown when a number cannot be represented at the requested scale without rounding.
9 */
10 class RoundingNecessaryException extends MathException
11 {
12 /**
13 * @return RoundingNecessaryException
14 *
15 * @psalm-pure
16 */
17 public static function roundingNecessary() : RoundingNecessaryException
18 {
19 return new self('Rounding is necessary to represent the result of the operation at this scale.');
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Internal\Calculator;
6
7 use Brick\Math\Internal\Calculator;
8
9 /**
10 * Calculator implementation built around the bcmath library.
11 *
12 * @internal
13 *
14 * @psalm-immutable
15 */
16 class BcMathCalculator extends Calculator
17 {
18 /**
19 * {@inheritdoc}
20 */
21 public function add(string $a, string $b) : string
22 {
23 return \bcadd($a, $b, 0);
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 public function sub(string $a, string $b) : string
30 {
31 return \bcsub($a, $b, 0);
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function mul(string $a, string $b) : string
38 {
39 return \bcmul($a, $b, 0);
40 }
41
42 /**
43 * {@inheritdoc}
44 *
45 * @psalm-suppress InvalidNullableReturnType
46 * @psalm-suppress NullableReturnStatement
47 */
48 public function divQ(string $a, string $b) : string
49 {
50 return \bcdiv($a, $b, 0);
51 }
52
53 /**
54 * {@inheritdoc}
55 *
56 * @psalm-suppress InvalidNullableReturnType
57 * @psalm-suppress NullableReturnStatement
58 */
59 public function divR(string $a, string $b) : string
60 {
61 if (version_compare(PHP_VERSION, '7.2') >= 0) {
62 return \bcmod($a, $b, 0);
63 }
64
65 return \bcmod($a, $b);
66 }
67
68 /**
69 * {@inheritdoc}
70 */
71 public function divQR(string $a, string $b) : array
72 {
73 $q = \bcdiv($a, $b, 0);
74
75 if (version_compare(PHP_VERSION, '7.2') >= 0) {
76 $r = \bcmod($a, $b, 0);
77 } else {
78 $r = \bcmod($a, $b);
79 }
80
81 assert($q !== null);
82 assert($r !== null);
83
84 return [$q, $r];
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function pow(string $a, int $e) : string
91 {
92 return \bcpow($a, (string) $e, 0);
93 }
94
95 /**
96 * {@inheritdoc}
97 *
98 * @psalm-suppress InvalidNullableReturnType
99 * @psalm-suppress NullableReturnStatement
100 */
101 public function modPow(string $base, string $exp, string $mod) : string
102 {
103 return \bcpowmod($base, $exp, $mod, 0);
104 }
105
106 /**
107 * {@inheritDoc}
108 *
109 * @psalm-suppress NullableReturnStatement
110 * @psalm-suppress InvalidNullableReturnType
111 */
112 public function sqrt(string $n) : string
113 {
114 return \bcsqrt($n, 0);
115 }
116 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math\Internal\Calculator;
6
7 use Brick\Math\Internal\Calculator;
8
9 /**
10 * Calculator implementation built around the GMP library.
11 *
12 * @internal
13 *
14 * @psalm-immutable
15 */
16 class GmpCalculator extends Calculator
17 {
18 /**
19 * {@inheritdoc}
20 */
21 public function add(string $a, string $b) : string
22 {
23 return \gmp_strval(\gmp_add($a, $b));
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 public function sub(string $a, string $b) : string
30 {
31 return \gmp_strval(\gmp_sub($a, $b));
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function mul(string $a, string $b) : string
38 {
39 return \gmp_strval(\gmp_mul($a, $b));
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function divQ(string $a, string $b) : string
46 {
47 return \gmp_strval(\gmp_div_q($a, $b));
48 }
49
50 /**
51 * {@inheritdoc}
52 */
53 public function divR(string $a, string $b) : string
54 {
55 return \gmp_strval(\gmp_div_r($a, $b));
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 public function divQR(string $a, string $b) : array
62 {
63 [$q, $r] = \gmp_div_qr($a, $b);
64
65 return [
66 \gmp_strval($q),
67 \gmp_strval($r)
68 ];
69 }
70
71 /**
72 * {@inheritdoc}
73 */
74 public function pow(string $a, int $e) : string
75 {
76 return \gmp_strval(\gmp_pow($a, $e));
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function modInverse(string $x, string $m) : ?string
83 {
84 $result = \gmp_invert($x, $m);
85
86 if ($result === false) {
87 return null;
88 }
89
90 return \gmp_strval($result);
91 }
92
93 /**
94 * {@inheritdoc}
95 */
96 public function modPow(string $base, string $exp, string $mod) : string
97 {
98 return \gmp_strval(\gmp_powm($base, $exp, $mod));
99 }
100
101 /**
102 * {@inheritdoc}
103 */
104 public function gcd(string $a, string $b) : string
105 {
106 return \gmp_strval(\gmp_gcd($a, $b));
107 }
108
109 /**
110 * {@inheritdoc}
111 */
112 public function fromBase(string $number, int $base) : string
113 {
114 return \gmp_strval(\gmp_init($number, $base));
115 }
116
117 /**
118 * {@inheritdoc}
119 */
120 public function toBase(string $number, int $base) : string
121 {
122 return \gmp_strval($number, $base);
123 }
124
125 /**
126 * {@inheritdoc}
127 */
128 public function and(string $a, string $b) : string
129 {
130 return \gmp_strval(\gmp_and($a, $b));
131 }
132
133 /**
134 * {@inheritdoc}
135 */
136 public function or(string $a, string $b) : string
137 {
138 return \gmp_strval(\gmp_or($a, $b));
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 public function xor(string $a, string $b) : string
145 {
146 return \gmp_strval(\gmp_xor($a, $b));
147 }
148
149 /**
150 * {@inheritDoc}
151 */
152 public function sqrt(string $n) : string
153 {
154 return \gmp_strval(\gmp_sqrt($n));
155 }
156 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Brick\Math;
6
7 /**
8 * Specifies a rounding behavior for numerical operations capable of discarding precision.
9 *
10 * Each rounding mode indicates how the least significant returned digit of a rounded result
11 * is to be calculated. If fewer digits are returned than the digits needed to represent the
12 * exact numerical result, the discarded digits will be referred to as the discarded fraction
13 * regardless the digits' contribution to the value of the number. In other words, considered
14 * as a numerical value, the discarded fraction could have an absolute value greater than one.
15 */
16 final class RoundingMode
17 {
18 /**
19 * Private constructor. This class is not instantiable.
20 *
21 * @codeCoverageIgnore
22 */
23 private function __construct()
24 {
25 }
26
27 /**
28 * Asserts that the requested operation has an exact result, hence no rounding is necessary.
29 *
30 * If this rounding mode is specified on an operation that yields a result that
31 * cannot be represented at the requested scale, a RoundingNecessaryException is thrown.
32 */
33 public const UNNECESSARY = 0;
34
35 /**
36 * Rounds away from zero.
37 *
38 * Always increments the digit prior to a nonzero discarded fraction.
39 * Note that this rounding mode never decreases the magnitude of the calculated value.
40 */
41 public const UP = 1;
42
43 /**
44 * Rounds towards zero.
45 *
46 * Never increments the digit prior to a discarded fraction (i.e., truncates).
47 * Note that this rounding mode never increases the magnitude of the calculated value.
48 */
49 public const DOWN = 2;
50
51 /**
52 * Rounds towards positive infinity.
53 *
54 * If the result is positive, behaves as for UP; if negative, behaves as for DOWN.
55 * Note that this rounding mode never decreases the calculated value.
56 */
57 public const CEILING = 3;
58
59 /**
60 * Rounds towards negative infinity.
61 *
62 * If the result is positive, behave as for DOWN; if negative, behave as for UP.
63 * Note that this rounding mode never increases the calculated value.
64 */
65 public const FLOOR = 4;
66
67 /**
68 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
69 *
70 * Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN.
71 * Note that this is the rounding mode commonly taught at school.
72 */
73 public const HALF_UP = 5;
74
75 /**
76 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
77 *
78 * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN.
79 */
80 public const HALF_DOWN = 6;
81
82 /**
83 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity.
84 *
85 * If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN.
86 */
87 public const HALF_CEILING = 7;
88
89 /**
90 * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity.
91 *
92 * If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP.
93 */
94 public const HALF_FLOOR = 8;
95
96 /**
97 * Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor.
98 *
99 * Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd;
100 * behaves as for HALF_DOWN if it's even.
101 *
102 * Note that this is the rounding mode that statistically minimizes
103 * cumulative error when applied repeatedly over a sequence of calculations.
104 * It is sometimes known as "Banker's rounding", and is chiefly used in the USA.
105 */
106 public const HALF_EVEN = 9;
107 }
1
2 Copyright (c) Nils Adermann, Jordi Boggiano
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is furnished
9 to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21
1 <?php
2
3 // autoload_classmap.php @generated by Composer
4
5 $vendorDir = dirname(dirname(__FILE__));
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
10 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
11 'JsonException' => $vendorDir . '/symfony/polyfill-php73/Resources/stubs/JsonException.php',
12 'Normalizer' => $vendorDir . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
13 'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
14 'ReturnTypeWillChange' => $vendorDir . '/symfony/polyfill-php81/Resources/stubs/ReturnTypeWillChange.php',
15 'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
16 'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
17 'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
18 );
1 <?php
2
3 // autoload_files.php @generated by Composer
4
5 $vendorDir = dirname(dirname(__FILE__));
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
10 '6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
11 '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
12 'a1105708a18b76903365ca1c4aa61b02' => $vendorDir . '/symfony/translation/Resources/functions.php',
13 '60799491728b879e74601d83e38b2cad' => $vendorDir . '/illuminate/collections/helpers.php',
14 '0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
15 '320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
16 '72579e7bd17821bb1321b87411366eae' => $vendorDir . '/illuminate/support/helpers.php',
17 'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
18 '25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php',
19 'f598d06aa772fa33d905e87be6398fb1' => $vendorDir . '/symfony/polyfill-intl-idn/bootstrap.php',
20 '667aeda72477189d0494fecd327c3641' => $vendorDir . '/symfony/var-dumper/Resources/functions/dump.php',
21 '23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php',
22 'ef65a1626449d89d0811cf9befce46f0' => $vendorDir . '/illuminate/events/functions.php',
23 '8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
24 '7018e3dbeb54682c59da60bb2ff4f971' => $vendorDir . '/roots/support/helpers.php',
25 'e39a8b23c42d4e1452234d762b03835a' => $vendorDir . '/ramsey/uuid/src/functions.php',
26 'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
27 '1d3e394e13b0f60fc9509fa2e09fa96e' => $vendorDir . '/roots/acorn/src/Roots/helpers.php',
28 '343d14c26e6742d3d4650d589923312e' => $vendorDir . '/roots/acorn/src/Roots/globals.php',
29 );
1 <?php
2
3 // autoload_namespaces.php @generated by Composer
4
5 $vendorDir = dirname(dirname(__FILE__));
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 );
1 <?php
2
3 // autoload_psr4.php @generated by Composer
4
5 $vendorDir = dirname(dirname(__FILE__));
6 $baseDir = dirname($vendorDir);
7
8 return array(
9 'voku\\' => array($vendorDir . '/voku/portable-ascii/src/voku'),
10 'Symfony\\Polyfill\\Php81\\' => array($vendorDir . '/symfony/polyfill-php81'),
11 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
12 'Symfony\\Polyfill\\Php73\\' => array($vendorDir . '/symfony/polyfill-php73'),
13 'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
14 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
15 'Symfony\\Polyfill\\Intl\\Normalizer\\' => array($vendorDir . '/symfony/polyfill-intl-normalizer'),
16 'Symfony\\Polyfill\\Intl\\Idn\\' => array($vendorDir . '/symfony/polyfill-intl-idn'),
17 'Symfony\\Polyfill\\Intl\\Grapheme\\' => array($vendorDir . '/symfony/polyfill-intl-grapheme'),
18 'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
19 'Symfony\\Contracts\\Translation\\' => array($vendorDir . '/symfony/translation-contracts'),
20 'Symfony\\Contracts\\Service\\' => array($vendorDir . '/symfony/service-contracts'),
21 'Symfony\\Contracts\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher-contracts'),
22 'Symfony\\Component\\VarDumper\\' => array($vendorDir . '/symfony/var-dumper'),
23 'Symfony\\Component\\Translation\\' => array($vendorDir . '/symfony/translation'),
24 'Symfony\\Component\\String\\' => array($vendorDir . '/symfony/string'),
25 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
26 'Symfony\\Component\\Mime\\' => array($vendorDir . '/symfony/mime'),
27 'Symfony\\Component\\HttpKernel\\' => array($vendorDir . '/symfony/http-kernel'),
28 'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'),
29 'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
30 'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
31 'Symfony\\Component\\ErrorHandler\\' => array($vendorDir . '/symfony/error-handler'),
32 'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
33 'Roots\\' => array($vendorDir . '/roots/acorn/src/Roots'),
34 'Ramsey\\Uuid\\' => array($vendorDir . '/ramsey/uuid/src'),
35 'Ramsey\\Collection\\' => array($vendorDir . '/ramsey/collection/src'),
36 'Psr\\SimpleCache\\' => array($vendorDir . '/psr/simple-cache/src'),
37 'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
38 'Psr\\EventDispatcher\\' => array($vendorDir . '/psr/event-dispatcher/src'),
39 'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
40 'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
41 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
42 'League\\MimeTypeDetection\\' => array($vendorDir . '/league/mime-type-detection/src'),
43 'League\\Flysystem\\' => array($vendorDir . '/league/flysystem/src'),
44 'Illuminate\\View\\' => array($vendorDir . '/illuminate/view'),
45 'Illuminate\\Support\\' => array($vendorDir . '/illuminate/macroable', $vendorDir . '/illuminate/collections', $vendorDir . '/illuminate/support'),
46 'Illuminate\\Session\\' => array($vendorDir . '/illuminate/session'),
47 'Illuminate\\Pipeline\\' => array($vendorDir . '/illuminate/pipeline'),
48 'Illuminate\\Log\\' => array($vendorDir . '/illuminate/log'),
49 'Illuminate\\Http\\' => array($vendorDir . '/illuminate/http'),
50 'Illuminate\\Filesystem\\' => array($vendorDir . '/illuminate/filesystem'),
51 'Illuminate\\Events\\' => array($vendorDir . '/illuminate/events'),
52 'Illuminate\\Contracts\\' => array($vendorDir . '/illuminate/contracts'),
53 'Illuminate\\Container\\' => array($vendorDir . '/illuminate/container'),
54 'Illuminate\\Console\\' => array($vendorDir . '/illuminate/console'),
55 'Illuminate\\Config\\' => array($vendorDir . '/illuminate/config'),
56 'Illuminate\\Cache\\' => array($vendorDir . '/illuminate/cache'),
57 'Illuminate\\Bus\\' => array($vendorDir . '/illuminate/bus'),
58 'Illuminate\\' => array($vendorDir . '/roots/acorn/src/Illuminate'),
59 'GrahamCampbell\\ResultType\\' => array($vendorDir . '/graham-campbell/result-type/src'),
60 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
61 'Doctrine\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib/Doctrine/Inflector'),
62 'Carbon\\' => array($vendorDir . '/nesbot/carbon/src/Carbon'),
63 'Brick\\Math\\' => array($vendorDir . '/brick/math/src'),
64 );
1 <?php
2
3 // autoload_real.php @generated by Composer
4
5 class ComposerAutoloaderInit05c31aef1015133fb9677718a400b237
6 {
7 private static $loader;
8
9 public static function loadClassLoader($class)
10 {
11 if ('Composer\Autoload\ClassLoader' === $class) {
12 require __DIR__ . '/ClassLoader.php';
13 }
14 }
15
16 /**
17 * @return \Composer\Autoload\ClassLoader
18 */
19 public static function getLoader()
20 {
21 if (null !== self::$loader) {
22 return self::$loader;
23 }
24
25 require __DIR__ . '/platform_check.php';
26
27 spl_autoload_register(array('ComposerAutoloaderInit05c31aef1015133fb9677718a400b237', 'loadClassLoader'), true, true);
28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
29 spl_autoload_unregister(array('ComposerAutoloaderInit05c31aef1015133fb9677718a400b237', 'loadClassLoader'));
30
31 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
32 if ($useStaticLoader) {
33 require __DIR__ . '/autoload_static.php';
34
35 call_user_func(\Composer\Autoload\ComposerStaticInit05c31aef1015133fb9677718a400b237::getInitializer($loader));
36 } else {
37 $map = require __DIR__ . '/autoload_namespaces.php';
38 foreach ($map as $namespace => $path) {
39 $loader->set($namespace, $path);
40 }
41
42 $map = require __DIR__ . '/autoload_psr4.php';
43 foreach ($map as $namespace => $path) {
44 $loader->setPsr4($namespace, $path);
45 }
46
47 $classMap = require __DIR__ . '/autoload_classmap.php';
48 if ($classMap) {
49 $loader->addClassMap($classMap);
50 }
51 }
52
53 $loader->register(true);
54
55 if ($useStaticLoader) {
56 $includeFiles = Composer\Autoload\ComposerStaticInit05c31aef1015133fb9677718a400b237::$files;
57 } else {
58 $includeFiles = require __DIR__ . '/autoload_files.php';
59 }
60 foreach ($includeFiles as $fileIdentifier => $file) {
61 composerRequire05c31aef1015133fb9677718a400b237($fileIdentifier, $file);
62 }
63
64 return $loader;
65 }
66 }
67
68 function composerRequire05c31aef1015133fb9677718a400b237($fileIdentifier, $file)
69 {
70 if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
71 require $file;
72
73 $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
74 }
75 }
This diff could not be displayed because it is too large.
1 <?php
2
3 // platform_check.php @generated by Composer
4
5 $issues = array();
6
7 if (!(PHP_VERSION_ID >= 70400)) {
8 $issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';
9 }
10
11 if ($issues) {
12 if (!headers_sent()) {
13 header('HTTP/1.1 500 Internal Server Error');
14 }
15 if (!ini_get('display_errors')) {
16 if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
17 fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
18 } elseif (!headers_sent()) {
19 echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
20 }
21 }
22 trigger_error(
23 'Composer detected issues in your platform: ' . implode(' ', $issues),
24 E_USER_ERROR
25 );
26 }
1 Copyright (c) 2006-2015 Doctrine Project
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in
5 the Software without restriction, including without limitation the rights to
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 of the Software, and to permit persons to whom the Software is furnished to do
8 so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE.
1 # Doctrine Inflector
2
3 Doctrine Inflector is a small library that can perform string manipulations
4 with regard to uppercase/lowercase and singular/plural forms of words.
5
6 [![Build Status](https://github.com/doctrine/inflector/workflows/Continuous%20Integration/badge.svg)](https://github.com/doctrine/inflector/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.0.x)
7 [![Code Coverage](https://codecov.io/gh/doctrine/inflector/branch/2.0.x/graph/badge.svg)](https://codecov.io/gh/doctrine/inflector/branch/2.0.x)
1 {
2 "name": "doctrine/inflector",
3 "type": "library",
4 "description": "PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.",
5 "keywords": ["php", "strings", "words", "manipulation", "inflector", "inflection", "uppercase", "lowercase", "singular", "plural"],
6 "homepage": "https://www.doctrine-project.org/projects/inflector.html",
7 "license": "MIT",
8 "authors": [
9 {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
10 {"name": "Roman Borschel", "email": "roman@code-factory.org"},
11 {"name": "Benjamin Eberlei", "email": "kontakt@beberlei.de"},
12 {"name": "Jonathan Wage", "email": "jonwage@gmail.com"},
13 {"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
14 ],
15 "require": {
16 "php": "^7.2 || ^8.0"
17 },
18 "require-dev": {
19 "doctrine/coding-standard": "^9",
20 "phpstan/phpstan": "^1.8",
21 "phpstan/phpstan-phpunit": "^1.1",
22 "phpstan/phpstan-strict-rules": "^1.3",
23 "phpunit/phpunit": "^8.5 || ^9.5",
24 "vimeo/psalm": "^4.25"
25 },
26 "autoload": {
27 "psr-4": {
28 "Doctrine\\Inflector\\": "lib/Doctrine/Inflector"
29 }
30 },
31 "autoload-dev": {
32 "psr-4": {
33 "Doctrine\\Tests\\Inflector\\": "tests/Doctrine/Tests/Inflector"
34 }
35 },
36 "config": {
37 "allow-plugins": {
38 "dealerdirect/phpcodesniffer-composer-installer": true
39 }
40 }
41 }
1 Introduction
2 ============
3
4 The Doctrine Inflector has methods for inflecting text. The features include pluralization,
5 singularization, converting between camelCase and under_score and capitalizing
6 words.
7
8 Installation
9 ============
10
11 You can install the Inflector with composer:
12
13 .. code-block:: console
14
15 $ composer require doctrine/inflector
16
17 Usage
18 =====
19
20 Using the inflector is easy, you can create a new ``Doctrine\Inflector\Inflector`` instance by using
21 the ``Doctrine\Inflector\InflectorFactory`` class:
22
23 .. code-block:: php
24
25 use Doctrine\Inflector\InflectorFactory;
26
27 $inflector = InflectorFactory::create()->build();
28
29 By default it will create an English inflector. If you want to use another language, just pass the language
30 you want to create an inflector for to the ``createForLanguage()`` method:
31
32 .. code-block:: php
33
34 use Doctrine\Inflector\InflectorFactory;
35 use Doctrine\Inflector\Language;
36
37 $inflector = InflectorFactory::createForLanguage(Language::SPANISH)->build();
38
39 The supported languages are as follows:
40
41 - ``Language::ENGLISH``
42 - ``Language::FRENCH``
43 - ``Language::NORWEGIAN_BOKMAL``
44 - ``Language::PORTUGUESE``
45 - ``Language::SPANISH``
46 - ``Language::TURKISH``
47
48 If you want to manually construct the inflector instead of using a factory, you can do so like this:
49
50 .. code-block:: php
51
52 use Doctrine\Inflector\CachedWordInflector;
53 use Doctrine\Inflector\RulesetInflector;
54 use Doctrine\Inflector\Rules\English;
55
56 $inflector = new Inflector(
57 new CachedWordInflector(new RulesetInflector(
58 English\Rules::getSingularRuleset()
59 )),
60 new CachedWordInflector(new RulesetInflector(
61 English\Rules::getPluralRuleset()
62 ))
63 );
64
65 Adding Languages
66 ----------------
67
68 If you are interested in adding support for your language, take a look at the other languages defined in the
69 ``Doctrine\Inflector\Rules`` namespace and the tests located in ``Doctrine\Tests\Inflector\Rules``. You can copy
70 one of the languages and update the rules for your language.
71
72 Once you have done this, send a pull request to the ``doctrine/inflector`` repository with the additions.
73
74 Custom Setup
75 ============
76
77 If you want to setup custom singular and plural rules, you can configure these in the factory:
78
79 .. code-block:: php
80
81 use Doctrine\Inflector\InflectorFactory;
82 use Doctrine\Inflector\Rules\Pattern;
83 use Doctrine\Inflector\Rules\Patterns;
84 use Doctrine\Inflector\Rules\Ruleset;
85 use Doctrine\Inflector\Rules\Substitution;
86 use Doctrine\Inflector\Rules\Substitutions;
87 use Doctrine\Inflector\Rules\Transformation;
88 use Doctrine\Inflector\Rules\Transformations;
89 use Doctrine\Inflector\Rules\Word;
90
91 $inflector = InflectorFactory::create()
92 ->withSingularRules(
93 new Ruleset(
94 new Transformations(
95 new Transformation(new Pattern('/^(bil)er$/i'), '\1'),
96 new Transformation(new Pattern('/^(inflec|contribu)tors$/i'), '\1ta')
97 ),
98 new Patterns(new Pattern('singulars')),
99 new Substitutions(new Substitution(new Word('spins'), new Word('spinor')))
100 )
101 )
102 ->withPluralRules(
103 new Ruleset(
104 new Transformations(
105 new Transformation(new Pattern('^(bil)er$'), '\1'),
106 new Transformation(new Pattern('^(inflec|contribu)tors$'), '\1ta')
107 ),
108 new Patterns(new Pattern('noflect'), new Pattern('abtuse')),
109 new Substitutions(
110 new Substitution(new Word('amaze'), new Word('amazable')),
111 new Substitution(new Word('phone'), new Word('phonezes'))
112 )
113 )
114 )
115 ->build();
116
117 No operation inflector
118 ----------------------
119
120 The ``Doctrine\Inflector\NoopWordInflector`` may be used to configure an inflector that doesn't perform any operation for
121 pluralization and/or singularization. If will simply return the input as output.
122
123 This is an implementation of the `Null Object design pattern <https://sourcemaking.com/design_patterns/null_object>`_.
124
125 .. code-block:: php
126
127 use Doctrine\Inflector\Inflector;
128 use Doctrine\Inflector\NoopWordInflector;
129
130 $inflector = new Inflector(new NoopWordInflector(), new NoopWordInflector());
131
132 Tableize
133 ========
134
135 Converts ``ModelName`` to ``model_name``:
136
137 .. code-block:: php
138
139 echo $inflector->tableize('ModelName'); // model_name
140
141 Classify
142 ========
143
144 Converts ``model_name`` to ``ModelName``:
145
146 .. code-block:: php
147
148 echo $inflector->classify('model_name'); // ModelName
149
150 Camelize
151 ========
152
153 This method uses `Classify`_ and then converts the first character to lowercase:
154
155 .. code-block:: php
156
157 echo $inflector->camelize('model_name'); // modelName
158
159 Capitalize
160 ==========
161
162 Takes a string and capitalizes all of the words, like PHP's built-in
163 ``ucwords`` function. This extends that behavior, however, by allowing the
164 word delimiters to be configured, rather than only separating on
165 whitespace.
166
167 Here is an example:
168
169 .. code-block:: php
170
171 $string = 'top-o-the-morning to all_of_you!';
172
173 echo $inflector->capitalize($string); // Top-O-The-Morning To All_of_you!
174
175 echo $inflector->capitalize($string, '-_ '); // Top-O-The-Morning To All_Of_You!
176
177 Pluralize
178 =========
179
180 Returns a word in plural form.
181
182 .. code-block:: php
183
184 echo $inflector->pluralize('browser'); // browsers
185
186 Singularize
187 ===========
188
189 Returns a word in singular form.
190
191 .. code-block:: php
192
193 echo $inflector->singularize('browsers'); // browser
194
195 Urlize
196 ======
197
198 Generate a URL friendly string from a string of text:
199
200 .. code-block:: php
201
202 echo $inflector->urlize('My first blog post'); // my-first-blog-post
203
204 Unaccent
205 ========
206
207 You can unaccent a string of text using the ``unaccent()`` method:
208
209 .. code-block:: php
210
211 echo $inflector->unaccent('año'); // ano
212
213 Legacy API
214 ==========
215
216 The API present in Inflector 1.x is still available, but will be deprecated in a future release and dropped for 3.0.
217 Support for languages other than English is available in the 2.0 API only.
218
219 Acknowledgements
220 ================
221
222 The language rules in this library have been adapted from several different sources, including but not limited to:
223
224 - `Ruby On Rails Inflector <http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html>`_
225 - `ICanBoogie Inflector <https://github.com/ICanBoogie/Inflector>`_
226 - `CakePHP Inflector <https://book.cakephp.org/3.0/en/core-libraries/inflector.html>`_
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 class CachedWordInflector implements WordInflector
8 {
9 /** @var WordInflector */
10 private $wordInflector;
11
12 /** @var string[] */
13 private $cache = [];
14
15 public function __construct(WordInflector $wordInflector)
16 {
17 $this->wordInflector = $wordInflector;
18 }
19
20 public function inflect(string $word): string
21 {
22 return $this->cache[$word] ?? $this->cache[$word] = $this->wordInflector->inflect($word);
23 }
24 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 use Doctrine\Inflector\Rules\Ruleset;
8
9 use function array_unshift;
10
11 abstract class GenericLanguageInflectorFactory implements LanguageInflectorFactory
12 {
13 /** @var Ruleset[] */
14 private $singularRulesets = [];
15
16 /** @var Ruleset[] */
17 private $pluralRulesets = [];
18
19 final public function __construct()
20 {
21 $this->singularRulesets[] = $this->getSingularRuleset();
22 $this->pluralRulesets[] = $this->getPluralRuleset();
23 }
24
25 final public function build(): Inflector
26 {
27 return new Inflector(
28 new CachedWordInflector(new RulesetInflector(
29 ...$this->singularRulesets
30 )),
31 new CachedWordInflector(new RulesetInflector(
32 ...$this->pluralRulesets
33 ))
34 );
35 }
36
37 final public function withSingularRules(?Ruleset $singularRules, bool $reset = false): LanguageInflectorFactory
38 {
39 if ($reset) {
40 $this->singularRulesets = [];
41 }
42
43 if ($singularRules instanceof Ruleset) {
44 array_unshift($this->singularRulesets, $singularRules);
45 }
46
47 return $this;
48 }
49
50 final public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): LanguageInflectorFactory
51 {
52 if ($reset) {
53 $this->pluralRulesets = [];
54 }
55
56 if ($pluralRules instanceof Ruleset) {
57 array_unshift($this->pluralRulesets, $pluralRules);
58 }
59
60 return $this;
61 }
62
63 abstract protected function getSingularRuleset(): Ruleset;
64
65 abstract protected function getPluralRuleset(): Ruleset;
66 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 use Doctrine\Inflector\Rules\English;
8 use Doctrine\Inflector\Rules\French;
9 use Doctrine\Inflector\Rules\NorwegianBokmal;
10 use Doctrine\Inflector\Rules\Portuguese;
11 use Doctrine\Inflector\Rules\Spanish;
12 use Doctrine\Inflector\Rules\Turkish;
13 use InvalidArgumentException;
14
15 use function sprintf;
16
17 final class InflectorFactory
18 {
19 public static function create(): LanguageInflectorFactory
20 {
21 return self::createForLanguage(Language::ENGLISH);
22 }
23
24 public static function createForLanguage(string $language): LanguageInflectorFactory
25 {
26 switch ($language) {
27 case Language::ENGLISH:
28 return new English\InflectorFactory();
29
30 case Language::FRENCH:
31 return new French\InflectorFactory();
32
33 case Language::NORWEGIAN_BOKMAL:
34 return new NorwegianBokmal\InflectorFactory();
35
36 case Language::PORTUGUESE:
37 return new Portuguese\InflectorFactory();
38
39 case Language::SPANISH:
40 return new Spanish\InflectorFactory();
41
42 case Language::TURKISH:
43 return new Turkish\InflectorFactory();
44
45 default:
46 throw new InvalidArgumentException(sprintf(
47 'Language "%s" is not supported.',
48 $language
49 ));
50 }
51 }
52 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 final class Language
8 {
9 public const ENGLISH = 'english';
10 public const FRENCH = 'french';
11 public const NORWEGIAN_BOKMAL = 'norwegian-bokmal';
12 public const PORTUGUESE = 'portuguese';
13 public const SPANISH = 'spanish';
14 public const TURKISH = 'turkish';
15
16 private function __construct()
17 {
18 }
19 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 use Doctrine\Inflector\Rules\Ruleset;
8
9 interface LanguageInflectorFactory
10 {
11 /**
12 * Applies custom rules for singularisation
13 *
14 * @param bool $reset If true, will unset default inflections for all new rules
15 *
16 * @return $this
17 */
18 public function withSingularRules(?Ruleset $singularRules, bool $reset = false): self;
19
20 /**
21 * Applies custom rules for pluralisation
22 *
23 * @param bool $reset If true, will unset default inflections for all new rules
24 *
25 * @return $this
26 */
27 public function withPluralRules(?Ruleset $pluralRules, bool $reset = false): self;
28
29 /**
30 * Builds the inflector instance with all applicable rules
31 */
32 public function build(): Inflector;
33 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 class NoopWordInflector implements WordInflector
8 {
9 public function inflect(string $word): string
10 {
11 return $word;
12 }
13 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\English;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\English;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\English;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17
18 yield new Pattern('.*ss');
19 yield new Pattern('clothes');
20 yield new Pattern('data');
21 yield new Pattern('fascia');
22 yield new Pattern('fuchsia');
23 yield new Pattern('galleria');
24 yield new Pattern('mafia');
25 yield new Pattern('militia');
26 yield new Pattern('pants');
27 yield new Pattern('petunia');
28 yield new Pattern('sepia');
29 yield new Pattern('trivia');
30 yield new Pattern('utopia');
31 }
32
33 /**
34 * @return Pattern[]
35 */
36 public static function getPlural(): iterable
37 {
38 yield from self::getDefault();
39
40 yield new Pattern('people');
41 yield new Pattern('trivia');
42 yield new Pattern('\w+ware$');
43 yield new Pattern('media');
44 }
45
46 /**
47 * @return Pattern[]
48 */
49 private static function getDefault(): iterable
50 {
51 yield new Pattern('\w+media');
52 yield new Pattern('advice');
53 yield new Pattern('aircraft');
54 yield new Pattern('amoyese');
55 yield new Pattern('art');
56 yield new Pattern('audio');
57 yield new Pattern('baggage');
58 yield new Pattern('bison');
59 yield new Pattern('borghese');
60 yield new Pattern('bream');
61 yield new Pattern('breeches');
62 yield new Pattern('britches');
63 yield new Pattern('buffalo');
64 yield new Pattern('butter');
65 yield new Pattern('cantus');
66 yield new Pattern('carp');
67 yield new Pattern('cattle');
68 yield new Pattern('chassis');
69 yield new Pattern('clippers');
70 yield new Pattern('clothing');
71 yield new Pattern('coal');
72 yield new Pattern('cod');
73 yield new Pattern('coitus');
74 yield new Pattern('compensation');
75 yield new Pattern('congoese');
76 yield new Pattern('contretemps');
77 yield new Pattern('coreopsis');
78 yield new Pattern('corps');
79 yield new Pattern('cotton');
80 yield new Pattern('data');
81 yield new Pattern('debris');
82 yield new Pattern('deer');
83 yield new Pattern('diabetes');
84 yield new Pattern('djinn');
85 yield new Pattern('education');
86 yield new Pattern('eland');
87 yield new Pattern('elk');
88 yield new Pattern('emoji');
89 yield new Pattern('equipment');
90 yield new Pattern('evidence');
91 yield new Pattern('faroese');
92 yield new Pattern('feedback');
93 yield new Pattern('fish');
94 yield new Pattern('flounder');
95 yield new Pattern('flour');
96 yield new Pattern('foochowese');
97 yield new Pattern('food');
98 yield new Pattern('furniture');
99 yield new Pattern('gallows');
100 yield new Pattern('genevese');
101 yield new Pattern('genoese');
102 yield new Pattern('gilbertese');
103 yield new Pattern('gold');
104 yield new Pattern('headquarters');
105 yield new Pattern('herpes');
106 yield new Pattern('hijinks');
107 yield new Pattern('homework');
108 yield new Pattern('hottentotese');
109 yield new Pattern('impatience');
110 yield new Pattern('information');
111 yield new Pattern('innings');
112 yield new Pattern('jackanapes');
113 yield new Pattern('jeans');
114 yield new Pattern('jedi');
115 yield new Pattern('kin');
116 yield new Pattern('kiplingese');
117 yield new Pattern('knowledge');
118 yield new Pattern('kongoese');
119 yield new Pattern('leather');
120 yield new Pattern('love');
121 yield new Pattern('lucchese');
122 yield new Pattern('luggage');
123 yield new Pattern('mackerel');
124 yield new Pattern('Maltese');
125 yield new Pattern('management');
126 yield new Pattern('metadata');
127 yield new Pattern('mews');
128 yield new Pattern('money');
129 yield new Pattern('moose');
130 yield new Pattern('mumps');
131 yield new Pattern('music');
132 yield new Pattern('nankingese');
133 yield new Pattern('news');
134 yield new Pattern('nexus');
135 yield new Pattern('niasese');
136 yield new Pattern('nutrition');
137 yield new Pattern('offspring');
138 yield new Pattern('oil');
139 yield new Pattern('patience');
140 yield new Pattern('pekingese');
141 yield new Pattern('piedmontese');
142 yield new Pattern('pincers');
143 yield new Pattern('pistoiese');
144 yield new Pattern('plankton');
145 yield new Pattern('pliers');
146 yield new Pattern('pokemon');
147 yield new Pattern('police');
148 yield new Pattern('polish');
149 yield new Pattern('portuguese');
150 yield new Pattern('proceedings');
151 yield new Pattern('progress');
152 yield new Pattern('rabies');
153 yield new Pattern('rain');
154 yield new Pattern('research');
155 yield new Pattern('rhinoceros');
156 yield new Pattern('rice');
157 yield new Pattern('salmon');
158 yield new Pattern('sand');
159 yield new Pattern('sarawakese');
160 yield new Pattern('scissors');
161 yield new Pattern('sea[- ]bass');
162 yield new Pattern('series');
163 yield new Pattern('shavese');
164 yield new Pattern('shears');
165 yield new Pattern('sheep');
166 yield new Pattern('siemens');
167 yield new Pattern('silk');
168 yield new Pattern('sms');
169 yield new Pattern('soap');
170 yield new Pattern('social media');
171 yield new Pattern('spam');
172 yield new Pattern('species');
173 yield new Pattern('staff');
174 yield new Pattern('sugar');
175 yield new Pattern('swine');
176 yield new Pattern('talent');
177 yield new Pattern('toothpaste');
178 yield new Pattern('traffic');
179 yield new Pattern('travel');
180 yield new Pattern('trousers');
181 yield new Pattern('trout');
182 yield new Pattern('tuna');
183 yield new Pattern('us');
184 yield new Pattern('vermontese');
185 yield new Pattern('vinegar');
186 yield new Pattern('weather');
187 yield new Pattern('wenchowese');
188 yield new Pattern('wheat');
189 yield new Pattern('whiting');
190 yield new Pattern('wildebeest');
191 yield new Pattern('wood');
192 yield new Pattern('wool');
193 yield new Pattern('yengeese');
194 }
195 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\French;
6
7 use Doctrine\Inflector\Rules\Pattern;
8 use Doctrine\Inflector\Rules\Substitution;
9 use Doctrine\Inflector\Rules\Transformation;
10 use Doctrine\Inflector\Rules\Word;
11
12 class Inflectible
13 {
14 /**
15 * @return Transformation[]
16 */
17 public static function getSingular(): iterable
18 {
19 yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/'), '\1ail');
20 yield new Transformation(new Pattern('/ails$/'), 'ail');
21 yield new Transformation(new Pattern('/(journ|chev)aux$/'), '\1al');
22 yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/'), '\1');
23 yield new Transformation(new Pattern('/s$/'), '');
24 }
25
26 /**
27 * @return Transformation[]
28 */
29 public static function getPlural(): iterable
30 {
31 yield new Transformation(new Pattern('/(s|x|z)$/'), '\1');
32 yield new Transformation(new Pattern('/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/'), '\1aux');
33 yield new Transformation(new Pattern('/ail$/'), 'ails');
34 yield new Transformation(new Pattern('/(chacal|carnaval|festival|récital)$/'), '\1s');
35 yield new Transformation(new Pattern('/al$/'), 'aux');
36 yield new Transformation(new Pattern('/(bleu|émeu|landau|pneu|sarrau)$/'), '\1s');
37 yield new Transformation(new Pattern('/(bijou|caillou|chou|genou|hibou|joujou|lieu|pou|au|eu|eau)$/'), '\1x');
38 yield new Transformation(new Pattern('/$/'), 's');
39 }
40
41 /**
42 * @return Substitution[]
43 */
44 public static function getIrregular(): iterable
45 {
46 yield new Substitution(new Word('monsieur'), new Word('messieurs'));
47 yield new Substitution(new Word('madame'), new Word('mesdames'));
48 yield new Substitution(new Word('mademoiselle'), new Word('mesdemoiselles'));
49 }
50 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\French;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\French;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\French;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17 }
18
19 /**
20 * @return Pattern[]
21 */
22 public static function getPlural(): iterable
23 {
24 yield from self::getDefault();
25 }
26
27 /**
28 * @return Pattern[]
29 */
30 private static function getDefault(): iterable
31 {
32 yield new Pattern('');
33 }
34 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\NorwegianBokmal;
6
7 use Doctrine\Inflector\Rules\Pattern;
8 use Doctrine\Inflector\Rules\Substitution;
9 use Doctrine\Inflector\Rules\Transformation;
10 use Doctrine\Inflector\Rules\Word;
11
12 class Inflectible
13 {
14 /**
15 * @return Transformation[]
16 */
17 public static function getSingular(): iterable
18 {
19 yield new Transformation(new Pattern('/re$/i'), 'r');
20 yield new Transformation(new Pattern('/er$/i'), '');
21 }
22
23 /**
24 * @return Transformation[]
25 */
26 public static function getPlural(): iterable
27 {
28 yield new Transformation(new Pattern('/e$/i'), 'er');
29 yield new Transformation(new Pattern('/r$/i'), 're');
30 yield new Transformation(new Pattern('/$/'), 'er');
31 }
32
33 /**
34 * @return Substitution[]
35 */
36 public static function getIrregular(): iterable
37 {
38 yield new Substitution(new Word('konto'), new Word('konti'));
39 }
40 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\NorwegianBokmal;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\NorwegianBokmal;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\NorwegianBokmal;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17 }
18
19 /**
20 * @return Pattern[]
21 */
22 public static function getPlural(): iterable
23 {
24 yield from self::getDefault();
25 }
26
27 /**
28 * @return Pattern[]
29 */
30 private static function getDefault(): iterable
31 {
32 yield new Pattern('barn');
33 yield new Pattern('fjell');
34 yield new Pattern('hus');
35 }
36 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 use function preg_match;
8
9 final class Pattern
10 {
11 /** @var string */
12 private $pattern;
13
14 /** @var string */
15 private $regex;
16
17 public function __construct(string $pattern)
18 {
19 $this->pattern = $pattern;
20
21 if (isset($this->pattern[0]) && $this->pattern[0] === '/') {
22 $this->regex = $this->pattern;
23 } else {
24 $this->regex = '/' . $this->pattern . '/i';
25 }
26 }
27
28 public function getPattern(): string
29 {
30 return $this->pattern;
31 }
32
33 public function getRegex(): string
34 {
35 return $this->regex;
36 }
37
38 public function matches(string $word): bool
39 {
40 return preg_match($this->getRegex(), $word) === 1;
41 }
42 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 use function array_map;
8 use function implode;
9 use function preg_match;
10
11 class Patterns
12 {
13 /** @var Pattern[] */
14 private $patterns;
15
16 /** @var string */
17 private $regex;
18
19 public function __construct(Pattern ...$patterns)
20 {
21 $this->patterns = $patterns;
22
23 $patterns = array_map(static function (Pattern $pattern): string {
24 return $pattern->getPattern();
25 }, $this->patterns);
26
27 $this->regex = '/^(?:' . implode('|', $patterns) . ')$/i';
28 }
29
30 public function matches(string $word): bool
31 {
32 return preg_match($this->regex, $word, $regs) === 1;
33 }
34 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Portuguese;
6
7 use Doctrine\Inflector\Rules\Pattern;
8 use Doctrine\Inflector\Rules\Substitution;
9 use Doctrine\Inflector\Rules\Transformation;
10 use Doctrine\Inflector\Rules\Word;
11
12 class Inflectible
13 {
14 /**
15 * @return Transformation[]
16 */
17 public static function getSingular(): iterable
18 {
19 yield new Transformation(new Pattern('/^(g|)ases$/i'), '\1ás');
20 yield new Transformation(new Pattern('/(japon|escoc|ingl|dinamarqu|fregu|portugu)eses$/i'), '\1ês');
21 yield new Transformation(new Pattern('/(ae|ao|oe)s$/'), 'ao');
22 yield new Transformation(new Pattern('/(ãe|ão|õe)s$/'), 'ão');
23 yield new Transformation(new Pattern('/^(.*[^s]s)es$/i'), '\1');
24 yield new Transformation(new Pattern('/sses$/i'), 'sse');
25 yield new Transformation(new Pattern('/ns$/i'), 'm');
26 yield new Transformation(new Pattern('/(r|t|f|v)is$/i'), '\1il');
27 yield new Transformation(new Pattern('/uis$/i'), 'ul');
28 yield new Transformation(new Pattern('/ois$/i'), 'ol');
29 yield new Transformation(new Pattern('/eis$/i'), 'ei');
30 yield new Transformation(new Pattern('/éis$/i'), 'el');
31 yield new Transformation(new Pattern('/([^p])ais$/i'), '\1al');
32 yield new Transformation(new Pattern('/(r|z)es$/i'), '\1');
33 yield new Transformation(new Pattern('/^(á|gá)s$/i'), '\1s');
34 yield new Transformation(new Pattern('/([^ê])s$/i'), '\1');
35 }
36
37 /**
38 * @return Transformation[]
39 */
40 public static function getPlural(): iterable
41 {
42 yield new Transformation(new Pattern('/^(alem|c|p)ao$/i'), '\1aes');
43 yield new Transformation(new Pattern('/^(irm|m)ao$/i'), '\1aos');
44 yield new Transformation(new Pattern('/ao$/i'), 'oes');
45 yield new Transformation(new Pattern('/^(alem|c|p)ão$/i'), '\1ães');
46 yield new Transformation(new Pattern('/^(irm|m)ão$/i'), '\1ãos');
47 yield new Transformation(new Pattern('/ão$/i'), 'ões');
48 yield new Transformation(new Pattern('/^(|g)ás$/i'), '\1ases');
49 yield new Transformation(new Pattern('/^(japon|escoc|ingl|dinamarqu|fregu|portugu)ês$/i'), '\1eses');
50 yield new Transformation(new Pattern('/m$/i'), 'ns');
51 yield new Transformation(new Pattern('/([^aeou])il$/i'), '\1is');
52 yield new Transformation(new Pattern('/ul$/i'), 'uis');
53 yield new Transformation(new Pattern('/ol$/i'), 'ois');
54 yield new Transformation(new Pattern('/el$/i'), 'eis');
55 yield new Transformation(new Pattern('/al$/i'), 'ais');
56 yield new Transformation(new Pattern('/(z|r)$/i'), '\1es');
57 yield new Transformation(new Pattern('/(s)$/i'), '\1');
58 yield new Transformation(new Pattern('/$/'), 's');
59 }
60
61 /**
62 * @return Substitution[]
63 */
64 public static function getIrregular(): iterable
65 {
66 yield new Substitution(new Word('abdomen'), new Word('abdomens'));
67 yield new Substitution(new Word('alemão'), new Word('alemães'));
68 yield new Substitution(new Word('artesã'), new Word('artesãos'));
69 yield new Substitution(new Word('álcool'), new Word('álcoois'));
70 yield new Substitution(new Word('árvore'), new Word('árvores'));
71 yield new Substitution(new Word('bencão'), new Word('bencãos'));
72 yield new Substitution(new Word('cão'), new Word('cães'));
73 yield new Substitution(new Word('campus'), new Word('campi'));
74 yield new Substitution(new Word('cadáver'), new Word('cadáveres'));
75 yield new Substitution(new Word('capelão'), new Word('capelães'));
76 yield new Substitution(new Word('capitão'), new Word('capitães'));
77 yield new Substitution(new Word('chão'), new Word('chãos'));
78 yield new Substitution(new Word('charlatão'), new Word('charlatães'));
79 yield new Substitution(new Word('cidadão'), new Word('cidadãos'));
80 yield new Substitution(new Word('consul'), new Word('consules'));
81 yield new Substitution(new Word('cristão'), new Word('cristãos'));
82 yield new Substitution(new Word('difícil'), new Word('difíceis'));
83 yield new Substitution(new Word('email'), new Word('emails'));
84 yield new Substitution(new Word('escrivão'), new Word('escrivães'));
85 yield new Substitution(new Word('fóssil'), new Word('fósseis'));
86 yield new Substitution(new Word('gás'), new Word('gases'));
87 yield new Substitution(new Word('germens'), new Word('germen'));
88 yield new Substitution(new Word('grão'), new Word('grãos'));
89 yield new Substitution(new Word('hífen'), new Word('hífens'));
90 yield new Substitution(new Word('irmão'), new Word('irmãos'));
91 yield new Substitution(new Word('liquens'), new Word('liquen'));
92 yield new Substitution(new Word('mal'), new Word('males'));
93 yield new Substitution(new Word('mão'), new Word('mãos'));
94 yield new Substitution(new Word('orfão'), new Word('orfãos'));
95 yield new Substitution(new Word('país'), new Word('países'));
96 yield new Substitution(new Word('pai'), new Word('pais'));
97 yield new Substitution(new Word('pão'), new Word('pães'));
98 yield new Substitution(new Word('projétil'), new Word('projéteis'));
99 yield new Substitution(new Word('réptil'), new Word('répteis'));
100 yield new Substitution(new Word('sacristão'), new Word('sacristães'));
101 yield new Substitution(new Word('sotão'), new Word('sotãos'));
102 yield new Substitution(new Word('tabelião'), new Word('tabeliães'));
103 }
104 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Portuguese;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Portuguese;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Portuguese;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17 }
18
19 /**
20 * @return Pattern[]
21 */
22 public static function getPlural(): iterable
23 {
24 yield from self::getDefault();
25 }
26
27 /**
28 * @return Pattern[]
29 */
30 private static function getDefault(): iterable
31 {
32 yield new Pattern('tórax');
33 yield new Pattern('tênis');
34 yield new Pattern('ônibus');
35 yield new Pattern('lápis');
36 yield new Pattern('fênix');
37 }
38 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 class Ruleset
8 {
9 /** @var Transformations */
10 private $regular;
11
12 /** @var Patterns */
13 private $uninflected;
14
15 /** @var Substitutions */
16 private $irregular;
17
18 public function __construct(Transformations $regular, Patterns $uninflected, Substitutions $irregular)
19 {
20 $this->regular = $regular;
21 $this->uninflected = $uninflected;
22 $this->irregular = $irregular;
23 }
24
25 public function getRegular(): Transformations
26 {
27 return $this->regular;
28 }
29
30 public function getUninflected(): Patterns
31 {
32 return $this->uninflected;
33 }
34
35 public function getIrregular(): Substitutions
36 {
37 return $this->irregular;
38 }
39 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Spanish;
6
7 use Doctrine\Inflector\Rules\Pattern;
8 use Doctrine\Inflector\Rules\Substitution;
9 use Doctrine\Inflector\Rules\Transformation;
10 use Doctrine\Inflector\Rules\Word;
11
12 class Inflectible
13 {
14 /**
15 * @return Transformation[]
16 */
17 public static function getSingular(): iterable
18 {
19 yield new Transformation(new Pattern('/ereses$/'), 'erés');
20 yield new Transformation(new Pattern('/iones$/'), 'ión');
21 yield new Transformation(new Pattern('/ces$/'), 'z');
22 yield new Transformation(new Pattern('/es$/'), '');
23 yield new Transformation(new Pattern('/s$/'), '');
24 }
25
26 /**
27 * @return Transformation[]
28 */
29 public static function getPlural(): iterable
30 {
31 yield new Transformation(new Pattern('/ú([sn])$/i'), 'u\1es');
32 yield new Transformation(new Pattern('/ó([sn])$/i'), 'o\1es');
33 yield new Transformation(new Pattern('/í([sn])$/i'), 'i\1es');
34 yield new Transformation(new Pattern('/é([sn])$/i'), 'e\1es');
35 yield new Transformation(new Pattern('/á([sn])$/i'), 'a\1es');
36 yield new Transformation(new Pattern('/z$/i'), 'ces');
37 yield new Transformation(new Pattern('/([aeiou]s)$/i'), '\1');
38 yield new Transformation(new Pattern('/([^aeéiou])$/i'), '\1es');
39 yield new Transformation(new Pattern('/$/'), 's');
40 }
41
42 /**
43 * @return Substitution[]
44 */
45 public static function getIrregular(): iterable
46 {
47 yield new Substitution(new Word('el'), new Word('los'));
48 yield new Substitution(new Word('papá'), new Word('papás'));
49 yield new Substitution(new Word('mamá'), new Word('mamás'));
50 yield new Substitution(new Word('sofá'), new Word('sofás'));
51 yield new Substitution(new Word('mes'), new Word('meses'));
52 }
53 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Spanish;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Spanish;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Spanish;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17 }
18
19 /**
20 * @return Pattern[]
21 */
22 public static function getPlural(): iterable
23 {
24 yield from self::getDefault();
25 }
26
27 /**
28 * @return Pattern[]
29 */
30 private static function getDefault(): iterable
31 {
32 yield new Pattern('lunes');
33 yield new Pattern('rompecabezas');
34 yield new Pattern('crisis');
35 }
36 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 final class Substitution
8 {
9 /** @var Word */
10 private $from;
11
12 /** @var Word */
13 private $to;
14
15 public function __construct(Word $from, Word $to)
16 {
17 $this->from = $from;
18 $this->to = $to;
19 }
20
21 public function getFrom(): Word
22 {
23 return $this->from;
24 }
25
26 public function getTo(): Word
27 {
28 return $this->to;
29 }
30 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 use Doctrine\Inflector\WordInflector;
8
9 use function strtolower;
10 use function strtoupper;
11 use function substr;
12
13 class Substitutions implements WordInflector
14 {
15 /** @var Substitution[] */
16 private $substitutions;
17
18 public function __construct(Substitution ...$substitutions)
19 {
20 foreach ($substitutions as $substitution) {
21 $this->substitutions[$substitution->getFrom()->getWord()] = $substitution;
22 }
23 }
24
25 public function getFlippedSubstitutions(): Substitutions
26 {
27 $substitutions = [];
28
29 foreach ($this->substitutions as $substitution) {
30 $substitutions[] = new Substitution(
31 $substitution->getTo(),
32 $substitution->getFrom()
33 );
34 }
35
36 return new Substitutions(...$substitutions);
37 }
38
39 public function inflect(string $word): string
40 {
41 $lowerWord = strtolower($word);
42
43 if (isset($this->substitutions[$lowerWord])) {
44 $firstLetterUppercase = $lowerWord[0] !== $word[0];
45
46 $toWord = $this->substitutions[$lowerWord]->getTo()->getWord();
47
48 if ($firstLetterUppercase) {
49 return strtoupper($toWord[0]) . substr($toWord, 1);
50 }
51
52 return $toWord;
53 }
54
55 return $word;
56 }
57 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 use Doctrine\Inflector\WordInflector;
8
9 use function preg_replace;
10
11 final class Transformation implements WordInflector
12 {
13 /** @var Pattern */
14 private $pattern;
15
16 /** @var string */
17 private $replacement;
18
19 public function __construct(Pattern $pattern, string $replacement)
20 {
21 $this->pattern = $pattern;
22 $this->replacement = $replacement;
23 }
24
25 public function getPattern(): Pattern
26 {
27 return $this->pattern;
28 }
29
30 public function getReplacement(): string
31 {
32 return $this->replacement;
33 }
34
35 public function inflect(string $word): string
36 {
37 return (string) preg_replace($this->pattern->getRegex(), $this->replacement, $word);
38 }
39 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 use Doctrine\Inflector\WordInflector;
8
9 class Transformations implements WordInflector
10 {
11 /** @var Transformation[] */
12 private $transformations;
13
14 public function __construct(Transformation ...$transformations)
15 {
16 $this->transformations = $transformations;
17 }
18
19 public function inflect(string $word): string
20 {
21 foreach ($this->transformations as $transformation) {
22 if ($transformation->getPattern()->matches($word)) {
23 return $transformation->inflect($word);
24 }
25 }
26
27 return $word;
28 }
29 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Turkish;
6
7 use Doctrine\Inflector\Rules\Pattern;
8 use Doctrine\Inflector\Rules\Substitution;
9 use Doctrine\Inflector\Rules\Transformation;
10 use Doctrine\Inflector\Rules\Word;
11
12 class Inflectible
13 {
14 /**
15 * @return Transformation[]
16 */
17 public static function getSingular(): iterable
18 {
19 yield new Transformation(new Pattern('/l[ae]r$/i'), '');
20 }
21
22 /**
23 * @return Transformation[]
24 */
25 public static function getPlural(): iterable
26 {
27 yield new Transformation(new Pattern('/([eöiü][^aoıueöiü]{0,6})$/u'), '\1ler');
28 yield new Transformation(new Pattern('/([aoıu][^aoıueöiü]{0,6})$/u'), '\1lar');
29 }
30
31 /**
32 * @return Substitution[]
33 */
34 public static function getIrregular(): iterable
35 {
36 yield new Substitution(new Word('ben'), new Word('biz'));
37 yield new Substitution(new Word('sen'), new Word('siz'));
38 yield new Substitution(new Word('o'), new Word('onlar'));
39 }
40 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Turkish;
6
7 use Doctrine\Inflector\GenericLanguageInflectorFactory;
8 use Doctrine\Inflector\Rules\Ruleset;
9
10 final class InflectorFactory extends GenericLanguageInflectorFactory
11 {
12 protected function getSingularRuleset(): Ruleset
13 {
14 return Rules::getSingularRuleset();
15 }
16
17 protected function getPluralRuleset(): Ruleset
18 {
19 return Rules::getPluralRuleset();
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Turkish;
6
7 use Doctrine\Inflector\Rules\Patterns;
8 use Doctrine\Inflector\Rules\Ruleset;
9 use Doctrine\Inflector\Rules\Substitutions;
10 use Doctrine\Inflector\Rules\Transformations;
11
12 final class Rules
13 {
14 public static function getSingularRuleset(): Ruleset
15 {
16 return new Ruleset(
17 new Transformations(...Inflectible::getSingular()),
18 new Patterns(...Uninflected::getSingular()),
19 (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions()
20 );
21 }
22
23 public static function getPluralRuleset(): Ruleset
24 {
25 return new Ruleset(
26 new Transformations(...Inflectible::getPlural()),
27 new Patterns(...Uninflected::getPlural()),
28 new Substitutions(...Inflectible::getIrregular())
29 );
30 }
31 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules\Turkish;
6
7 use Doctrine\Inflector\Rules\Pattern;
8
9 final class Uninflected
10 {
11 /**
12 * @return Pattern[]
13 */
14 public static function getSingular(): iterable
15 {
16 yield from self::getDefault();
17 }
18
19 /**
20 * @return Pattern[]
21 */
22 public static function getPlural(): iterable
23 {
24 yield from self::getDefault();
25 }
26
27 /**
28 * @return Pattern[]
29 */
30 private static function getDefault(): iterable
31 {
32 yield new Pattern('lunes');
33 yield new Pattern('rompecabezas');
34 yield new Pattern('crisis');
35 }
36 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector\Rules;
6
7 class Word
8 {
9 /** @var string */
10 private $word;
11
12 public function __construct(string $word)
13 {
14 $this->word = $word;
15 }
16
17 public function getWord(): string
18 {
19 return $this->word;
20 }
21 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 use Doctrine\Inflector\Rules\Ruleset;
8
9 use function array_merge;
10
11 /**
12 * Inflects based on multiple rulesets.
13 *
14 * Rules:
15 * - If the word matches any uninflected word pattern, it is not inflected
16 * - The first ruleset that returns a different value for an irregular word wins
17 * - The first ruleset that returns a different value for a regular word wins
18 * - If none of the above match, the word is left as-is
19 */
20 class RulesetInflector implements WordInflector
21 {
22 /** @var Ruleset[] */
23 private $rulesets;
24
25 public function __construct(Ruleset $ruleset, Ruleset ...$rulesets)
26 {
27 $this->rulesets = array_merge([$ruleset], $rulesets);
28 }
29
30 public function inflect(string $word): string
31 {
32 if ($word === '') {
33 return '';
34 }
35
36 foreach ($this->rulesets as $ruleset) {
37 if ($ruleset->getUninflected()->matches($word)) {
38 return $word;
39 }
40
41 $inflected = $ruleset->getIrregular()->inflect($word);
42
43 if ($inflected !== $word) {
44 return $inflected;
45 }
46
47 $inflected = $ruleset->getRegular()->inflect($word);
48
49 if ($inflected !== $word) {
50 return $inflected;
51 }
52 }
53
54 return $word;
55 }
56 }
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Inflector;
6
7 interface WordInflector
8 {
9 public function inflect(string $word): string;
10 }
1 The MIT License (MIT)
2
3 Copyright (c) 2020-2022 Graham Campbell <hello@gjcampbell.co.uk>
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
1 {
2 "name": "graham-campbell/result-type",
3 "description": "An Implementation Of The Result Type",
4 "keywords": ["result", "result-type", "Result", "Result Type", "Result-Type", "Graham Campbell", "GrahamCampbell"],
5 "license": "MIT",
6 "authors": [
7 {
8 "name": "Graham Campbell",
9 "email": "hello@gjcampbell.co.uk",
10 "homepage": "https://github.com/GrahamCampbell"
11 }
12 ],
13 "require": {
14 "php": "^7.2.5 || ^8.0",
15 "phpoption/phpoption": "^1.9"
16 },
17 "require-dev": {
18 "phpunit/phpunit": "^8.5.28 || ^9.5.21"
19 },
20 "autoload": {
21 "psr-4": {
22 "GrahamCampbell\\ResultType\\": "src/"
23 }
24 },
25 "autoload-dev": {
26 "psr-4": {
27 "GrahamCampbell\\Tests\\ResultType\\": "tests/"
28 }
29 },
30 "config": {
31 "preferred-install": "dist"
32 }
33 }
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * This file is part of Result Type.
7 *
8 * (c) Graham Campbell <hello@gjcampbell.co.uk>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace GrahamCampbell\ResultType;
15
16 use PhpOption\None;
17 use PhpOption\Some;
18
19 /**
20 * @template T
21 * @template E
22 * @extends \GrahamCampbell\ResultType\Result<T,E>
23 */
24 final class Error extends Result
25 {
26 /**
27 * @var E
28 */
29 private $value;
30
31 /**
32 * Internal constructor for an error value.
33 *
34 * @param E $value
35 *
36 * @return void
37 */
38 private function __construct($value)
39 {
40 $this->value = $value;
41 }
42
43 /**
44 * Create a new error value.
45 *
46 * @template F
47 *
48 * @param F $value
49 *
50 * @return \GrahamCampbell\ResultType\Result<T,F>
51 */
52 public static function create($value)
53 {
54 return new self($value);
55 }
56
57 /**
58 * Get the success option value.
59 *
60 * @return \PhpOption\Option<T>
61 */
62 public function success()
63 {
64 return None::create();
65 }
66
67 /**
68 * Map over the success value.
69 *
70 * @template S
71 *
72 * @param callable(T):S $f
73 *
74 * @return \GrahamCampbell\ResultType\Result<S,E>
75 */
76 public function map(callable $f)
77 {
78 return self::create($this->value);
79 }
80
81 /**
82 * Flat map over the success value.
83 *
84 * @template S
85 * @template F
86 *
87 * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
88 *
89 * @return \GrahamCampbell\ResultType\Result<S,F>
90 */
91 public function flatMap(callable $f)
92 {
93 /** @var \GrahamCampbell\ResultType\Result<S,F> */
94 return self::create($this->value);
95 }
96
97 /**
98 * Get the error option value.
99 *
100 * @return \PhpOption\Option<E>
101 */
102 public function error()
103 {
104 return Some::create($this->value);
105 }
106
107 /**
108 * Map over the error value.
109 *
110 * @template F
111 *
112 * @param callable(E):F $f
113 *
114 * @return \GrahamCampbell\ResultType\Result<T,F>
115 */
116 public function mapError(callable $f)
117 {
118 return self::create($f($this->value));
119 }
120 }
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * This file is part of Result Type.
7 *
8 * (c) Graham Campbell <hello@gjcampbell.co.uk>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace GrahamCampbell\ResultType;
15
16 /**
17 * @template T
18 * @template E
19 */
20 abstract class Result
21 {
22 /**
23 * Get the success option value.
24 *
25 * @return \PhpOption\Option<T>
26 */
27 abstract public function success();
28
29 /**
30 * Map over the success value.
31 *
32 * @template S
33 *
34 * @param callable(T):S $f
35 *
36 * @return \GrahamCampbell\ResultType\Result<S,E>
37 */
38 abstract public function map(callable $f);
39
40 /**
41 * Flat map over the success value.
42 *
43 * @template S
44 * @template F
45 *
46 * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
47 *
48 * @return \GrahamCampbell\ResultType\Result<S,F>
49 */
50 abstract public function flatMap(callable $f);
51
52 /**
53 * Get the error option value.
54 *
55 * @return \PhpOption\Option<E>
56 */
57 abstract public function error();
58
59 /**
60 * Map over the error value.
61 *
62 * @template F
63 *
64 * @param callable(E):F $f
65 *
66 * @return \GrahamCampbell\ResultType\Result<T,F>
67 */
68 abstract public function mapError(callable $f);
69 }
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * This file is part of Result Type.
7 *
8 * (c) Graham Campbell <hello@gjcampbell.co.uk>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace GrahamCampbell\ResultType;
15
16 use PhpOption\None;
17 use PhpOption\Some;
18
19 /**
20 * @template T
21 * @template E
22 * @extends \GrahamCampbell\ResultType\Result<T,E>
23 */
24 final class Success extends Result
25 {
26 /**
27 * @var T
28 */
29 private $value;
30
31 /**
32 * Internal constructor for a success value.
33 *
34 * @param T $value
35 *
36 * @return void
37 */
38 private function __construct($value)
39 {
40 $this->value = $value;
41 }
42
43 /**
44 * Create a new error value.
45 *
46 * @template S
47 *
48 * @param S $value
49 *
50 * @return \GrahamCampbell\ResultType\Result<S,E>
51 */
52 public static function create($value)
53 {
54 return new self($value);
55 }
56
57 /**
58 * Get the success option value.
59 *
60 * @return \PhpOption\Option<T>
61 */
62 public function success()
63 {
64 return Some::create($this->value);
65 }
66
67 /**
68 * Map over the success value.
69 *
70 * @template S
71 *
72 * @param callable(T):S $f
73 *
74 * @return \GrahamCampbell\ResultType\Result<S,E>
75 */
76 public function map(callable $f)
77 {
78 return self::create($f($this->value));
79 }
80
81 /**
82 * Flat map over the success value.
83 *
84 * @template S
85 * @template F
86 *
87 * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
88 *
89 * @return \GrahamCampbell\ResultType\Result<S,F>
90 */
91 public function flatMap(callable $f)
92 {
93 return $f($this->value);
94 }
95
96 /**
97 * Get the error option value.
98 *
99 * @return \PhpOption\Option<E>
100 */
101 public function error()
102 {
103 return None::create();
104 }
105
106 /**
107 * Map over the error value.
108 *
109 * @template F
110 *
111 * @param callable(E):F $f
112 *
113 * @return \GrahamCampbell\ResultType\Result<T,F>
114 */
115 public function mapError(callable $f)
116 {
117 return self::create($this->value);
118 }
119 }
1 <?php
2
3 namespace Illuminate\Bus;
4
5 use Carbon\CarbonImmutable;
6 use Illuminate\Contracts\Queue\Factory as QueueFactory;
7
8 class BatchFactory
9 {
10 /**
11 * The queue factory implementation.
12 *
13 * @var \Illuminate\Contracts\Queue\Factory
14 */
15 protected $queue;
16
17 /**
18 * Create a new batch factory instance.
19 *
20 * @param \Illuminate\Contracts\Queue\Factory $queue
21 * @return void
22 */
23 public function __construct(QueueFactory $queue)
24 {
25 $this->queue = $queue;
26 }
27
28 /**
29 * Create a new batch instance.
30 *
31 * @param \Illuminate\Bus\BatchRepository $repository
32 * @param string $id
33 * @param string $name
34 * @param int $totalJobs
35 * @param int $pendingJobs
36 * @param int $failedJobs
37 * @param array $failedJobIds
38 * @param array $options
39 * @param \Carbon\CarbonImmutable $createdAt
40 * @param \Carbon\CarbonImmutable|null $cancelledAt
41 * @param \Carbon\CarbonImmutable|null $finishedAt
42 * @return \Illuminate\Bus\Batch
43 */
44 public function make(BatchRepository $repository,
45 string $id,
46 string $name,
47 int $totalJobs,
48 int $pendingJobs,
49 int $failedJobs,
50 array $failedJobIds,
51 array $options,
52 CarbonImmutable $createdAt,
53 ?CarbonImmutable $cancelledAt,
54 ?CarbonImmutable $finishedAt)
55 {
56 return new Batch($this->queue, $repository, $id, $name, $totalJobs, $pendingJobs, $failedJobs, $failedJobIds, $options, $createdAt, $cancelledAt, $finishedAt);
57 }
58 }
1 <?php
2
3 namespace Illuminate\Bus;
4
5 use Closure;
6
7 interface BatchRepository
8 {
9 /**
10 * Retrieve a list of batches.
11 *
12 * @param int $limit
13 * @param mixed $before
14 * @return \Illuminate\Bus\Batch[]
15 */
16 public function get($limit, $before);
17
18 /**
19 * Retrieve information about an existing batch.
20 *
21 * @param string $batchId
22 * @return \Illuminate\Bus\Batch|null
23 */
24 public function find(string $batchId);
25
26 /**
27 * Store a new pending batch.
28 *
29 * @param \Illuminate\Bus\PendingBatch $batch
30 * @return \Illuminate\Bus\Batch
31 */
32 public function store(PendingBatch $batch);
33
34 /**
35 * Increment the total number of jobs within the batch.
36 *
37 * @param string $batchId
38 * @param int $amount
39 * @return void
40 */
41 public function incrementTotalJobs(string $batchId, int $amount);
42
43 /**
44 * Decrement the total number of pending jobs for the batch.
45 *
46 * @param string $batchId
47 * @param string $jobId
48 * @return \Illuminate\Bus\UpdatedBatchJobCounts
49 */
50 public function decrementPendingJobs(string $batchId, string $jobId);
51
52 /**
53 * Increment the total number of failed jobs for the batch.
54 *
55 * @param string $batchId
56 * @param string $jobId
57 * @return \Illuminate\Bus\UpdatedBatchJobCounts
58 */
59 public function incrementFailedJobs(string $batchId, string $jobId);
60
61 /**
62 * Mark the batch that has the given ID as finished.
63 *
64 * @param string $batchId
65 * @return void
66 */
67 public function markAsFinished(string $batchId);
68
69 /**
70 * Cancel the batch that has the given ID.
71 *
72 * @param string $batchId
73 * @return void
74 */
75 public function cancel(string $batchId);
76
77 /**
78 * Delete the batch that has the given ID.
79 *
80 * @param string $batchId
81 * @return void
82 */
83 public function delete(string $batchId);
84
85 /**
86 * Execute the given Closure within a storage specific transaction.
87 *
88 * @param \Closure $callback
89 * @return mixed
90 */
91 public function transaction(Closure $callback);
92 }
This diff could not be displayed because it is too large.