{"id":166359,"date":"2013-01-20T18:05:04","date_gmt":"2013-01-20T14:05:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=166359"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=166359","title":{"rendered":"<span class=\"post_title\">\u0428\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u201eRegistry\u201c \u043d\u0430 PHP<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u201cRegistry\u201c \u043d\u0430 PHP. \u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e \u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u2014 \u044d\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041f\u0440\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/design-pattern.ru\/patterns\/registry.html\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041e\u0442 \u0441\u0435\u0431\u044f \u0436\u0435 \u0445\u043e\u0447\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u0434\u0435\u0442 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u201c<a href=\"http:\/\/en.wikipedia.org\/wiki\/Facade_pattern\">Facade<\/a>\u201c.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043e\u0439, \u044f \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0434\u043b\u044f \u0441\u0435\u0431\u044f.<\/p>\n<pre><code class=\"php\">&lt;?php \t\/** \t * \u041a\u043b\u0430\u0441\u0441 \u00abRegistry\u00bb \u0445\u0440\u0430\u043d\u0438\u0442 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0432\u043e \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \t * \u041a\u043b\u0430\u0441\u0441 \u0437\u0430\u0449\u0438\u0449\u0435\u043d \u043e\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u00abSingleton\u00bb. \t *\/ \t \tfinal class Registry { \t\tprivate $vars = array(); \/\/ \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \t\t \t\t \t\t \t\t \t\t\/\/ Singleton ---------------------------------------------------- \t\tstatic private $instance = NULL; \/\/ \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 \t\t \t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \t\tstatic function instance() { \t\t\tif (self::$instance == NULL) { \t\t\t\tself::$instance = new Registry(); \t\t\t}; \t\t\t \t\t\treturn self::$instance; \t\t} \t\t \t\t\/\/ \u0441\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \t\tprivate function __construct() {} \t\tprivate function __clone() {} \t\t\/\/ -------------------------------------------------------------- \t\t \t\t \t\t \t\t \t\t\/\/ \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 -------------------------------------------- \t\t\/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \t\tfunction set($name, $value = NULL, $type = 'simple') { \t\t\tif (!is_string($name)) { \t\t\t\t$this-&gt;errors('arg', 1, __METHOD__, 'string', gettype($name)); \t\t\t\treturn false; \t\t\t}; \t\t\t \t\t\t\/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \t\t\tswitch ($type) { \t\t\t\tcase 'protected': \t\t\t\t\tif (!isset($this-&gt;vars[$name]) || (isset($this-&gt;vars[$name]) && $this-&gt;vars[$name]['type'] == 'simple')) { \t\t\t\t\t\t$this-&gt;vars[$name] = array( \t\t\t\t\t\t\t'value' =&gt; $value, \t\t\t\t\t\t\t'type' =&gt; $type \t\t\t\t\t\t); \t\t\t\t\t\treturn true; \t\t\t\t\t} else { \t\t\t\t\t\t$this-&gt;errors('var', 0, $name, __METHOD__); \t\t\t\t\t\treturn false; \t\t\t\t\t}; \t\t\t\t\t \t\t\t\tcase 'simple': \t\t\t\t\tif (isset($this-&gt;vars[$name]) && $this-&gt;vars[$name]['type'] == 'protected') { \t\t\t\t\t\t$this-&gt;errors('var', 0, $name, __METHOD__); \t\t\t\t\t} else { \t\t\t\t\t\t$this-&gt;vars[$name] = array( \t\t\t\t\t\t\t'value' =&gt; $value, \t\t\t\t\t\t\t'type' =&gt; $type \t\t\t\t\t\t); \t\t\t\t\t\treturn true; \t\t\t\t\t}; \t\t\t\t\t\t\t\t\t \t\t\t\tdefault: \t\t\t\t\t$this-&gt;errors('var', 2, $name, __METHOD__); \t\t\t\t\treturn false; \t\t\t}; \t\t} \t\t \t\t\/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \t\tfunction get($name) { \t\t\tif (!is_string($name)) { \t\t\t\t$this-&gt;errors('arg', 1, __METHOD__, 'string', gettype($name)); \t\t\t\treturn false; \t\t\t}; \t\t\t \t\t\tif (isset($this-&gt;vars[$name])) { \t\t\t\treturn $this-&gt;vars[$name]['value']; \t\t\t} else { \t\t\t\t$this-&gt;errors('var', 1, $name, __METHOD__); \t\t\t\treturn false; \t\t\t} \t\t} \t\t\/\/ -------------------------------------------------------------- \t\t \t\t \t\t \t\t \t\t\/\/ \u043e\u0448\u0438\u0431\u043a\u0438 (\u043f\u0440\u0438\u0432\u0430\u0442\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f) ----------------------------------- \t\tprivate function errors($type) { \t\t\tswitch ($type) { \t\t\t\tcase 'arg': \t\t\t\t\t\/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \t\t\t\t\t$number = func_get_arg(1); \t\t\t\t\t$method = func_get_arg(2); \t\t\t\t\t$must = func_get_arg(3); \t\t\t\t\t$given = func_get_arg(4); \t\t\t\t\t \t\t\t\t\t$call = debug_backtrace()[1]; \t\t\t\t\ttrigger_error(&quot;argument &lt;i&gt;$number&lt;\/i&gt; passed to &lt;i&gt;$method()&lt;\/i&gt; must be an instance of &lt;u&gt;$must&lt;\/u&gt;, &lt;u&gt;$given&lt;\/u&gt; given, called in &lt;b&gt;&quot; . $call['file'] . &quot;&lt;\/b&gt; on line &lt;b&gt;&quot; . $call['line'] . &quot;&lt;\/b&gt; and defined&quot;, E_USER_WARNING); \t\t\t\t\tbreak; \t\t\t\t\t \t\t\t\tcase 'var': \t\t\t\t\t\/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \t\t\t\t\t$error = func_get_arg(1); \t\t\t\t\t$name = func_get_arg(2); \t\t\t\t\t$method = func_get_arg(3); \t\t\t\t\t \t\t\t\t\t\/\/ \u043e\u0448\u0438\u0431\u043a\u0438 \t\t\t\t\t$errors = array( \t\t\t\t\t\tarray( \t\t\t\t\t\t\t'value' =&gt; &quot;protected variable &lt;i&gt;$name&lt;\/i&gt; passed to &lt;i&gt;$method()&lt;\/i&gt; has already been registered&quot;, \t\t\t\t\t\t\t'type' =&gt; E_USER_ERROR \t\t\t\t\t\t), \t\t\t\t\t\tarray( \t\t\t\t\t\t\t'value' =&gt; &quot;variable &lt;i&gt;$name&lt;\/i&gt; passed to &lt;i&gt;$method()&lt;\/i&gt; has not been registered&quot;, \t\t\t\t\t\t\t'type' =&gt; E_USER_WARNING \t\t\t\t\t\t), \t\t\t\t\t\tarray( \t\t\t\t\t\t\t'value' =&gt; &quot;type of variable &lt;i&gt;$name&lt;\/i&gt; passed to &lt;i&gt;$method()&lt;\/i&gt; must be &lt;u&gt;simple&lt;\/u&gt; or &lt;u&gt;protected&lt;\/u&gt;&quot;, \t\t\t\t\t\t\t'type' =&gt; E_USER_WARNING \t\t\t\t\t\t) \t\t\t\t\t); \t\t\t\t\t \t\t\t\t\t$call = debug_backtrace()[1]; \t\t\t\t\ttrigger_error($errors[$error]['value'] . &quot;, called in &lt;b&gt;&quot; . $call['file'] . &quot;&lt;\/b&gt; on line &lt;b&gt;&quot; . $call['line'] . &quot;&lt;\/b&gt; and defined&quot;, $errors[$error]['type']); \t\t\t\t\tbreak; \t\t\t}; \t\t} \t\t\/\/ -------------------------------------------------------------- \t} ?&gt;<\/code><\/pre>\n<p>  <\/p>\n<h6>\u201cSingleton\u201c<\/h6>\n<p>  \u0412\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u043d\u0438\u0435 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0448\u0430\u0431\u043b\u043e\u043d \u201cSingleton\u201c. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c.<\/p>\n<pre><code class=\"php\">\/\/ Singleton ---------------------------------------------------- \t\tstatic private $instance = NULL; \/\/ \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 \t\t \t\t\/\/ \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \t\tstatic function instance() { \t\t\tif (self::$instance == NULL) { \t\t\t\tself::$instance = new Registry(); \t\t\t}; \t\t\t \t\t\treturn self::$instance; \t\t} \t\t \t\t\/\/ \u0441\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \t\tprivate function __construct() {} \t\tprivate function __clone() {} \t\t\/\/ --------------------------------------------------------------<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 Registry, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0449\u0438\u0449\u0435\u043d \u044d\u0442\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>Registry::instance()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0435\u0441\u043b\u0438 \u043e\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0432. \u0421\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u043d\u0430\u0440\u0443\u0436\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0447\u0435\u0440\u0435\u0437 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new \u0438\u043b\u0438 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u0422.\u043a. \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u043d, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043e\u0434\u0430 \u0438, \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 Registry.<\/p>\n<h6>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h6>\n<p>  \u041a\u043b\u0430\u0441\u0441 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u2014 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0435 (protected) \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 (simple). \u0417\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/p>\n<h6>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h6>\n<p>  <\/p>\n<pre><code class=\"php\">bool Registry::set(string $name, mixed $value [, string $type])<\/code><\/pre>\n<p>  \u0413\u0434\u0435 <code>$name<\/code> \u2014 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, <code>$value<\/code> \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, <code>$type<\/code> \u2014 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>'simple'<\/code>). \u0412\u0435\u0440\u043d\u0435\u0442 true, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0438 false, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u0415\u0441\u043b\u0438 \u0412\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<h6>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/h6>\n<p>  <\/p>\n<pre><code class=\"php\">mixed Registry::get(string $name)<\/code><\/pre>\n<p>  \u0413\u0434\u0435 <code>$name<\/code> \u2014 \u0438\u043c\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>$name<\/code> \u0438\u043b\u0438 false, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<h6>\u041f\u0440\u0438\u043c\u0435\u0440<\/h6>\n<p>  <\/p>\n<pre><code class=\"php\">\/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 $registry = Registry::instance();  \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 $registry-&gt;set('protected_var', 'This variable is protected', 'protected'); \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 $registry-&gt;set('simple_var', 'This variable is simple');  echo $registry-&gt;get('protected_var'); \/\/ =&gt; 'This variable is protected' echo $registry-&gt;get('simple_var'); \/\/ =&gt; 'This variable is simple' echo $registry-&gt;get('var'); \/\/ =&gt; false  \/\/ \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 $registry-&gt;set('simple_var', 'Rewrite simple variable'); \/\/ \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439 $registry-&gt;set('protected_var', 'Rewrite protected variable');<\/code><\/pre>\n<h6>\u041e\u0448\u0438\u0431\u043a\u0438<\/h6>\n<p>  \u041a\u043b\u0430\u0441\u0441 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043e\u0448\u0438\u0431\u043e\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u044e trigger_error(). \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0438\u0445 \u0442\u0438\u043f.  <\/p>\n<table>\n<tr>\n<td width=\"150\">\u0422\u0438\u043f<\/td>\n<td>\u041e\u0448\u0438\u0431\u043a\u0430<\/td>\n<td>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/td>\n<\/tr>\n<tr>\n<td>E_USER_ERROR<\/td>\n<td>protected variable test_var passed to Registry::set() has already been registered, called in \/test.php on line 10<\/td>\n<td>\u041d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 test_var.<\/td>\n<\/tr>\n<tr>\n<td>E_USER_WARNING<\/td>\n<td>variable test_var2 passed to Registry::get() has not been registered, called in \/test2.php on line 5<\/td>\n<td>\u0412\u044b \u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 test_var2.<\/td>\n<\/tr>\n<tr>\n<td>E_USER_WARNING<\/td>\n<td>type of variable test_var3 passed to Registry::set() must be simple or protected, called in \/test3.php on line 7<\/td>\n<td>\u0412\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 test_var3, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u0438\u0431\u043e simple, \u043b\u0438\u0431\u043e protected.<\/td>\n<\/tr>\n<tr>\n<td>E_USER_WARNING<\/td>\n<td>argument 1 passed to Registry::set() must be an instance of string, array given, called in \/test4.php on line 6<\/td>\n<td>\u041f\u0435\u0440\u0432\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 Registry::set() \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0439, \u0412\u044b \u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432.<\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0444\u0430\u0441\u0430\u0434\u043e\u043c \u0432 \u043c\u043e\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u0440\u0430\u043d\u0435\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440 Smarty \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0435\u0437\u0434\u0435). \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043c\u043d\u0435, \u0447\u0442\u043e \u044f \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0443 \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u043d\u0435 \u043f\u043e\u043b\u043e\u0436\u0443 \u0438\u0437-\u0437\u0430 \u044d\u0442\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0443 \u0432\u0441\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0430 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c Singleton \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u044e\u0442\u0441\u044f. \u041c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0438 \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043a\u043e\u0434\u0430.    \t \t\t   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/166359\/\"> http:\/\/habrahabr.ru\/post\/166359\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u0441\u0432\u043e\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u201cRegistry\u201c \u043d\u0430 PHP. \u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e \u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0435 \u2014 \u044d\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041f\u0440\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"http:\/\/design-pattern.ru\/patterns\/registry.html\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u041e\u0442 \u0441\u0435\u0431\u044f \u0436\u0435 \u0445\u043e\u0447\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0448\u0430\u0431\u043b\u043e\u043d \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u0434\u0435\u0442 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u201c<a href=\"http:\/\/en.wikipedia.org\/wiki\/Facade_pattern\">Facade<\/a>\u201c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-166359","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=166359"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/166359\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}