Skip to content

Instantly share code, notes, and snippets.

View andevsoftware's full-sized avatar

Andev Software andevsoftware

View GitHub Profile
@andevsoftware
andevsoftware / ts-validate.validators.regex.ts
Last active March 5, 2016 20:07
TSValidate.Validators.Regex
import Regex = TSValidate.Validators.Regex;
validator.add('created_at', new Regex()
.pattern(/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/)
.message('The creation date is invalid')
);
@andevsoftware
andevsoftware / ts-validate.validators.inclusionin.ts
Last active March 5, 2016 12:52
TSValidate.Validators.InclusionIn
import InclusionIn = TSValidate.Validators.InclusionIn;
validator.add('status', new InclusionIn()
.message('The status must be A or B')
.domain(['A', 'B'])
);
@andevsoftware
andevsoftware / ts-validate.validators.exclusionin.ts
Created March 5, 2016 12:34
TSValidate.Validators.ExclusionIn
import ExclusionIn = TSValidate.Validators.ExclusionIn;
validator.add('status', new ExclusionIn()
.message('The status must not be A or B')
.domain(['A', 'B'])
);
@andevsoftware
andevsoftware / ts-validate.validators.email.ts
Last active March 5, 2016 12:52
TSValidate.Validators.Email
import Email = TSValidate.Validators.Email;
validate.add('email', new Email()
.message('The e-mail is not valid')
);
@andevsoftware
andevsoftware / ts-validate.validators.identical.ts
Created March 5, 2016 12:24
TSValidate.Validators.Identical
import Identical = TSValidate.Validators.Identical;
validator.add('terms', new Identical()
.accepted('yes')
.message('Terms and conditions must be accepted')
);
@andevsoftware
andevsoftware / ts-validate.validators.presenceof.ts
Created March 5, 2016 12:21
TSValidate.Validators.PresenceOf
import PresenceOf = TSValidation.Validators.PresenceOf;
validator.add('name', new PresenceOf()
.message('The name is required')
);
@andevsoftware
andevsoftware / ts-validate.introduction.ts
Last active March 5, 2016 12:18
TSValidate Introduction
import Email = TSValidate.Validators.Email;
import PresenceOf = TSValidate.Validators.PresenceOf;
var validation = new TSValidate.Validation;
validation.add(
'name',
new PresenceOf()
.message('The name is required')
);
@andevsoftware
andevsoftware / phalcon-rest-acl-memory-adapter.php
Created February 28, 2016 19:41
Phalcon REST - Acl Memory Adapter
<?php
namespace App\Acl\Adapter;
use PhalconRest\Acl\MountingEnabledAdapterInterface;
class Memory extends \Phalcon\Acl\Adapter\Memory implements MountingEnabledAdapterInterface
{
use \AclAdapterMountTrait;
}
@andevsoftware
andevsoftware / phalcon-rest-create-roles.php
Last active February 28, 2016 20:44
Phalcon REST - Create Roles
<?php
/** @var \PhalconRest\Acl\MountingEnabledAdapterInterface $acl */
$acl = $di->get(Services::ACL);
// These are our main roles
$unauthorizedRole = new Acl\Role(AclRoles::UNAUTHORIZED);
$authorizedRole = new Acl\Role(AclRoles::AUTHORIZED);
@andevsoftware
andevsoftware / phalcon-rest-restrict-access-on-resources.php
Last active February 28, 2016 19:45
Phalcon REST - Restrict Access On Resources
<?php
$api->resource(Resource::crud('/users', 'User')
// Here we restrict access to all endpoints
// on this Resource. The `User` role is not allowed
// to access all endpoints by default.
->deny(AclRoles::UNAUTHORIZED, AclRoles::USER)
// Because access can be overridden,