Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V  < 1 2  
Reply to this topicStart new topic
> Najoptymalniejszy sposób na __autoload z wielu katalogów
Ultear
post
Post #21





Grupa: Zarejestrowani
Postów: 52
Pomógł: 3
Dołączył: 9.12.2013

Ostrzeżenie: (0%)
-----


Nie modyfikowąłem, wygląda standardowo, czyli tak o:

  1. <?php
  2.  
  3. /*
  4.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  5.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  6.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  7.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  8.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  9.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  10.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  11.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  12.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  13.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  14.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15.  *
  16.  * This software consists of voluntary contributions made by many individuals
  17.  * and is licensed under the MIT license. For more information, see
  18.  * <http://www.doctrine-project.org>.
  19.  */
  20.  
  21. /**
  22.  * SplClassLoader implementation that implements the technical interoperability
  23.  * standards for PHP 5.3 namespaces and class names.
  24.  *
  25.  * <a href="http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1" target="_blank">http://groups.google.com/group/php-standar...-proposal?pli=1</a>
  26.  *
  27.  * // Example which loads classes for the Doctrine Common package in the
  28.  * // Doctrine\Common namespace.
  29.  * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
  30.  * $classLoader->register();
  31.  *
  32.  * @license <a href="http://www.opensource.org/licenses/mit-license.html" target="_blank">http://www.opensource.org/licenses/mit-license.html</a> MIT License
  33.  * @author Jonathan H. Wage <jonwage@gmail.com>
  34.  * @author Roman S. Borschel <roman@code-factory.org>
  35.  * @author Matthew Weier O'Phinney <matthew@zend.com>
  36.  * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  37.  * @author Fabien Potencier <fabien.potencier@symfony-project.org>
  38.  */
  39. class SplClassLoader
  40. {
  41. private $_fileExtension = '.php';
  42. private $_namespace;
  43. private $_includePath;
  44. private $_namespaceSeparator = '\\';
  45.  
  46. /**
  47.   * Creates a new <tt>SplClassLoader</tt> that loads classes of the
  48.   * specified namespace.
  49.   *
  50.   * @param string $ns The namespace to use.
  51.   */
  52. public function __construct($ns = null, $includePath = null)
  53. {
  54. $this->_namespace = $ns;
  55. $this->_includePath = $includePath;
  56. }
  57.  
  58. /**
  59.   * Sets the namespace separator used by classes in the namespace of this class loader.
  60.   *
  61.   * @param string $sep The separator to use.
  62.   */
  63. public function setNamespaceSeparator($sep)
  64. {
  65. $this->_namespaceSeparator = $sep;
  66. }
  67.  
  68. /**
  69.   * Gets the namespace seperator used by classes in the namespace of this class loader.
  70.   *
  71.   * @return void
  72.   */
  73. public function getNamespaceSeparator()
  74. {
  75. return $this->_namespaceSeparator;
  76. }
  77.  
  78. /**
  79.   * Sets the base include path for all class files in the namespace of this class loader.
  80.   *
  81.   * @param string $includePath
  82.   */
  83. public function setIncludePath($includePath)
  84. {
  85. $this->_includePath = $includePath;
  86. }
  87.  
  88. /**
  89.   * Gets the base include path for all class files in the namespace of this class loader.
  90.   *
  91.   * @return string $includePath
  92.   */
  93. public function getIncludePath()
  94. {
  95. return $this->_includePath;
  96. }
  97.  
  98. /**
  99.   * Sets the file extension of class files in the namespace of this class loader.
  100.   *
  101.   * @param string $fileExtension
  102.   */
  103. public function setFileExtension($fileExtension)
  104. {
  105. $this->_fileExtension = $fileExtension;
  106. }
  107.  
  108. /**
  109.   * Gets the file extension of class files in the namespace of this class loader.
  110.   *
  111.   * @return string $fileExtension
  112.   */
  113. public function getFileExtension()
  114. {
  115. return $this->_fileExtension;
  116. }
  117.  
  118. /**
  119.   * Installs this class loader on the SPL autoload stack.
  120.   */
  121. public function register()
  122. {
  123. spl_autoload_register(array($this, 'loadClass'));
  124. }
  125.  
  126. /**
  127.   * Uninstalls this class loader from the SPL autoloader stack.
  128.   */
  129. public function unregister()
  130. {
  131. spl_autoload_unregister(array($this, 'loadClass'));
  132. }
  133.  
  134. /**
  135.   * Loads the given class or interface.
  136.   *
  137.   * @param string $className The name of the class to load.
  138.   * @return void
  139.   */
  140. public function loadClass($className)
  141. {
  142. if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
  143. $fileName = '';
  144. $namespace = '';
  145. if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
  146. $namespace = substr($className, 0, $lastNsPos);
  147. $className = substr($className, $lastNsPos + 1);
  148. $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
  149. }
  150. $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;
  151.  
  152. require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
  153. }
  154. }
  155. }
Go to the top of the page
+Quote Post
pedro84
post
Post #22





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

Ostrzeżenie: (0%)
-----


Pokaż swoją strukturę katalogów oraz w którym miejscu masz rzucany ten błąd.
Go to the top of the page
+Quote Post
Ultear
post
Post #23





Grupa: Zarejestrowani
Postów: 52
Pomógł: 3
Dołączył: 9.12.2013

Ostrzeżenie: (0%)
-----


(IMG:http://iv.pl/images/28113811220350395835.png)
Go to the top of the page
+Quote Post
pedro84
post
Post #24





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

Ostrzeżenie: (0%)
-----


Mały hint: stałe w tablicy w zmiennej $options.
Go to the top of the page
+Quote Post
Ultear
post
Post #25





Grupa: Zarejestrowani
Postów: 52
Pomógł: 3
Dołączył: 9.12.2013

Ostrzeżenie: (0%)
-----


  1. public $options = array(
  2. \PDO::ATTR_PERSISTENT => true,
  3. \PDO::ATR_ERRMODE => \PDO::ERRMODE_EXCEPTION
  4. );


Zapomniałem o tamtym (IMG:style_emoticons/default/wink.gif)

Dziękuje za pomoc haha (IMG:style_emoticons/default/biggrin.gif)
Go to the top of the page
+Quote Post
pedro84
post
Post #26





Grupa: Nieautoryzowani
Postów: 2 249
Pomógł: 305
Dołączył: 2.10.2006

Ostrzeżenie: (0%)
-----


Będziesz pamiętał na przyszłość (mam nadzieję (IMG:style_emoticons/default/smile.gif) ). Aż się chce takim ludziom pomagać, gdzie mały hint wystarczy, żeby sami doszli do rozwiązania.
Go to the top of the page
+Quote Post
Ultear
post
Post #27





Grupa: Zarejestrowani
Postów: 52
Pomógł: 3
Dołączył: 9.12.2013

Ostrzeżenie: (0%)
-----


Dopiero zaczynam tematy z przestrzeniami nazw, dlatego tak (IMG:style_emoticons/default/smile.gif) Jeszcze raz dziękuje za pomoc
Go to the top of the page
+Quote Post

2 Stron V  < 1 2
Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.09.2025 - 13:59