$shipType = (string) $shipType;
$shipName = (string) $shipName;
- // Is the other one a contract partner?
- if (is_null($partnerInstance)) {
- // Opps! Empty partner instance?
- throw new NullPointerException($partnerInstance, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!is_object($partnerInstance)) {
- // Not an object! ;-(
- throw new NoObjectException($partnerInstance, self::EXCEPTION_IS_NO_OBJECT);
- } elseif (!method_exists($partnerInstance, 'isContractPartner')) {
- // Does not have the required feature (method)
- throw new MissingMethodException(array($partnerInstance, 'isContractPartner'), self::EXCEPTION_MISSING_METHOD);
- }
-
// Get new instance
$contractInstance = new WorksContract();
}
// Schiff-Instanz temporaer erzeugen und in den Bauvertrag einfuegen
- $eval = sprintf("\$contractInstance->setShipInstance(%s::create%s(\"%s\"));",
- $shipType,
- $shipType,
- $shipName
- );
-
- // Debug message
- if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $contractInstance->getDebugInstance()->output(sprintf("[%s:%d] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
- __CLASS__,
- __LINE__,
- htmlentities($eval)
- ));
+ $shipInstance = ObjectFactory::createObjectByName($shipType, array($shipName));
+ $contractInstance->setShipInstance($shipInstance);
- // Execute constructed command
- @eval($eval);
+ // Remove the ship instance
+ unset($shipInstance);
// Set itself as contract partner
$contractInstance->setContractPartner($partnerInstance);
));
// Initialize the instance (shall not be done within dynamic part)
- $instance = null;
-
- // Prepare the big command for everthing
- $eval = "try {
- \$instance = ".$shipPart."::create".$shipPart."(";
- foreach ($dataArray as $pIdx => $parts) {
- if (is_string($parts)) {
- // String einbauen
- $eval .= "\"".$parts."\", ";
- } elseif (is_array($parts)) {
- // Ist ein weiteres Array!
- $eval .= "array(";
- foreach ($parts as $idx2 => $sub) {
- $eval .= "'".$idx2."' => ";
- if (is_string($sub)) {
- // Ist erneut ein String
- $eval .= "\"".$sub."\"";
- } elseif (is_array($sub)) {
- // Wird nicht mehr unterstuetzt!
- ApplicationEntryPoint::app_die("No more arrays!");
- } else {
- // Direkt anhaengen
- $eval .= $sub;
- }
- $eval .= ", ";
- }
-
- // Letztes Komma entfernen
- $eval = substr($eval, 0, -2);
- $eval .= "), ";
- } else {
- // Etwas anderes direkt!
- $eval .= $parts.", ";
- }
- }
+ $partInstance = null;
- // Letztes Komma abhaengen
- $eval = substr($eval, 0, -2);
- $eval .= ");
-} catch (DimNotFoundInArrayException \$e) {
- \$this->getDebugInstance()->output(sprintf(\"[main:] Die <strong>%s</strong> konnte nicht vervollständigt werden. Grund: <strong>%s</strong><br />\\n\",
- \$this->getShipInstance()->getShipName(),
- \$e->getMessage()
- ));
- \$instance = null;
-}";
-
- // Debug message
- if ((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[Ship:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
- htmlentities($eval)
- ));
-
- // Code ausfuhren
- @eval($eval);
-
- // Try to add the ship part to the contract
+ // Try to get an instance for this ship part
try {
+ $partInstance = ObjectFactory::createObjectByName($shipPart, $dataArray);
+ } catch (DimNotFoundInArrayException $e) {
+ $this->getDebugInstance()->output(sprintf("[main:] Die <strong>%s</strong> konnte nicht vervollständigt werden. Grund: <strong>%s</strong><br />",
+ $this->getShipInstance()->getShipName(),
+ $e->getMessage()
+ ));
+
+ // Debug message
if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] Versuche ein Schiffsteil in den Bauvertrag aufzunehmen.<br />\n",
__CLASS__,
__LINE__
));
- if (!$instance instanceof ConstructableShipPart) {
+
+ // Is this ship part constructable?
+ if (!$partInstance instanceof ConstructableShipPart) {
// Ship part not constructable!
throw new ShipPartNotConstructableException(array($shipPart), self::EXCEPTION_NOT_CONSTRUCTABLE);
- } elseif (!$this->getShipInstance()->createShipPart($instance, $parentPart)) {
+ } elseif (!$this->getShipInstance()->createShipPart($partInstance, $parentPart)) {
// Schiff konnte nicht gebaut werden!
throw new ShipNotConstructedException(sprintf("Das Schiff <strong>%s</strong> konnte wegen eines Fehlers nicht gebaut werden. Siehe obere Meldungen.",
$this->getShipInstance()->getShipName()
}
// Get price for this item
- $price = $this->getMerchantInstance()->getPriceFromList($instance);
+ $price = $this->getMerchantInstance()->getPriceFromList($partInstance);
// Final debug message
if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s</strong> kostet <strong>%s</strong>.<br />\n",
__CLASS__,
__LINE__,
- $instance->getObjectDescription(),
+ $partInstance->getObjectDescription(),
$this->getMerchantInstance()->formatCurrency($price)
));
// Add price
- $instance->setPrice($price);
+ $partInstance->setPrice($price);
// Final debug message
if ((defined('DEBUG_CONTRACT')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:%d] <strong>%s</strong> wurde in den Bauvertrag aufgenommen.<br />\n",
__CLASS__,
__LINE__,
- $instance->getObjectDescription()
+ $partInstance->getObjectDescription()
));
}