2011-11-23 04:17:06 +01:00
|
|
|
<?php
|
2013-11-05 17:12:09 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Magallanes package.
|
|
|
|
*
|
|
|
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-11-23 04:17:06 +01:00
|
|
|
class Mage_Task_Factory
|
|
|
|
{
|
|
|
|
/**
|
2012-09-24 00:33:10 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string|array $taskData
|
2012-01-04 02:25:42 +01:00
|
|
|
* @param boolean $inRollback
|
2011-11-23 04:17:06 +01:00
|
|
|
* @return Mage_Task_TaskAbstract
|
|
|
|
*/
|
2012-09-24 00:33:10 +02:00
|
|
|
public static function get($taskData, Mage_Config $taskConfig, $inRollback = false, $stage = null)
|
2011-11-23 04:17:06 +01:00
|
|
|
{
|
2012-09-24 00:33:10 +02:00
|
|
|
if (is_array($taskData)) {
|
|
|
|
$taskName = $taskData['name'];
|
|
|
|
$taskParameters = $taskData['parameters'];
|
|
|
|
} else {
|
|
|
|
$taskName = $taskData;
|
|
|
|
$taskParameters = array();
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:38:52 +01:00
|
|
|
$instance = null;
|
2012-02-05 03:42:54 +01:00
|
|
|
$taskName = ucwords(str_replace('-', ' ', $taskName));
|
|
|
|
$taskName = str_replace(' ', '', $taskName);
|
2012-09-24 00:33:10 +02:00
|
|
|
|
2011-11-23 12:38:52 +01:00
|
|
|
if (strpos($taskName, '/') === false) {
|
|
|
|
Mage_Autoload::loadUserTask($taskName);
|
|
|
|
$className = 'Task_' . ucfirst($taskName);
|
2012-09-24 00:33:10 +02:00
|
|
|
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
|
2011-11-23 12:38:52 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$taskName = str_replace(' ', '_', ucwords(str_replace('/', ' ', $taskName)));
|
|
|
|
$className = 'Mage_Task_BuiltIn_' . $taskName;
|
2012-09-24 00:33:10 +02:00
|
|
|
$instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
|
2011-11-23 12:38:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert($instance instanceOf Mage_Task_TaskAbstract);
|
|
|
|
return $instance;
|
2011-11-23 04:17:06 +01:00
|
|
|
}
|
|
|
|
}
|