Skip to content

Commit

Permalink
Update Pluf_Signal to the new version
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Jul 6, 2020
1 parent 0e0715f commit 93b4267
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
3 changes: 2 additions & 1 deletion examples/NoteBook/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ function init()
$this->_a['cols'] = [
// It is mandatory to have an "id" column.
'id' => [
// DB
'type' => Schema::SEQUENCE,
'primary' => true,
// It is automatically added.
'blank' => true,
// View
'editable' => false,
'readable' => true
],
Expand Down
4 changes: 3 additions & 1 deletion src6/Pluf/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
namespace Pluf\Pluf;

use Pluf\Signal;

class Module extends \Pluf\Module
{

Expand All @@ -41,7 +43,7 @@ public function init(\Pluf $bootstrap): void
* These details are used to generated the methods
* to retrieve related models from each model.
*/
\Pluf_Signal::connect('Pluf_Dispatcher::postDispatch', array(
Signal::connect('Pluf_Dispatcher::postDispatch', array(
'\\Pluf\\Logger',
'flushHandler'
), 'Pluf_Dispatcher');
Expand Down
4 changes: 2 additions & 2 deletions src6/Pluf/Queue/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
namespace Pluf\Pluf\Queue;

use Pluf\Signal;
use Pluf\Pluf\Queue;
use Pluf;
use Pluf_Signal;

/**
* Class to process a Pluf_Queue.
Expand Down Expand Up @@ -90,7 +90,7 @@ public static function process()
*
* array('item' => $item, 'queue' => $queue);
*/
Pluf_Signal::send('Pluf_Queue_Processor::process', 'Pluf_Queue_Process', $q);
Signal::send('Pluf_Queue_Processor::process', 'Pluf_Queue_Process', $q);
$q['queue']->lock = 2;
$q['queue']->update();
}
Expand Down
4 changes: 2 additions & 2 deletions src6/Processors/DispatcherSignals.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
namespace Pluf\Processors;

use Pluf\ProcessorAdaptor;
use Pluf\Signal;
use Pluf\HTTP\Request;
use Pluf\HTTP\Response;
use Pluf_Signal;

class DispatcherSignals extends ProcessorAdaptor
{
Expand Down Expand Up @@ -46,7 +46,7 @@ public function response(Request $request, Response $response): Response
* array('request' => $request,
* 'response' => $response)
*/
Pluf_Signal::send('Pluf_Dispatcher::postDispatch', 'Pluf_Dispatcher', [
Signal::send('Pluf_Dispatcher::postDispatch', 'Pluf_Dispatcher', [
'request' => $request,
'response' => $response
]);
Expand Down
6 changes: 3 additions & 3 deletions src6/Processors/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
namespace Pluf\Processors;

use Pluf\Exception;
use Pluf\Processor;
use Pluf\Signal;
use Pluf\Data\Query;
use Pluf\HTTP\Request;
use Pluf\HTTP\Response;
use Pluf;
use Pluf_Signal;
use Pluf\Processor;

/**
* Allow a session object in the request.
Expand Down Expand Up @@ -165,7 +165,7 @@ public static function processContext($signal, &$params)
}

// TODO: maso, 2020: move to module initials
Pluf_Signal::connect('Pluf_Template_Context_Request::construct', array(
Signal::connect('Pluf_Template_Context_Request::construct', array(
'Pluf_Middleware_Session',
'processContext'
));
3 changes: 2 additions & 1 deletion src/Pluf/Signal.php → src6/Signal.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Pluf;

/**
* Signal system.
*/
class Pluf_Signal
class Signal
{

/**
Expand Down
31 changes: 17 additions & 14 deletions src6/Template/Compiler.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
namespace Pluf\Template;

use Pluf\Signal;
use Exception;
use Pluf;
use Pluf_Signal;

/**
* Class to compile a template file into the corresponding PHP script
Expand Down Expand Up @@ -148,11 +148,11 @@ class Compiler
* in the configuration of the application.
*/
protected $_allowedTags = array(
'url' => '\\Pluf\\Template\\Tag\\UrlTag',
'aurl' => '\\Pluf\\Template\\Tag\\Rurl',
'media' => '\\Pluf\\Template\\Tag\\MediaUrl',
'amedia' => '\\Pluf\\Template\\Tag\\RmediaUrl',
'aperm' => '\\Pluf\\Template\\Tag\\APerm',
'url' => '\\Pluf\\Template\\Tag\\UrlTag',
'aurl' => '\\Pluf\\Template\\Tag\\Rurl',
'media' => '\\Pluf\\Template\\Tag\\MediaUrl',
'amedia' => '\\Pluf\\Template\\Tag\\RmediaUrl',
'aperm' => '\\Pluf\\Template\\Tag\\APerm',
'getmsgs' => '\\Pluf\\Template\\Tag\\Messages'
);

Expand Down Expand Up @@ -244,7 +244,7 @@ function __construct($template_file, $folders = array(), $load = true)
'tags' => array(),
'modifiers' => array()
);
Pluf_Signal::send('Pluf_Template_Compiler::construct_template_tags_modifiers', 'Pluf_Template_Compiler', $params);
Signal::send('Pluf_Template_Compiler::construct_template_tags_modifiers', 'Pluf_Template_Compiler', $params);
$this->_allowedTags = array_merge($this->_allowedTags, $params['tags'], Pluf::f('template_tags', array()));
$this->_modifier = array_merge($this->_modifier, $params['modifiers'], Pluf::f('template_modifiers', array()));
foreach ($this->_allowedTags as $name => $model) {
Expand Down Expand Up @@ -275,6 +275,7 @@ function compile()
$tplcontent = preg_replace('!<\?php(.*?)\?>!s', '', $tplcontent);
// Catch the litteral blocks and put them in the
// $this->_literals stack
$_match = [];
preg_match_all('!{literal}(.*?){/literal}!s', $tplcontent, $_match);
$this->_literals = $_match[1];
$tplcontent = preg_replace("!{literal}(.*?){/literal}!s", '{literal}', $tplcontent);
Expand All @@ -295,13 +296,13 @@ function compile()
function getCompiledTemplate()
{
$result = $this->compile();
// if (count($this->_usedModifiers)) {
// $code = array();
// // foreach ($this->_usedModifiers as $modifier) {
// // $code[] = 'Pluf::loadFunction(\'' . $modifier . '\'); ';
// // }
// $result = '<?php ' . implode("\n", $code) . '? >' . $result;
// }
// if (count($this->_usedModifiers)) {
// $code = array();
// // foreach ($this->_usedModifiers as $modifier) {
// // $code[] = 'Pluf::loadFunction(\'' . $modifier . '\'); ';
// // }
// $result = '<?php ' . implode("\n", $code) . '? >' . $result;
// }
// Clean the output
$result = str_replace(array(
'?><?php',
Expand All @@ -324,6 +325,7 @@ function compileBlocks()
$tplcontent = $this->templateContent;
$this->_extendedTemplate = '';
// Match extends on the first line of the template
$_match = [];
if (preg_match("!{extends\s['\"](.*?)['\"]}!", $tplcontent, $_match)) {
$this->_extendedTemplate = $_match[1];
}
Expand Down Expand Up @@ -403,6 +405,7 @@ function _callback($matches)
return '%%' . substr($tok[0], 1) . '%%';
}
} else {
$m = [];
if (! preg_match('/^(\/?[a-zA-Z0-9_]+)(?:(?:\s+(.*))|(?:\((.*)\)))?$/', $tag, $m)) {
trigger_error(sprintf(__('Invalid function syntax: %s'), $tag), E_USER_ERROR);
return '';
Expand Down
4 changes: 2 additions & 2 deletions src6/Template/Context/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
namespace Pluf\Template\Context;

use Pluf\Signal;
use Pluf\Template\ContextVars;
use Pluf;
use Pluf_Signal;

/**
* Class storing the data that are then used in the template.
Expand Down Expand Up @@ -62,7 +62,7 @@ function __construct($request, $vars = array())
* array('request' => $request,
* 'context' => array());
*/
Pluf_Signal::send('Pluf_Template_Context_Request::construct', 'Pluf_Template_Context_Request', $params);
Signal::send('Pluf_Template_Context_Request::construct', 'Pluf_Template_Context_Request', $params);
$this->_vars = new ContextVars($params['context']);
}
}

0 comments on commit 93b4267

Please sign in to comment.