mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-18 03:21:18 +02:00
Remove singleton code sample, update gemfile
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -1,2 +1,3 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gem 'github-pages'
|
gem 'github-pages'
|
||||||
|
gem 'rouge'
|
||||||
|
157
Gemfile.lock
157
Gemfile.lock
@@ -2,125 +2,146 @@ GEM
|
|||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
RedCloth (4.2.9)
|
RedCloth (4.2.9)
|
||||||
activesupport (4.2.5.1)
|
activesupport (5.0.0.1)
|
||||||
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||||
i18n (~> 0.7)
|
i18n (~> 0.7)
|
||||||
json (~> 1.7, >= 1.7.7)
|
|
||||||
minitest (~> 5.1)
|
minitest (~> 5.1)
|
||||||
thread_safe (~> 0.3, >= 0.3.4)
|
|
||||||
tzinfo (~> 1.1)
|
tzinfo (~> 1.1)
|
||||||
addressable (2.3.8)
|
addressable (2.4.0)
|
||||||
|
blankslate (2.1.2.4)
|
||||||
|
classifier-reborn (2.0.4)
|
||||||
|
fast-stemmer (~> 1.0)
|
||||||
coffee-script (2.4.1)
|
coffee-script (2.4.1)
|
||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.10.0)
|
coffee-script-source (1.10.0)
|
||||||
colorator (0.1)
|
colorator (0.1)
|
||||||
ethon (0.8.1)
|
concurrent-ruby (1.0.2)
|
||||||
|
ethon (0.9.1)
|
||||||
ffi (>= 1.3.0)
|
ffi (>= 1.3.0)
|
||||||
execjs (2.6.0)
|
execjs (2.7.0)
|
||||||
faraday (0.9.2)
|
faraday (0.10.0)
|
||||||
multipart-post (>= 1.2, < 3)
|
multipart-post (>= 1.2, < 3)
|
||||||
ffi (1.9.10)
|
fast-stemmer (1.0.2)
|
||||||
|
ffi (1.9.14)
|
||||||
|
ffi (1.9.14-x64-mingw32)
|
||||||
gemoji (2.1.0)
|
gemoji (2.1.0)
|
||||||
github-pages (48)
|
github-pages (39)
|
||||||
RedCloth (= 4.2.9)
|
RedCloth (= 4.2.9)
|
||||||
github-pages-health-check (= 0.6.1)
|
github-pages-health-check (~> 0.2)
|
||||||
jekyll (= 3.0.3)
|
jekyll (= 2.4.0)
|
||||||
jekyll-coffeescript (= 1.0.1)
|
jekyll-coffeescript (= 1.0.1)
|
||||||
jekyll-feed (= 0.3.1)
|
jekyll-feed (= 0.3.1)
|
||||||
jekyll-gist (= 1.4.0)
|
jekyll-mentions (= 0.2.1)
|
||||||
jekyll-mentions (= 1.0.0)
|
jekyll-redirect-from (= 0.8.0)
|
||||||
jekyll-paginate (= 1.1.0)
|
|
||||||
jekyll-redirect-from (= 0.9.1)
|
|
||||||
jekyll-sass-converter (= 1.3.0)
|
jekyll-sass-converter (= 1.3.0)
|
||||||
jekyll-seo-tag (= 1.0.0)
|
jekyll-sitemap (= 0.8.1)
|
||||||
jekyll-sitemap (= 0.10.0)
|
jemoji (= 0.5.0)
|
||||||
jekyll-textile-converter (= 0.1.0)
|
kramdown (= 1.5.0)
|
||||||
jemoji (= 0.5.1)
|
liquid (= 2.6.2)
|
||||||
kramdown (= 1.9.0)
|
maruku (= 0.7.0)
|
||||||
liquid (= 3.0.6)
|
|
||||||
mercenary (~> 0.3)
|
mercenary (~> 0.3)
|
||||||
rdiscount (= 2.1.8)
|
pygments.rb (= 0.6.3)
|
||||||
redcarpet (= 3.3.3)
|
rdiscount (= 2.1.7)
|
||||||
rouge (= 1.10.1)
|
redcarpet (= 3.3.2)
|
||||||
terminal-table (~> 1.4)
|
terminal-table (~> 1.4)
|
||||||
github-pages-health-check (0.6.1)
|
github-pages-health-check (0.3.2)
|
||||||
addressable (~> 2.3)
|
net-dns (~> 0.6)
|
||||||
net-dns (~> 0.8)
|
|
||||||
public_suffix (~> 1.4)
|
public_suffix (~> 1.4)
|
||||||
typhoeus (~> 0.7)
|
typhoeus (~> 0.7)
|
||||||
html-pipeline (2.3.0)
|
html-pipeline (1.9.0)
|
||||||
activesupport (>= 2, < 5)
|
activesupport (>= 2)
|
||||||
nokogiri (>= 1.4)
|
nokogiri (~> 1.4)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
jekyll (3.0.3)
|
jekyll (2.4.0)
|
||||||
|
classifier-reborn (~> 2.0)
|
||||||
colorator (~> 0.1)
|
colorator (~> 0.1)
|
||||||
|
jekyll-coffeescript (~> 1.0)
|
||||||
|
jekyll-gist (~> 1.0)
|
||||||
|
jekyll-paginate (~> 1.0)
|
||||||
jekyll-sass-converter (~> 1.0)
|
jekyll-sass-converter (~> 1.0)
|
||||||
jekyll-watch (~> 1.1)
|
jekyll-watch (~> 1.1)
|
||||||
kramdown (~> 1.3)
|
kramdown (~> 1.3)
|
||||||
liquid (~> 3.0)
|
liquid (~> 2.6.1)
|
||||||
mercenary (~> 0.3.3)
|
mercenary (~> 0.3.3)
|
||||||
rouge (~> 1.7)
|
pygments.rb (~> 0.6.0)
|
||||||
|
redcarpet (~> 3.1)
|
||||||
safe_yaml (~> 1.0)
|
safe_yaml (~> 1.0)
|
||||||
|
toml (~> 0.1.0)
|
||||||
jekyll-coffeescript (1.0.1)
|
jekyll-coffeescript (1.0.1)
|
||||||
coffee-script (~> 2.2)
|
coffee-script (~> 2.2)
|
||||||
jekyll-feed (0.3.1)
|
jekyll-feed (0.3.1)
|
||||||
jekyll-gist (1.4.0)
|
jekyll-gist (1.4.0)
|
||||||
octokit (~> 4.2)
|
octokit (~> 4.2)
|
||||||
jekyll-mentions (1.0.0)
|
jekyll-mentions (0.2.1)
|
||||||
html-pipeline (~> 2.2)
|
html-pipeline (~> 1.9.0)
|
||||||
jekyll (~> 3.0)
|
jekyll (~> 2.0)
|
||||||
jekyll-paginate (1.1.0)
|
jekyll-paginate (1.1.0)
|
||||||
jekyll-redirect-from (0.9.1)
|
jekyll-redirect-from (0.8.0)
|
||||||
jekyll (>= 2.0)
|
jekyll (>= 2.0)
|
||||||
jekyll-sass-converter (1.3.0)
|
jekyll-sass-converter (1.3.0)
|
||||||
sass (~> 3.2)
|
sass (~> 3.2)
|
||||||
jekyll-seo-tag (1.0.0)
|
jekyll-sitemap (0.8.1)
|
||||||
jekyll (>= 2.0)
|
jekyll-watch (1.5.0)
|
||||||
jekyll-sitemap (0.10.0)
|
listen (~> 3.0, < 3.1)
|
||||||
jekyll-textile-converter (0.1.0)
|
jemoji (0.5.0)
|
||||||
RedCloth (~> 4.0)
|
|
||||||
jekyll-watch (1.3.1)
|
|
||||||
listen (~> 3.0)
|
|
||||||
jemoji (0.5.1)
|
|
||||||
gemoji (~> 2.0)
|
gemoji (~> 2.0)
|
||||||
html-pipeline (~> 2.2)
|
html-pipeline (~> 1.9)
|
||||||
jekyll (>= 2.0)
|
jekyll (>= 2.0)
|
||||||
json (1.8.3)
|
kramdown (1.5.0)
|
||||||
kramdown (1.9.0)
|
liquid (2.6.2)
|
||||||
liquid (3.0.6)
|
listen (3.0.8)
|
||||||
listen (3.0.6)
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||||
rb-fsevent (>= 0.9.3)
|
rb-inotify (~> 0.9, >= 0.9.7)
|
||||||
rb-inotify (>= 0.9.7)
|
maruku (0.7.0)
|
||||||
mercenary (0.3.5)
|
mercenary (0.3.6)
|
||||||
mini_portile2 (2.0.0)
|
mini_portile2 (2.1.0)
|
||||||
minitest (5.8.4)
|
minitest (5.9.1)
|
||||||
multipart-post (2.0.0)
|
multipart-post (2.0.0)
|
||||||
net-dns (0.8.0)
|
net-dns (0.8.0)
|
||||||
nokogiri (1.6.7.2)
|
nokogiri (1.6.8.1)
|
||||||
mini_portile2 (~> 2.0.0.rc2)
|
mini_portile2 (~> 2.1.0)
|
||||||
octokit (4.2.0)
|
nokogiri (1.6.8.1-x64-mingw32)
|
||||||
sawyer (~> 0.6.0, >= 0.5.3)
|
mini_portile2 (~> 2.1.0)
|
||||||
|
octokit (4.6.1)
|
||||||
|
sawyer (~> 0.8.0, >= 0.5.3)
|
||||||
|
parslet (1.5.0)
|
||||||
|
blankslate (~> 2.0)
|
||||||
|
posix-spawn (0.3.12)
|
||||||
public_suffix (1.5.3)
|
public_suffix (1.5.3)
|
||||||
rb-fsevent (0.9.7)
|
pygments.rb (0.6.3)
|
||||||
|
posix-spawn (~> 0.3.6)
|
||||||
|
yajl-ruby (~> 1.2.0)
|
||||||
|
rb-fsevent (0.9.8)
|
||||||
rb-inotify (0.9.7)
|
rb-inotify (0.9.7)
|
||||||
ffi (>= 0.5.0)
|
ffi (>= 0.5.0)
|
||||||
rdiscount (2.1.8)
|
rdiscount (2.1.7)
|
||||||
redcarpet (3.3.3)
|
redcarpet (3.3.2)
|
||||||
rouge (1.10.1)
|
rouge (2.0.7)
|
||||||
safe_yaml (1.0.4)
|
safe_yaml (1.0.4)
|
||||||
sass (3.4.21)
|
sass (3.4.22)
|
||||||
sawyer (0.6.0)
|
sawyer (0.8.1)
|
||||||
addressable (~> 2.3.5)
|
addressable (>= 2.3.5, < 2.6)
|
||||||
faraday (~> 0.8, < 0.10)
|
faraday (~> 0.8, < 1.0)
|
||||||
terminal-table (1.5.2)
|
terminal-table (1.7.3)
|
||||||
|
unicode-display_width (~> 1.1.1)
|
||||||
thread_safe (0.3.5)
|
thread_safe (0.3.5)
|
||||||
|
toml (0.1.2)
|
||||||
|
parslet (~> 1.5.0)
|
||||||
typhoeus (0.8.0)
|
typhoeus (0.8.0)
|
||||||
ethon (>= 0.8.0)
|
ethon (>= 0.8.0)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
|
unicode-display_width (1.1.1)
|
||||||
|
yajl-ruby (1.2.1)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
x64-mingw32
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
github-pages
|
github-pages
|
||||||
|
rouge
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.13.6
|
||||||
|
@@ -68,70 +68,7 @@ yourself a lot of trouble down the road by using factories.
|
|||||||
When designing web applications, it often makes sense conceptually and architecturally to allow access to one and only
|
When designing web applications, it often makes sense conceptually and architecturally to allow access to one and only
|
||||||
one instance of a particular class. The singleton pattern enables us to do this.
|
one instance of a particular class. The singleton pattern enables us to do this.
|
||||||
|
|
||||||
{% highlight php %}
|
**TODO: NEED NEW SINGLETON CODE EXAMPLE**
|
||||||
<?php
|
|
||||||
class Singleton
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Singleton The reference to *Singleton* instance of this class
|
|
||||||
*/
|
|
||||||
private static $instance;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the *Singleton* instance of this class.
|
|
||||||
*
|
|
||||||
* @return Singleton The *Singleton* instance.
|
|
||||||
*/
|
|
||||||
public static function getInstance()
|
|
||||||
{
|
|
||||||
if (null === static::$instance) {
|
|
||||||
static::$instance = new static();
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::$instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Protected constructor to prevent creating a new instance of the
|
|
||||||
* *Singleton* via the `new` operator from outside of this class.
|
|
||||||
*/
|
|
||||||
protected function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private clone method to prevent cloning of the instance of the
|
|
||||||
* *Singleton* instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function __clone()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private unserialize method to prevent unserializing of the *Singleton*
|
|
||||||
* instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function __wakeup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SingletonChild extends Singleton
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
$obj = Singleton::getInstance();
|
|
||||||
var_dump($obj === Singleton::getInstance()); // bool(true)
|
|
||||||
|
|
||||||
$anotherObj = SingletonChild::getInstance();
|
|
||||||
var_dump($anotherObj === Singleton::getInstance()); // bool(false)
|
|
||||||
|
|
||||||
var_dump($anotherObj === SingletonChild::getInstance()); // bool(true)
|
|
||||||
{% endhighlight %}
|
|
||||||
|
|
||||||
The code above implements the singleton pattern using a [*static* variable](http://php.net/language.variables.scope#language.variables.scope.static) and the static creation method `getInstance()`.
|
The code above implements the singleton pattern using a [*static* variable](http://php.net/language.variables.scope#language.variables.scope.static) and the static creation method `getInstance()`.
|
||||||
Note the following:
|
Note the following:
|
||||||
|
Reference in New Issue
Block a user