Skip to content

Commit

Permalink
integrate composer and use composer autoloader, remove files of libra…
Browse files Browse the repository at this point in the history
…ries loaded with composer, PHP -> 5.5 (already used in many files)
  • Loading branch information
Mairu committed Jul 24, 2016
1 parent c3228c4 commit b8678c1
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 2,313 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ application/modules/smilies/static/img
web.config
robots.txt
.user.ini

/vendor/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ Ilch 2.0 ist der direkte Nachfolger der Ilch Versionen 1.1.
- Aufrufen der "/index.php"
- Den Bildschirmanweisungen folgen

### Installation der Entwicklerversion
- Dateien in das Webverzeichnis legen
- [Composer installieren](https://getcomposer.org/download/) (falls noch nicht geschehen)
- `composer install` ausführen, um die Abhängigkeiten zu laden
- Aufrufen der "/index.php"
- Den Bildschirmanweisungen folgen

### Voraussetzungen
- PHP Version 5.4
- PHP Version 5.5
- MySQL, MariaDB oder Equivalent

### Support/Dokumentation
Expand Down
2 changes: 0 additions & 2 deletions application/libraries/Ilch/Design/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ public function escape($string)
*/
public function getHtmlFromBBCode($bbcode)
{
require_once APPLICATION_PATH.'/libraries/jbbcode/Parser.php';

$parser = new \JBBCode\Parser();
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());

Expand Down
73 changes: 21 additions & 52 deletions application/libraries/Ilch/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,39 @@

namespace Ilch;

require_once APPLICATION_PATH.'/libraries/Ilch/Functions.php';

/**
* Class Loader for loading classes of modules
*/
class Loader
{
/**
* @var string[]
*/
protected $namespaces = ['Ilch'];

/**
* Initialize "spl_autoload_register".
*/
public function __construct()
{
/**
* Loads all needed files for the given class.
*
* @param string $class
* @throws \InvalidArgumentException
*/
spl_autoload_register(function ($class) {
$class = str_replace('\\', '/', $class);
$classParts = explode('/', $class);
$path = APPLICATION_PATH;
$type = 'modules';

/*
* Libraries path handling.
*/
foreach ($this->namespaces as $nameSpace) {
if (strpos($classParts[0], $nameSpace) !== false) {
$type = 'libraries';
$path = $path.'/libraries';
break;
}
}

/*
* Modules path handling.
*/
if ($type == 'modules') {
$lastClassPart = $classParts[count($classParts)-1];
unset($classParts[count($classParts)-1]);
$classParts = array_map('strtolower', $classParts);
$class = implode('/', $classParts).'/'.$lastClassPart;
}

/*
* General loading handling.
*/
if (file_exists($path.'/'. $class . '.php')) {
require_once($path.'/'. $class . '.php');
}
});
spl_autoload_register([$this, 'loadModuleClass']);
}

/**
* Adds loader namespace.
*
* @param string $namespace
* Load a module class
* @param string $class
*/
public function registNamespace($namespace)
private function loadModuleClass($class)
{
$this->namespaces[$namespace] = $namespace;
$class = str_replace('\\', '/', $class);
$classParts = explode('/', $class);

$lastClassPart = array_pop($classParts);
$classParts = array_map('strtolower', $classParts);

$filePath = APPLICATION_PATH . '/' . implode('/', $classParts) . '/'.$lastClassPart . '.php';

/*
* General loading handling.
*/
if (file_exists($filePath)) {
require $filePath;
}
}
}

Loading

14 comments on commit b8678c1

@blackcoder87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arbeitest du hier noch dran oder übernimmst Teile davon? Ansonsten würde ich gerne den Teil übernehmen, welcher password_compat entfernt.

https://github.com/blackcoder87/Ilch-2.0/commit/743f7d58a2667c31e5161c8982806dad6e051b61

@Mairu
Copy link
Member Author

@Mairu Mairu commented on b8678c1 Aug 17, 2016 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c0r1an
Copy link
Member

@c0r1an c0r1an commented on b8678c1 Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich bin gerade im Urlaub :) sowie ich dafür Zeit habe schau ich noch mal drüber...Ich denke mal zu nächste Woche.

@c0r1an
Copy link
Member

@c0r1an c0r1an commented on b8678c1 Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Ich finde Composer ist keine schlechte lösung...das vereinfacht natürlich einiges. Ich würde auch eher die anderen fragen was sie davon halten.

@blackcoder87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wie sieht das aus mit dem Composer auf Webspace?

@Mairu
Copy link
Member Author

