Browse Source

Start to cleanup old code in Moxl

Use __call to remove all the accessors
pull/676/head
Timothée Jaussoin 8 years ago
parent
commit
d66f97b107
  1. 1
      app/widgets/Presence/Presence.php
  2. 1
      app/widgets/Rooms/Rooms.php
  3. 3
      lib/moxl/src/Moxl/Stanza/Roster.php
  4. 24
      lib/moxl/src/Moxl/Stanza/Storage.php
  5. 10
      lib/moxl/src/Moxl/Xec/Action.php
  6. 8
      lib/moxl/src/Moxl/Xec/Action/Presence/Away.php
  7. 8
      lib/moxl/src/Moxl/Xec/Action/Presence/Chat.php
  8. 30
      lib/moxl/src/Moxl/Xec/Action/Presence/DND.php
  9. 20
      lib/moxl/src/Moxl/Xec/Action/Presence/Muc.php
  10. 45
      lib/moxl/src/Moxl/Xec/Action/Presence/Subscribe.php
  11. 40
      lib/moxl/src/Moxl/Xec/Action/Presence/Subscribed.php
  12. 61
      lib/moxl/src/Moxl/Xec/Action/Presence/Unavailable.php
  13. 49
      lib/moxl/src/Moxl/Xec/Action/Presence/Unsubscribe.php
  14. 40
      lib/moxl/src/Moxl/Xec/Action/Presence/Unsubscribed.php
  15. 30
      lib/moxl/src/Moxl/Xec/Action/Presence/XA.php
  16. 8
      lib/moxl/src/Moxl/Xec/Action/Storage/Get.php
  17. 16
      lib/moxl/src/Moxl/Xec/Action/Storage/Set.php

1
app/widgets/Presence/Presence.php

@ -161,7 +161,6 @@ class Presence extends \Movim\Widget\Base
// We refresh our personnal feed
function ajaxFeedRefresh()
{
// Replace me with GetItemsId when moving from Metronome
$r = new GetItemsId;
$r->setTo($this->user->jid)
->setNode('urn:xmpp:microblog:0')

1
app/widgets/Rooms/Rooms.php

@ -369,7 +369,6 @@ class Rooms extends \Movim\Widget\Base
$pu = new Unavailable;
$pu->setTo($room)
->setResource($resource)
->setMuc()
->request();
}

3
lib/moxl/src/Moxl/Stanza/Roster.php

