Browse Source

define dependencies

PHP-GTK3
yggverse 2 months ago
parent
commit
137b9926e1
  1. 19
      src/Abstract/Entity/Browser/Container/Page/Content/Markup.php
  2. 25
      src/Abstract/Entity/Button.php
  3. 31
      src/Abstract/Entity/Entry.php
  4. 2
      src/Model/Connection/Nex.php
  5. 14
      src/Model/Database.php
  6. 13
      src/Model/Filesystem.php
  7. 13
      src/Model/Pool.php

19
src/Abstract/Entity/Browser/Container/Page/Content/Markup.php

@ -4,11 +4,14 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content; namespace Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Content;
use \GdkEvent;
use \GtkLabel;
use \Yggverse\Yoda\Entity\Browser\Container\Page\Content; use \Yggverse\Yoda\Entity\Browser\Container\Page\Content;
abstract class Markup abstract class Markup
{ {
public \GtkLabel $gtk; public GtkLabel $gtk;
// Dependencies // Dependencies
public Content $content; public Content $content;
@ -23,7 +26,7 @@ abstract class Markup
$this->content = $content; $this->content = $content;
// Init markup label // Init markup label
$this->gtk = new \GtkLabel; $this->gtk = new GtkLabel;
$this->gtk->set_use_markup( $this->gtk->set_use_markup(
true true
@ -55,7 +58,7 @@ abstract class Markup
$this->gtk->connect( $this->gtk->connect(
'activate-link', 'activate-link',
function( function(
\GtkLabel $label, GtkLabel $label,
string $href string $href
) { ) {
return $this->_onActivateLink( return $this->_onActivateLink(
@ -68,8 +71,8 @@ abstract class Markup
$this->gtk->connect( $this->gtk->connect(
'button-press-event', 'button-press-event',
function( function(
\GtkLabel $label, GtkLabel $label,
\GdkEvent $event GdkEvent $event
) { ) {
return $this->_onButtonPressEvent( return $this->_onButtonPressEvent(
$label, $label,
@ -80,13 +83,13 @@ abstract class Markup
} }
abstract protected function _onActivateLink( abstract protected function _onActivateLink(
\GtkLabel $label, GtkLabel $label,
string $href string $href
): bool; ): bool;
abstract protected function _onButtonPressEvent( abstract protected function _onButtonPressEvent(
\GtkLabel $label, GtkLabel $label,
\GdkEvent $event GdkEvent $event
): bool; ): bool;
abstract public function set( abstract public function set(

25
src/Abstract/Entity/Button.php

@ -4,9 +4,16 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Abstract\Entity; namespace Yggverse\Yoda\Abstract\Entity;
use \Exception;
use \GtkButton;
use \GtkIconSize;
use \GtkIconTheme;
use \GtkImage;
abstract class Button abstract class Button
{ {
public \GtkButton $gtk; public GtkButton $gtk;
public const SENSITIVE = false; public const SENSITIVE = false;
public const IMAGE = null; public const IMAGE = null;
@ -16,7 +23,7 @@ abstract class Button
public function __construct() public function __construct()
{ {
// Init button // Init button
$this->gtk = new \GtkButton; $this->gtk = new GtkButton;
if ($this::IMAGE) if ($this::IMAGE)
{ {
@ -47,7 +54,7 @@ abstract class Button
$this->gtk->connect( $this->gtk->connect(
'clicked', 'clicked',
function( function(
\GtkButton $entity GtkButton $entity
) { ) {
$this->_onClick( $this->_onClick(
$entity $entity
@ -57,12 +64,12 @@ abstract class Button
} }
abstract protected function _onClick( abstract protected function _onClick(
\GtkButton $entity GtkButton $entity
): void; ): void;
public function setImage( public function setImage(
?string $image = null, ?string $image = null,
int $size = \GtkIconSize::BUTTON int $size = GtkIconSize::BUTTON
): void ): void
{ {
switch (true) switch (true)
@ -74,7 +81,7 @@ abstract class Button
): ):
$this->gtk->set_image( $this->gtk->set_image(
\GtkImage::new_from_file( GtkImage::new_from_file(
$image, $image,
$size $size
) )
@ -82,12 +89,12 @@ abstract class Button
break; break;
case \GtkIconTheme::get_default()->has_icon( case GtkIconTheme::get_default()->has_icon(
$image $image
): ):
$this->gtk->set_image( $this->gtk->set_image(
\GtkImage::new_from_icon_name( GtkImage::new_from_icon_name(
$image, $image,
$size $size
) )
@ -97,7 +104,7 @@ abstract class Button
default: default:
throw new \Exception; throw new Exception;
} }
} }
} }

31
src/Abstract/Entity/Entry.php

@ -4,9 +4,12 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Abstract\Entity; namespace Yggverse\Yoda\Abstract\Entity;
use \GdkEvent;
use \GtkEntry;
abstract class Entry abstract class Entry
{ {
public \GtkEntry $gtk; public GtkEntry $gtk;
public const LENGTH = 1024; public const LENGTH = 1024;
public const PLACEHOLDER = ''; public const PLACEHOLDER = '';
@ -15,7 +18,7 @@ abstract class Entry
public function __construct() public function __construct()
{ {
$this->gtk = new \GtkEntry; $this->gtk = new GtkEntry;
$this->gtk->set_placeholder_text( $this->gtk->set_placeholder_text(
_($this::PLACEHOLDER) _($this::PLACEHOLDER)
@ -40,7 +43,7 @@ abstract class Entry
$this->gtk->connect( $this->gtk->connect(
'activate', 'activate',
function( function(
\GtkEntry $entry GtkEntry $entry
) { ) {
$this->_onActivate( $this->_onActivate(
$entry $entry
@ -51,8 +54,8 @@ abstract class Entry
$this->gtk->connect( $this->gtk->connect(
'key-release-event', 'key-release-event',
function ( function (
\GtkEntry $entry, GtkEntry $entry,
\GdkEvent $event GdkEvent $event
) { ) {
$this->_onKeyRelease( $this->_onKeyRelease(
$entry, $entry,
@ -64,7 +67,7 @@ abstract class Entry
$this->gtk->connect( $this->gtk->connect(
'changed', 'changed',
function ( function (
\GtkEntry $entry GtkEntry $entry
) { ) {
$this->_onChanged( $this->_onChanged(
$entry $entry
@ -75,8 +78,8 @@ abstract class Entry
$this->gtk->connect( $this->gtk->connect(
'focus-out-event', 'focus-out-event',
function ( function (
\GtkEntry $entry, GtkEntry $entry,
\GdkEvent $event GdkEvent $event
) { ) {
$this->_onFocusOut( $this->_onFocusOut(
$entry, $entry,
@ -87,21 +90,21 @@ abstract class Entry
} }
abstract protected function _onActivate( abstract protected function _onActivate(
\GtkEntry $entry GtkEntry $entry
): void; ): void;
abstract protected function _onKeyRelease( abstract protected function _onKeyRelease(
\GtkEntry $entry, GtkEntry $entry,
\GdkEvent $event GdkEvent $event
): void; ): void;
abstract protected function _onChanged( abstract protected function _onChanged(
\GtkEntry $entry GtkEntry $entry
): void; ): void;
abstract protected function _onFocusOut( abstract protected function _onFocusOut(
\GtkEntry $entry, GtkEntry $entry,
\GdkEvent $event GdkEvent $event
): void; ): void;
public function setLength( public function setLength(

2
src/Model/Connection/Nex.php

@ -26,7 +26,7 @@ class Nex
int $timeout = 15 int $timeout = 15
): void ): void
{ {
$response = (new \Yggverse\Nex\Client)->request( $response = (new Client)->request(
$address->get(), $address->get(),
$timeout $timeout
); );

14
src/Model/Database.php

@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Model; namespace Yggverse\Yoda\Model;
use \PDO;
class Database class Database
{ {
private \PDO $_connection; private PDO $_connection;
private bool $_exists; private bool $_exists;
@ -21,7 +23,7 @@ class Database
); );
// Init database connection // Init database connection
$this->_connection = new \PDO( $this->_connection = new PDO(
sprintf( sprintf(
'sqlite:%s', 'sqlite:%s',
$filename $filename
@ -31,13 +33,13 @@ class Database
); );
$this->_connection->setAttribute( $this->_connection->setAttribute(
\PDO::ATTR_ERRMODE, PDO::ATTR_ERRMODE,
\PDO::ERRMODE_EXCEPTION PDO::ERRMODE_EXCEPTION
); );
$this->_connection->setAttribute( $this->_connection->setAttribute(
\PDO::ATTR_DEFAULT_FETCH_MODE, PDO::ATTR_DEFAULT_FETCH_MODE,
\PDO::FETCH_OBJ PDO::FETCH_OBJ
); );
// Init tables // Init tables

13
src/Model/Filesystem.php

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Model; namespace Yggverse\Yoda\Model;
use \Exception;
use \Finfo;
class Filesystem class Filesystem
{ {
public const MIME_IMAGE_GIF = 'image/gif'; public const MIME_IMAGE_GIF = 'image/gif';
@ -27,13 +30,13 @@ class Filesystem
// Require path // Require path
if (empty($dirname)) if (empty($dirname))
{ {
throw new \Exception; throw new Exception;
} }
// Require absolute path // Require absolute path
if (!str_starts_with($dirname, DIRECTORY_SEPARATOR)) if (!str_starts_with($dirname, DIRECTORY_SEPARATOR))
{ {
throw new \Exception; throw new Exception;
} }
// Init destination // Init destination
@ -64,7 +67,7 @@ class Filesystem
// Require filename // Require filename
if (empty($filename)) if (empty($filename))
{ {
throw new \Exception; throw new Exception;
} }
// Unify separators // Unify separators
@ -78,7 +81,7 @@ class Filesystem
// Check absolute filename path started with filesystem base // Check absolute filename path started with filesystem base
if (!str_starts_with($filepath, $this->_base)) if (!str_starts_with($filepath, $this->_base))
{ {
throw new \Exception; throw new Exception;
} }
// Return as is // Return as is
@ -228,7 +231,7 @@ class Filesystem
if ($data) if ($data)
{ {
$mime = ( $mime = (
new \Finfo( new Finfo(
FILEINFO_MIME_TYPE FILEINFO_MIME_TYPE
) )
)->buffer( )->buffer(

13
src/Model/Pool.php

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Yggverse\Yoda\Model; namespace Yggverse\Yoda\Model;
use \Exception;
use \Shmop;
class Pool implements \Yggverse\Yoda\Interface\Model\Pool class Pool implements \Yggverse\Yoda\Interface\Model\Pool
{ {
private string $_namespace; private string $_namespace;
@ -23,11 +26,11 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
int $size = 0xfffff, int $size = 0xfffff,
string $flags = 'c', string $flags = 'c',
int $mode = 0644, int $mode = 0644,
): ?\Shmop ): ?Shmop
{ {
if (isset($this->_data[$key])) if (isset($this->_data[$key]))
{ {
throw new \Exception; throw new Exception;
} }
return $this->_data[$key] = shmop_open( return $this->_data[$key] = shmop_open(
@ -48,7 +51,7 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
{ {
if (!isset($this->_data[$key])) if (!isset($this->_data[$key]))
{ {
throw new \Exception; throw new Exception;
} }
if (empty($this->_data[$key])) if (empty($this->_data[$key]))
@ -73,7 +76,7 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
{ {
if (!isset($this->_data[$key])) if (!isset($this->_data[$key]))
{ {
throw new \Exception; throw new Exception;
} }
return shmop_write( return shmop_write(
@ -89,7 +92,7 @@ class Pool implements \Yggverse\Yoda\Interface\Model\Pool
{ {
if (!isset($this->_data[$key])) if (!isset($this->_data[$key]))
{ {
throw new \Exception; throw new Exception;
} }
$result = shmop_delete( $result = shmop_delete(

Loading…
Cancel
Save