@Mairu Mairu commented on b8678c1 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muss nicht installiert werden, man müsste "nur" das Skript ändern, dass das "Ilch 2.0"-Archiv erstellt, welches man runterladen kann. Dort muss composer install ausgeführt werden, bevor die Dateien in das Archiv gepackt werden.

Wenn alle dafür wären, könnte ich den Branch mergen und das Buildscript entsprechend anpassen.

@c0r1an
Copy link
Member

@c0r1an c0r1an commented on b8678c1 Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich bin dafür.

@kveldscholten
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wofür ist der Composer den genau? Hab zwar ein bisschen gegoogelt aber so recht konnte ich nichts mit den Infos anfangen

@dastiii
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getcomposer.org/doc/00-intro.md
Das erklärt es denke ich ganz gut.

Wäre jedenfalls ne sehr gute Sache.

@blackcoder87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also hätten wir folgende Vorteile? (jBBCode als Beispiel)

  • jBBCode kann aus unserem Repository gelöscht werden.
  • Bei einem Ilch-Update bräuchten wir keine neue Version von jBBCode ausliefern, sondern nur eine aktualisierte composer.json (composer.lock?)?
  • Der Download von Ilch 2 ist kleiner, weil jBBCode nicht mitgeliefert werden muss.

Fehlt noch was?

Wie läuft das mit Konfigurationsdateien von z.B. CKEditor?
Auch dürften wir keine modifizierten Versionen von z.B. CKEditor haben, damit wir Composer nutzen können oder? (Aktuell sieht es aus als hätten wir da was dran geändert)

Leider wird anscheinend noch nichts was von Composer heruntergeladen wird irgendwie verifiziert (wie bei unserem Ilch-Updater).
composer/composer#38
composer/composer#4022

😨

@Mairu
Copy link
Member Author

@Mairu Mairu commented on b8678c1 Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also im Paket, was wir zum Download anbieten, würde ich das vendor Verzeichnis schon mit ausliefern. Ansonsten müssten die Benutzer selbst Composer haben und den Befehl composer install ausführen müssen.
Alternativ könnte man dies in Installations/Update Prozess integrieren (http://stackoverflow.com/questions/17219436/run-composer-with-a-php-script-in-browser). Früher gab es Hoster, die keine Verbindung zu anderen Hosts aufbauen konnten, dort würde das auch nicht gehen. Ich weiß allerdings nicht, ob sich das mittlerweile geändert hat.

Vorteile:

  • Repository wird kleiner (Bibliotheken sind selbst nicht mehr Teil des Repositories)
  • Neue Versionen von verwendeten Bibliotheken können einfacher installiert werden - composer update
  • Neue Abhängigkeiten können einfacher installiert werden
  • Einfacheres Autoloading verwendeter Bibliotheken

Nachteile:

  • Zusätzliches Tool
  • komplizierteres "Installationsverfahren" für Entwickler (es muss ein Befehl ausgeführt werden, siehe Readme)
  • Anpassungen des travis und build scriptes erforderlich

Um die Sache mit dem Verifizieren anzusprechen. Gibt es noch nicht, wie es aussieht. Allerdings werden die Pakete mittlerweile nur noch über https heruntergeladen und das Archiv mit einer Checksumme überprüft. Also es wird kein anderes Archiv verwendet werden, als das was in der composer.lock festgehalten ist. Ggf. müsste man das nochmal genau überprüfen und Änderungen vornehmen, da in composer.lock in diesem Branch z.B. gerade keine shasum drin steht.

@blackcoder87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wenn nur wir den Composer ausführen um bequem alle Bibliotheken in den richtigen Versionen herunterladen zu können, dann habe ich auf jeden Fall nichts gegen das Einbinden vom Composer.

Die shasum für die genutzen Bibliotheken sollten wir noch in die composer.lock eintragen, nachdem wir überprüft haben ob die Bibliotheken in Ordnung sind. Anscheinend verweigert composer install die Installation, wenn die shasum nicht passt - das ist gut. :)
http://stackoverflow.com/questions/31910786/what-is-shasum-in-composer-lock

In den Installations/Update-Prozess würde ich das noch nicht einbauen.

In diesem Branch steht auch noch paar mal PHP 5.5, anstatt 5.6.

  • Readme.md
  • composer.json
  • composer.lock?
  • index.php

@Mairu
Copy link
Member Author

@Mairu Mairu commented on b8678c1 Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naja der Branch ist ja älter, noch zu der Zeit erstellt, als es im master noch auf PHP 5.4 stand.
Ich würde alles nötige natürlich nochmal überarbeiten, bevor ich es in den master merge.

@blackcoder87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, habe es nur zur Sicherheit erwähnt. :)

Please sign in to comment.