@ -2,7 +2,8 @@
namespace Moxl\Stanza;
class Roster {
class Roster
{
static function get()
{
$dom = new \DOMDocument('1.0', 'UTF-8');

24
lib/moxl/src/Moxl/Stanza/Storage.php

@ -5,26 +5,30 @@
namespace Moxl\Stanza;
class Storage {
static function set($xmlns, $data)
class Storage
{
private function prepareQuery($xmlns, $data = false)
{
$dom = new \DOMDocument('1.0', 'utf-8');
$query = $dom->createElementNS('jabber:iq:private', 'query');
$data = $dom->createElementNS($xmlns, 'data', $data);
$data = ($data)
? $dom->createElement('data', $data)
: $dom->createElement('data');
$data->setAttribute('xmlns', $xmlns);
$query->appendchild($data);
$xml = \Moxl\API::iqWrapper($query, false, 'set');
return $query;
}
static function set($xmlns, $data)
{
$xml = \Moxl\API::iqWrapper(self::prepareQuery($xmlns, $data), false, 'set');
\Moxl\API::request($xml);
}
static function get($xmlns)
{
$dom = new \DOMDocument('1.0', 'utf-8');
$query = $dom->createElementNS('jabber:iq:private', 'query');
$data = $dom->createElementNS($xmlns, 'data');
$query->appendchild($data);
$xml = \Moxl\API::iqWrapper($query, false, 'get');
$xml = \Moxl\API::iqWrapper(self::prepareQuery($xmlns), false, 'get');
\Moxl\API::request($xml);
}

10
lib/moxl/src/Moxl/Xec/Action.php

@ -45,5 +45,15 @@ abstract class Action extends Payload
return $instances;
}
public function __call($name, $args)
{
if (substr($name, 0, 3) == 'set') {
$property = '_' . strtolower(substr($name, 3));
$this->$property = $args[0];
return $this;
}
}
abstract public function request();
}

8
lib/moxl/src/Moxl/Xec/Action/Presence/Away.php

@ -30,7 +30,7 @@ use App\Presence as DBPresence;
class Away extends Action
{
private $_status;
protected $_status;
public function request()
{
@ -38,12 +38,6 @@ class Away extends Action
Presence::away($this->_status);
}
public function setStatus($status)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false)
{
$presence = DBPresence::findByStanza($stanza);

8
lib/moxl/src/Moxl/Xec/Action/Presence/Chat.php

@ -8,7 +8,7 @@ use App\Presence as DBPresence;
class Chat extends Action
{
private $_status;
protected $_status;
public function request()
{
@ -16,12 +16,6 @@ class Chat extends Action
Presence::chat($this->_status);
}
public function setStatus($status)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false)
{
$presence = DBPresence::findByStanza($stanza);

30
lib/moxl/src/Moxl/Xec/Action/Presence/DND.php

@ -1,26 +1,4 @@
<?php
/*
* DND.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -30,7 +8,7 @@ use App\Presence as DBPresence;
class DND extends Action
{
private $_status;
protected $_status;
public function request()
{
@ -38,12 +16,6 @@ class DND extends Action
Presence::DND($this->_status);
}
public function setStatus($status)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false)
{
$presence = DBPresence::findByStanza($stanza);

20
lib/moxl/src/Moxl/Xec/Action/Presence/Muc.php

@ -9,10 +9,10 @@ use Movim\Session;
class Muc extends Action
{
private $_to;
private $_nickname;
private $_mam = false;
private $_mam2 = false;
protected $_to;
protected $_nickname;
protected $_mam = false;
protected $_mam2 = false;
public function request()
{
@ -31,18 +31,6 @@ class Muc extends Action
Presence::muc($this->_to, $this->_nickname, $this->_mam);
}
public function setTo($to)
{
$this->_to = $to;
return $this;
}
public function setNickname($nickname)
{
$this->_nickname = $nickname;
return $this;
}
public function enableMAM()
{
$this->_mam = true;

45
lib/moxl/src/Moxl/Xec/Action/Presence/Subscribe.php

@ -1,26 +1,4 @@
<?php
/*
* Away.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -29,28 +7,17 @@ use Moxl\Stanza\Presence;
class Subscribe extends Action
{
private $_to;
private $_status;
public function request()
protected $_to;
protected $_status;
public function request()
{
$this->store();
Presence::subscribe($this->_to, $this->_status);
}
public function setTo($to)
{
$this->_to = $to;
return $this;
}
public function setStatus($status)
public function handle($stanza, $parent = false)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false) {
$this->pack($this->_to);
$this->deliver();
}

40
lib/moxl/src/Moxl/Xec/Action/Presence/Subscribed.php

@ -1,26 +1,4 @@
<?php
/*
* Subscribed.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -29,25 +7,17 @@ use Moxl\Stanza\Presence;
class Subscribed extends Action
{
private $_to;
public function request()
protected $_to;
public function request()
{
$this->store();
Presence::subscribed($this->_to);
}
public function setTo($to)
public function handle($stanza, $parent = false)
{
$this->_to = $to;
return $this;
}
public function handle($stanza, $parent = false) {
$this->pack($this->_to);
$this->deliver();
}
public function load($key) {}
public function save() {}
}

61
lib/moxl/src/Moxl/Xec/Action/Presence/Unavailable.php

@ -1,26 +1,4 @@
<?php
/*
* Unavailable.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -29,11 +7,10 @@ use Moxl\Stanza\Presence;
class Unavailable extends Action
{
private $_status;
private $_to;
private $_type;
private $_resource;
private $_muc = false;
protected $_status;
protected $_to;
protected $_type;
protected $_resource;
public function request()
{
@ -41,36 +18,6 @@ class Unavailable extends Action
Presence::unavailable($this->_to.'/'.$this->_resource, $this->_status, $this->_type);
}
public function setStatus($status)
{
$this->_status = $status;
return $this;
}
public function setTo($to)
{
$this->_to = $to;
return $this;
}
public function setResource($resource)
{
$this->_resource = $resource;
return $this;
}
public function setType($type)
{
$this->_type = $type;
return $this;
}
public function setMuc()
{
$this->_muc = true;
return $this;
}
public function handle($stanza, $parent = false)
{
$this->deliver();

49
lib/moxl/src/Moxl/Xec/Action/Presence/Unsubscribe.php

@ -1,26 +1,4 @@
<?php
/*
* Unsubscribe.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -29,31 +7,16 @@ use Moxl\Stanza\Presence;
class Unsubscribe extends Action
{
private $_to;
private $_status;
public function request()
protected $_to;
protected $_status;
public function request()
{
$this->store();
Presence::unsubscribe($this->_to, $this->_status);
}
public function setTo($to)
{
$this->_to = $to;
return $this;
}
public function setStatus($status)
public function handle($stanza, $parent = false)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false) {
var_dump('Presence Unsubscribe');
}
public function load($key) {}
public function save() {}
}

40
lib/moxl/src/Moxl/Xec/Action/Presence/Unsubscribed.php

@ -1,26 +1,4 @@
<?php
/*
* Unsubscribed.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -29,25 +7,17 @@ use Moxl\Stanza\Presence;
class Unsubscribed extends Action
{
private $_to;
public function request()
protected $_to;
public function request()
{
$this->store();
Presence::unsubscribed($this->_to);
}
public function setTo($to)
public function handle($stanza, $parent = false)
{
$this->_to = $to;
return $this;
}
public function handle($stanza, $parent = false) {
$this->pack($this->_to);
$this->deliver();
}
public function load($key) {}
public function save() {}
}

30
lib/moxl/src/Moxl/Xec/Action/Presence/XA.php

@ -1,26 +1,4 @@
<?php
/*
* XA.php
*
* Copyright 2012 edhelas <edhelas@edhelas-laptop>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
namespace Moxl\Xec\Action\Presence;
@ -30,7 +8,7 @@ use App\Presence as DBPresence;
class XA extends Action
{
private $_status;
protected $_status;
public function request()
{
@ -38,12 +16,6 @@ class XA extends Action
Presence::XA($this->_status);
}
public function setStatus($status)
{
$this->_status = $status;
return $this;
}
public function handle($stanza, $parent = false)
{
$presence = DBPresence::findByStanza($stanza);

8
lib/moxl/src/Moxl/Xec/Action/Storage/Get.php

@ -31,7 +31,7 @@ use App\User;
class Get extends Action
{
private $_xmlns;
protected $_xmlns;
public function request()
{
@ -39,12 +39,6 @@ class Get extends Action
Storage::get($this->_xmlns);
}
public function setXmlns($xmlns)
{
$this->_xmlns = $xmlns;
return $this;
}
public function handle($stanza, $parent = false)
{
if($stanza->query->data) {

16
lib/moxl/src/Moxl/Xec/Action/Storage/Set.php

@ -29,8 +29,8 @@ use Moxl\Stanza\Storage;
class Set extends Action
{
private $_xmlns;
private $_data;
protected $_xmlns;
protected $_data;
public function request()
{
@ -38,18 +38,6 @@ class Set extends Action
Storage::set($this->_xmlns, $this->_data);
}
public function setXmlns($xmlns)
{
$this->_xmlns = $xmlns;
return $this;
}
public function setData($data)
{
$this->_data = $data;
return $this;
}
public function handle($stanza, $parent = false)
{
$this->pack(unserialize($this->_data));

Loading…
Cancel
Save