Vitor Mattos
CTO da LibreCode, empreendedor, sempre buscando novos desafios e conhecimentos. Grande incentivador do software livre, evangelista PHP, palestrante em eventos regionais e nacionais.
A Simple Nextcloud App Tutorial
Realizador de sonhos desde 2003
Amante de opensource
Palestrante
PHP Zend Certified Engineer ( ZEND024235 )
PHPRio ( https://telegram.me/phprio )
CTO LibreCode
Redes sociais: ( VitorMattos ou VitorMattosRJ )
# PRESENTING CODE
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>wifi_password</id>
<name>Wifi - Password</name>
<summary>Create, manage and share wi-fi passwords</summary>
<description>Create, manage and share wi-fi passwords using qrcode</description>
<version>1.0.0-alfa</version>
<licence>agpl</licence>
<author>Vinicius Reis</author>
<author>Vitor Mattos</author>
<namespace>WifiPassword</namespace>
<category>files</category>
<category>tools</category>
<bugs>https://github.com/vinicius73/wifi-password/issues</bugs>
<dependencies>
<nextcloud min-version="22" max-version="25" />
</dependencies>
</info>
# PRESENTING CODE
<?php
declare(strict_types=1);
namespace OCA\WifiPassword\AppInfo;
use OCP\AppFramework\App;
class Application extends App {
public const APP_ID = 'wifi_password';
public function __construct() {
parent::__construct(self::APP_ID);
}
}
# PRESENTING CODE
{
"name": "vinicius73/wifi-password",
"type": "project",
"license": "AGPL",
"authors": [
{
"name": "Vinicius Reis",
"email": "luiz.vinicius73@gmail.com"
},
{
"name": "Vitor Mattos",
"email": "vitor@php.rio"
}
],
"autoload": {
"psr-4": {
"Root\\Teste\\": "src/"
}
}
}
# PRESENTING CODE
{
"name": "vinicius73/wifi-password",
"type": "project",
"license": "AGPL",
"authors": [
{
"name": "Vinicius Reis",
"email": "luiz.vinicius73@gmail.com"
},
{
"name": "Vitor Mattos",
"email": "vitor@php.rio"
}
],
"autoload": {
"psr-4": {
"OCA\\WifiPassword\\": "src/"
}
}
}
Info: fix the namespace
# PRESENTING CODE
occ app:enable wifi_password
# PRESENTING CODE
composer require --dev nextcloud/coding-standard
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix"
}
# PRESENTING CODE
<?php
declare(strict_types=1);
require_once './vendor/autoload.php';
use Nextcloud\CodingStandard\Config;
$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;
.php-cs-fixer.dist.php
PS: add .php-cs-fixer.cache to .gitignore
# PRESENTING CODE
composer require --dev vimeo/psalm
composer require --dev christophwurst/nextcloud:dev-master
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm"
}
# PRESENTING CODE
<?xml version="1.0"?>
<psalm
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="OC\*" />
<referencedClass name="OC" />
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
psalm.xml
# PRESENTING CODE
composer require --dev libresign/nextcloud-behat
vendor/bin/behat init
Behat
default:
autoload:
'': '%paths.base%/tests/features/bootstrap'
suites:
default:
paths:
- '%paths.base%/tests/features'
extensions:
PhpBuiltin\Server:
verbose: false
rootDir: /var/www/html
host: localhost
behat.yml
# PRESENTING CODE
Show me the code
# PRESENTING CODE
Show me the code
# PRESENTING CODE
return [
'routes' => [
['name' => 'author#index', 'url' => '/authors', 'verb' => 'GET'],
['name' => 'author#show', 'url' => '/authors/{id}', 'verb' => 'GET'],
['name' => 'author#create', 'url' => '/authors', 'verb' => 'POST'],
['name' => 'author#update', 'url' => '/authors/{id}', 'verb' => 'PUT'],
['name' => 'author#destroy', 'url' => '/authors/{id}', 'verb' => 'DELETE'],
// your other routes here
],
];
this...
# PRESENTING CODE
return [
'resources' => [
'author' => ['url' => '/authors'],
],
'routes' => [
// your other routes here
],
];
can be abbreviated by using the resources key:
# PRESENTING CODE
<?php
return [
'routes' => [
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
],
];
# PRESENTING CODE
<?php
declare(strict_types=1);
namespace OCA\WifiPassword\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCA\WifiPassword\AppInfo\Application;
class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(): TemplateResponse
{
return new TemplateResponse(Application::APP_ID, "page-main");
}
}
# PRESENTING CODE
Hello World
# PRESENTING CODE
...
<dependencies>
<nextcloud min-version="22" max-version="25" />
</dependencies>
<navigations>
<navigation>
<name>Wifi Password</name>
<route>wifi_password.page.index</route>
</navigation>
</navigations>
</info>
# PRESENTING CODE
img/app.svg
img/app-dark.svg
# PRESENTING CODE
By Vitor Mattos
A simple Nextcloud app tutorial
CTO da LibreCode, empreendedor, sempre buscando novos desafios e conhecimentos. Grande incentivador do software livre, evangelista PHP, palestrante em eventos regionais e nacionais.