repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/customer/edit.blade.php
resources/views/customer/edit.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('customer.update_customer')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::model($customer, array('route' => array('customers.update', $customer->id), 'method' => 'PUT', 'files' => true)) !!} <div class="form-group"> {!! Form::label('name', trans('customer.name').' *') !!} {!! Form::text('name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('customer.email')) !!} {!! Form::text('email', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('phone_number', trans('customer.phone_number')) !!} {!! Form::text('phone_number', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('customer.choose_avatar')) !!} {!! Form::file('avatar', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('addrees', trans('customer.address')) !!} {!! Form::text('address', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('city', trans('customer.city')) !!} {!! Form::text('city', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('state', trans('customer.state')) !!} {!! Form::text('state', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('zip', trans('customer.zip')) !!} {!! Form::text('zip', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('company_name', trans('customer.company_name')) !!} {!! Form::text('company_name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('account', trans('customer.account')) !!} {!! Form::text('account', null, array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('customer.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/customer/index.blade.php
resources/views/customer/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('customer.list_customers')}}</div> <div class="panel-body"> <a class="btn btn-small btn-success" href="{{ URL::to('customers/create') }}">{{trans('customer.new_customer')}}</a> <hr /> @if (Session::has('message')) <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p> @endif <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('customer.customer_id')}}</td> <td>{{trans('customer.name')}}</td> <td>{{trans('customer.email')}}</td> <td>{{trans('customer.phone_number')}}</td> <td>&nbsp;</td> <td>{{trans('customer.avatar')}}</td> </tr> </thead> <tbody> @foreach($customer as $value) <tr> <td>{{ $value->id }}</td> <td>{{ $value->name }}</td> <td>{{ $value->email }}</td> <td>{{ $value->phone_number }}</td> <td> <a class="btn btn-small btn-info" href="{{ URL::to('customers/' . $value->id . '/edit') }}">{{trans('customer.edit')}}</a> {!! Form::open(array('url' => 'customers/' . $value->id, 'class' => 'pull-right')) !!} {!! Form::hidden('_method', 'DELETE') !!} {!! Form::submit(trans('customer.delete'), array('class' => 'btn btn-warning')) !!} {!! Form::close() !!} </td> <td>{!! Html::image(url() . '/images/customers/' . $value->avatar, 'a picture', array('class' => 'thumb')) !!}</td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/customer/create.blade.php
resources/views/customer/create.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('customer.new_customer')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::open(array('url' => 'customers', 'files' => true)) !!} <div class="form-group"> {!! Form::label('name', trans('customer.name') .' *') !!} {!! Form::text('name', Input::old('name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('customer.email')) !!} {!! Form::text('email', Input::old('email'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('phone_number', trans('customer.phone_number')) !!} {!! Form::text('phone_number', Input::old('phone_number'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('customer.choose_avatar')) !!} {!! Form::file('avatar', Input::old('avatar'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('address', trans('customer.address')) !!} {!! Form::text('address', Input::old('address'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('city', trans('customer.city')) !!} {!! Form::text('city', Input::old('city'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('state', trans('customer.state')) !!} {!! Form::text('state', Input::old('state'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('zip', trans('customer.zip')) !!} {!! Form::text('zip', Input::old('zip'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('company_name', trans('customer.company_name')) !!} {!! Form::text('company_name', Input::old('company_name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('account', trans('customer.account') .' #') !!} {!! Form::text('account', Input::old('account'), array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('customer.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/auth/reset.blade.php
resources/views/auth/reset.blade.php
@extends('app') @section('content') <div class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Reset Password</div> <div class="panel-body"> @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <form class="form-horizontal" role="form" method="POST" action="{{ url('/password/reset') }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <input type="hidden" name="token" value="{{ $token }}"> <div class="form-group"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password_confirmation"> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Reset Password </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/auth/login.blade.php
resources/views/auth/login.blade.php
@extends('app') @section('content') <div class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Login</div> <div class="panel-body"> @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="form-group"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <div class="checkbox"> <label> <input type="checkbox" name="remember"> Remember Me </label> </div> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary">Login</button> <a class="btn btn-link" href="{{ url('/password/email') }}">Forgot Your Password?</a> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/auth/register.blade.php
resources/views/auth/register.blade.php
@extends('app') @section('content') <div class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Register</div> <div class="panel-body"> @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/register') }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="form-group"> <label class="col-md-4 control-label">Name</label> <div class="col-md-6"> <input type="text" class="form-control" name="name" value="{{ old('name') }}"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <label class="col-md-4 control-label">Confirm Password</label> <div class="col-md-6"> <input type="password" class="form-control" name="password_confirmation"> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Register </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/auth/password.blade.php
resources/views/auth/password.blade.php
@extends('app') @section('content') <div class="container-fluid"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Reset Password</div> <div class="panel-body"> @if (session('status')) <div class="alert alert-success"> {{ session('status') }} </div> @endif @if (count($errors) > 0) <div class="alert alert-danger"> <strong>Whoops!</strong> There were some problems with your input.<br><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif <form class="form-horizontal" role="form" method="POST" action="{{ url('/password/email') }}"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="form-group"> <label class="col-md-4 control-label">E-Mail Address</label> <div class="col-md-6"> <input type="email" class="form-control" name="email" value="{{ old('email') }}"> </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Send Password Reset Link </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/supplier/edit.blade.php
resources/views/supplier/edit.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('supplier.update_supplier')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::model($supplier, array('route' => array('suppliers.update', $supplier->id), 'method' => 'PUT', 'files' => true)) !!} <div class="form-group"> {!! Form::label('company_name', trans('supplier.company_name')) !!} {!! Form::text('company_name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('name', trans('supplier.name')) !!} {!! Form::text('name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('supplier.email')) !!} {!! Form::text('email', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('phone_number', trans('supplier.phone_number')) !!} {!! Form::text('phone_number', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('supplier.choose_avatar')) !!} {!! Form::file('avatar', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('addrees', trans('supplier.address')) !!} {!! Form::text('address', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('city', trans('supplier.city')) !!} {!! Form::text('city', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('state', trans('supplier.state')) !!} {!! Form::text('state', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('zip', trans('supplier.zip')) !!} {!! Form::text('zip', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('comments', trans('supplier.comments')) !!} {!! Form::text('comments', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('account', trans('supplier.account')) !!} {!! Form::text('account', null, array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('supplier.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/supplier/index.blade.php
resources/views/supplier/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('supplier.list_suppliers')}}</div> <div class="panel-body"> <a class="btn btn-small btn-success" href="{{ URL::to('suppliers/create') }}">{{trans('supplier.new_supplier')}}</a> <hr /> @if (Session::has('message')) <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p> @endif <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('supplier.company_name')}}</td> <td>{{trans('supplier.name')}}</td> <td>{{trans('supplier.email')}}</td> <td>{{trans('supplier.phone_number')}}</td> <td>&nbsp;</td> <td>{{trans('supplier.avatar')}}</td> </tr> </thead> <tbody> @foreach($supplier as $value) <tr> <td>{{ $value->company_name }}</td> <td>{{ $value->name }}</td> <td>{{ $value->email }}</td> <td>{{ $value->phone_number }}</td> <td> <a class="btn btn-small btn-info" href="{{ URL::to('suppliers/' . $value->id . '/edit') }}">{{trans('supplier.edit')}}</a> {!! Form::open(array('url' => 'suppliers/' . $value->id, 'class' => 'pull-right')) !!} {!! Form::hidden('_method', 'DELETE') !!} {!! Form::submit(trans('supplier.delete'), array('class' => 'btn btn-warning')) !!} {!! Form::close() !!} </td> <td>{!! Html::image(url() . '/images/suppliers/' . $value->avatar, 'a picture', array('class' => 'thumb')) !!}</td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/supplier/create.blade.php
resources/views/supplier/create.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('supplier.new_supplier')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::open(array('url' => 'suppliers', 'files' => true)) !!} <div class="form-group"> {!! Form::label('company_name', trans('supplier.company_name').' *') !!} {!! Form::text('company_name', Input::old('company_name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('name', trans('supplier.name')) !!} {!! Form::text('name', Input::old('name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('supplier.email')) !!} {!! Form::text('email', Input::old('name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('phone_number', trans('supplier.phone_number')) !!} {!! Form::text('phone_number', Input::old('phone_number'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('supplier.choose_avatar')) !!} {!! Form::file('avatar', Input::old('avatar'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('address', trans('supplier.address')) !!} {!! Form::text('address', Input::old('address'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('city', trans('supplier.city')) !!} {!! Form::text('city', Input::old('city'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('state', trans('supplier.state')) !!} {!! Form::text('state', Input::old('state'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('zip', trans('supplier.zip')) !!} {!! Form::text('zip', Input::old('zip'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('comments', trans('supplier.comments')) !!} {!! Form::text('comments', Input::old('comments'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('account', trans('supplier.account').' #') !!} {!! Form::text('account', Input::old('account'), array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('supplier.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/errors/503.blade.php
resources/views/errors/503.blade.php
<html> <head> <link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'> <style> body { margin: 0; padding: 0; width: 100%; height: 100%; color: #B0BEC5; display: table; font-weight: 100; font-family: 'Lato'; } .container { text-align: center; display: table-cell; vertical-align: middle; } .content { text-align: center; display: inline-block; } .title { font-size: 72px; margin-bottom: 40px; } </style> </head> <body> <div class="container"> <div class="content"> <div class="title">Be right back.</div> </div> </div> </body> </html>
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/emails/password.blade.php
resources/views/emails/password.blade.php
Click here to reset your password: {{ url('password/reset/'.$token) }}
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/tutapos-setting/index.blade.php
resources/views/tutapos-setting/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">Application Settings</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} {!! Form::model($tutapos_settings, array('route' => array('tutapos-settings.update', $tutapos_settings->id), 'method' => 'PUT', 'files' => true)) !!} <div class="form-group"> {!! Form::label('language', 'Language') !!} {!! Form::select('language', array('en' => 'English', 'id' => 'Indonesia', 'es' => 'Spanish'), Input::old('language'), array('class' => 'form-control')) !!} </div> {!! Form::submit('Submit', array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/inventory/edit.blade.php
resources/views/inventory/edit.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('item.inventory_data_tracking')}}</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} <table class="table table-bordered"> <tr><td>UPC/EAN/ISBN</td><td>{{ $item->upc_ean_isbn }}</td></tr> <tr><td>{{trans('item.item_name')}}</td><td>{{ $item->item_name }}</td></tr> <tr><td>{{trans('item.current_quantity')}}</td><td>{{ $item->quantity }}</td></tr> {!! Form::model($item->inventory, array('route' => array('inventory.update', $item->id), 'method' => 'PUT')) !!} <tr><td>{{trans('item.inventory_to_add_subtract')}} *</td><td>{!! Form::text('in_out_qty', Input::old('in_out_qty'), array('class' => 'form-control')) !!}</td></tr> <tr><td>{{trans('item.comments')}}</td><td>{!! Form::text('remarks', Input::old('remarks'), array('class' => 'form-control')) !!}</td></tr> <tr><td>&nbsp;</td><td>{!! Form::submit(trans('item.submit'), array('class' => 'btn btn-primary')) !!}</td></tr> {!! Form::close() !!} </table> <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('item.inventory_data_tracking')}}</td> <td>{{trans('item.employee')}}</td> <td>{{trans('item.in_out_qty')}}</td> <td>{{trans('item.remarks')}}</td> </tr> </thead> <tbody> @foreach($item->inventory as $value) <tr> <td>{{ $value->created_at }}</td> <td>{{ $value->user->name }}</td> <td>{{ $value->in_out_qty }}</td> <td>{{ $value->remarks }}</td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/receiving/complete.blade.php
resources/views/receiving/complete.blade.php
@extends('app') @section('content') {!! Html::script('js/angular.min.js', array('type' => 'text/javascript')) !!} {!! Html::script('js/app.js', array('type' => 'text/javascript')) !!} <style> table td { border-top: none !important; } </style> <div class="container-fluid"> <div class="row"> <div class="col-md-12" style="text-align:center"> TutaPOS - Tuta Point of Sale </div> </div> <div class="row"> <div class="col-md-12"> {{trans('receiving.supplier')}}: {{ $receivings->supplier->company_name}}<br /> {{trans('receiving.receiving_id')}}: RECV{{$receivingItemsData->receiving_id}}<br /> {{trans('receiving.employee')}}: {{$receivings->user->name}}<br /> </div> </div> <div class="row"> <div class="col-md-12"> <div class="table-responsive"> <table class="table"> <tr> <td>{{trans('receiving.item')}}</td> <td>{{trans('receiving.price')}}</td> <td>{{trans('receiving.qty')}}</td> <td>{{trans('receiving.total')}}</td> </tr> @foreach($receivingItems as $value) <tr> <td>{{$value->item->item_name}}</td> <td>{{$value->cost_price}}</td> <td>{{$value->quantity}}</td> <td>{{$value->total_cost}}</td> </tr> @endforeach </table> </div> </div> </div> <div class="row"> <div class="col-md-12"> {{trans('receiving.payment_type')}}: {{$receivings->payment_type}} </div> </div> <hr class="hidden-print"/> <div class="row"> <div class="col-md-8"> &nbsp; </div> <div class="col-md-2"> <button type="button" onclick="printInvoice()" class="btn btn-info pull-right hidden-print">{{trans('receiving.print')}}</button> </div> <div class="col-md-2"> <a href="{{ url('/receivings') }}" type="button" class="btn btn-info pull-right hidden-print">{{trans('receiving.new_receiving')}}</a> </div> </div> </div> <script> function printInvoice() { window.print(); } </script> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/receiving/index.blade.php
resources/views/receiving/index.blade.php
@extends('app') @section('content') {!! Html::script('js/angular.min.js', array('type' => 'text/javascript')) !!} {!! Html::script('js/app.js', array('type' => 'text/javascript')) !!} <div class="container-fluid"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-inbox" aria-hidden="true"></span> {{trans('receiving.item_receiving')}}</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} <div class="row" ng-controller="SearchItemCtrl"> <div class="col-md-3"> <label>{{trans('receiving.search_item')}} <input ng-model="searchKeyword" class="form-control"></label> <table class="table table-hover"> <tr ng-repeat="item in items | filter: searchKeyword | limitTo:10"> <td>@{{item.item_name}}</td><td><button class="btn btn-primary btn-xs" type="button" ng-click="addReceivingTemp(item,newreceivingtemp)"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span></button></td> </tr> </table> </div> <div class="col-md-9"> <div class="row"> {!! Form::open(array('url' => 'receivings', 'class' => 'form-horizontal')) !!} <div class="col-md-5"> <div class="form-group"> <label for="invoice" class="col-sm-3 control-label">{{trans('receiving.invoice')}}</label> <div class="col-sm-9"> <input type="text" class="form-control" id="invoice" value="@if ($receiving) {{$receiving->id + 1}} @else 1 @endif" readonly/> </div> </div> <div class="form-group"> <label for="employee" class="col-sm-3 control-label">{{trans('receiving.employee')}}</label> <div class="col-sm-9"> <input type="text" class="form-control" name="employee_id" id="employee" value="{{ Auth::user()->name }}" readonly/> </div> </div> </div> <div class="col-md-7"> <div class="form-group"> <label for="supplier_id" class="col-sm-4 control-label">{{trans('receiving.supplier')}}</label> <div class="col-sm-8"> {!! Form::select('supplier_id', $supplier, Input::old('supplier_id'), array('class' => 'form-control')) !!} </div> </div> <div class="form-group"> <label for="payment_type" class="col-sm-4 control-label">{{trans('receiving.payment_type')}}</label> <div class="col-sm-8"> {!! Form::select('payment_type', array('Cash' => 'Cash', 'Check' => 'Check', 'Debit Card' => 'Debit Card', 'Credit Card' => 'Credit Card'), Input::old('payment_type'), array('class' => 'form-control')) !!} </div> </div> </div> </div> <table class="table table-bordered"> <tr><th>{{trans('receiving.item_id')}}</th><th>{{trans('receiving.item_name')}}</th><th>{{trans('receiving.cost')}}</th><th>{{trans('receiving.quantity')}}</th><th>{{trans('receiving.total')}}</th><th>&nbsp;</th></tr> <tr ng-repeat="newreceivingtemp in receivingtemp"> <td>@{{newreceivingtemp.item_id}}</td><td>@{{newreceivingtemp.item.item_name}}</td><td>@{{newreceivingtemp.item.cost_price | currency}}</td><td><input type="text" style="text-align:center" autocomplete="off" name="quantity" ng-change="updateReceivingTemp(newreceivingtemp)" ng-model="newreceivingtemp.quantity" size="2"></td><td>@{{newreceivingtemp.item.cost_price * newreceivingtemp.quantity | currency}}</td><td><button class="btn btn-danger btn-xs" type="button" ng-click="removeReceivingTemp(newreceivingtemp.id)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td> </tr> </table> <div class="row"> <div class="col-md-7"> <div class="form-group"> <label for="total" class="col-sm-5 control-label">{{trans('receiving.amount_tendered')}}</label> <div class="col-sm-7"> <div class="input-group"> <div class="input-group-addon">$</div> <input type="text" class="form-control" id="amount_tendered"/> </div> </div> </div> <div>&nbsp;</div> <div class="form-group"> <label for="employee" class="col-sm-4 control-label">{{trans('receiving.comments')}}</label> <div class="col-sm-8"> <input type="text" class="form-control" name="comments" id="comments" /> </div> </div> </div> <div class="col-md-5"> <div class="form-group"> <label for="supplier_id" class="col-sm-4 control-label">{{trans('receiving.grand_total')}}</label> <div class="col-sm-8"> <p class="form-control-static"><b>@{{sum(receivingtemp) | currency}}</b></p> </div> </div> <div>&nbsp;</div> <div class="form-group"> <div class="col-sm-12"> <button type="submit" class="btn btn-primary btn-block">{{trans('receiving.submit')}}</button> </div> </div> </div> </div> {!! Form::close() !!} </div> </div> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/report/sale.blade.php
resources/views/report/sale.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('report-sale.reports')}} - {{trans('report-sale.sales_report')}}</div> <div class="panel-body"> <div class="row"> <div class="col-md-4"> <div class="well well-sm">{{trans('report-sale.grand_total')}}: {{DB::table('sale_items')->sum('total_selling')}}</div> </div> <div class="col-md-4"> <div class="well well-sm">{{trans('report-sale.grand_profit')}}: {{DB::table('sale_items')->sum('total_selling') - DB::table('sale_items')->sum('total_cost')}}</div> </div> </div> <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('report-sale.sale_id')}}</td> <td>{{trans('report-sale.date')}}</td> <td>{{trans('report-sale.items_purchased')}}</td> <td>{{trans('report-sale.sold_by')}}</td> <td>{{trans('report-sale.sold_to')}}</td> <td>{{trans('report-sale.total')}}</td> <td>{{trans('report-sale.profit')}}</td> <td>{{trans('report-sale.payment_type')}}</td> <td>{{trans('report-sale.comments')}}</td> <td>&nbsp;</td> </tr> </thead> <tbody> @foreach($saleReport as $value) <tr> <td>{{ $value->id }}</td> <td>{{ $value->created_at }}</td> <td>{{DB::table('sale_items')->where('sale_id', $value->id)->sum('quantity')}}</td> <td>{{ $value->user->name }}</td> <td>{{ $value->customer->name }}</td> <td>${{DB::table('sale_items')->where('sale_id', $value->id)->sum('total_selling')}}</td> <td>{{DB::table('sale_items')->where('sale_id', $value->id)->sum('total_selling') - DB::table('sale_items')->where('sale_id', $value->id)->sum('total_cost')}}</td> <td>{{ $value->payment_type }}</td> <td>{{ $value->comments }}</td> <td> <a class="btn btn-small btn-info" data-toggle="collapse" href="#detailedSales{{ $value->id }}" aria-expanded="false" aria-controls="detailedReceivings"> {{trans('report-sale.detail')}}</a> </td> </tr> <tr class="collapse" id="detailedSales{{ $value->id }}"> <td colspan="10"> <table class="table"> <tr> <td>{{trans('report-sale.item_id')}}</td> <td>{{trans('report-sale.item_name')}}</td> <td>{{trans('report-sale.quantity_purchase')}}</td> <td>{{trans('report-sale.total')}}</td> <td>{{trans('report-sale.profit')}}</td> </tr> @foreach(ReportSalesDetailed::sale_detailed($value->id) as $SaleDetailed) <tr> <td>{{ $SaleDetailed->item_id }}</td> <td>{{ $SaleDetailed->item->item_name }}</td> <td>{{ $SaleDetailed->quantity }}</td> <td>{{ $SaleDetailed->selling_price * $SaleDetailed->quantity}}</td> <td>{{ ($SaleDetailed->quantity * $SaleDetailed->selling_price) - ($SaleDetailed->quantity * $SaleDetailed->cost_price)}}</td> </tr> @endforeach </table> </td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/report/receiving.blade.php
resources/views/report/receiving.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('report-receiving.reports')}} - {{trans('report-receiving.receivings_report')}}</div> <div class="panel-body"> <div class="well well-sm">{{trans('report-receiving.grand_total')}}: {{DB::table('receiving_items')->sum('total_cost')}}</div> <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('report-receiving.receiving_id')}}</td> <td>{{trans('report-receiving.date')}}</td> <td>{{trans('report-receiving.items_received')}}</td> <td>{{trans('report-receiving.received_by')}}</td> <td>{{trans('report-receiving.supplied_by')}}</td> <td>{{trans('report-receiving.total')}}</td> <td>{{trans('report-receiving.payment_type')}}</td> <td>{{trans('report-receiving.comments')}}</td> <td>&nbsp;</td> </tr> </thead> <tbody> @foreach($receivingReport as $value) <tr> <td>{{ $value->id }}</td> <td>{{ $value->created_at }}</td> <td>{{DB::table('receiving_items')->where('receiving_id', $value->id)->sum('quantity')}}</td> <td>{{ $value->user->name }}</td> <td>{{ $value->supplier->company_name }}</td> <td>{{DB::table('receiving_items')->where('receiving_id', $value->id)->sum('total_cost')}}</td> <td>{{ $value->payment_type }}</td> <td>{{ $value->comments }}</td> <td> <a class="btn btn-small btn-info" data-toggle="collapse" href="#detailedReceivings{{ $value->id }}" aria-expanded="false" aria-controls="detailedReceivings">{{trans('report-receiving.detail')}}</a> </td> </tr> <tr class="collapse" id="detailedReceivings{{ $value->id }}"> <td colspan="9"> <table class="table"> <tr> <td>{{trans('report-receiving.item_id')}}</td> <td>{{trans('report-receiving.item_name')}}</td> <td>{{trans('report-receiving.item_received')}}</td> <td>{{trans('report-receiving.total')}}</td> </tr> @foreach(ReportReceivingsDetailed::receiving_detailed($value->id) as $receiving_detailed) <tr> <td>{{ $receiving_detailed->item_id }}</td> <td>{{ $receiving_detailed->item->item_name }}</td> <td>{{ $receiving_detailed->quantity }}</td> <td>{{ $receiving_detailed->quantity * $receiving_detailed->cost_price}}</td> </tr> @endforeach </table> </td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/sale/complete.blade.php
resources/views/sale/complete.blade.php
@extends('app') @section('content') {!! Html::script('js/angular.min.js', array('type' => 'text/javascript')) !!} {!! Html::script('js/app.js', array('type' => 'text/javascript')) !!} <style> table td { border-top: none !important; } </style> <div class="container-fluid"> <div class="row"> <div class="col-md-12" style="text-align:center"> TutaPOS - Tuta Point of Sale </div> </div> <div class="row"> <div class="col-md-12"> {{trans('sale.customer')}}: {{ $sales->customer->name}}<br /> {{trans('sale.sale_id')}}: SALE{{$saleItemsData->sale_id}}<br /> {{trans('sale.employee')}}: {{$sales->user->name}}<br /> </div> </div> <div class="row"> <div class="col-md-12"> <div class="table-responsive"> <table class="table"> <tr> <td>{{trans('sale.item')}}</td> <td>{{trans('sale.price')}}</td> <td>{{trans('sale.qty')}}</td> <td>{{trans('sale.total')}}</td> </tr> @foreach($saleItems as $value) <tr> <td>{{$value->item->item_name}}</td> <td>{{$value->selling_price}}</td> <td>{{$value->quantity}}</td> <td>{{$value->total_selling}}</td> </tr> @endforeach </table> </div> </div> </div> <div class="row"> <div class="col-md-12"> {{trans('sale.payment_type')}}: {{$sales->payment_type}} </div> </div> <hr class="hidden-print"/> <div class="row"> <div class="col-md-8"> &nbsp; </div> <div class="col-md-2"> <button type="button" onclick="printInvoice()" class="btn btn-info pull-right hidden-print">{{trans('sale.print')}}</button> </div> <div class="col-md-2"> <a href="{{ url('/sales') }}" type="button" class="btn btn-info pull-right hidden-print">{{trans('sale.new_sale')}}</a> </div> </div> </div> <script> function printInvoice() { window.print(); } </script> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/sale/index.blade.php
resources/views/sale/index.blade.php
@extends('app') @section('content') {!! Html::script('js/angular.min.js', array('type' => 'text/javascript')) !!} {!! Html::script('js/sale.js', array('type' => 'text/javascript')) !!} <div class="container-fluid"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-inbox" aria-hidden="true"></span> {{trans('sale.sales_register')}}</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-success">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} <div class="row" ng-controller="SearchItemCtrl"> <div class="col-md-3"> <label>{{trans('sale.search_item')}} <input ng-model="searchKeyword" class="form-control"></label> <table class="table table-hover"> <tr ng-repeat="item in items | filter: searchKeyword | limitTo:10"> <td>@{{item.item_name}}</td> <td><button class="btn btn-success btn-xs" type="button" ng-click="addSaleTemp(item, newsaletemp)"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span></button></td> </tr> </table> </div> <div class="col-md-9"> <div class="row"> {!! Form::open(array('url' => 'sales', 'class' => 'form-horizontal')) !!} <div class="col-md-5"> <div class="form-group"> <label for="invoice" class="col-sm-3 control-label">{{trans('sale.invoice')}}</label> <div class="col-sm-9"> <input type="text" class="form-control" id="invoice" value="@if ($sale) {{$sale->id + 1}} @else 1 @endif" readonly/> </div> </div> <div class="form-group"> <label for="employee" class="col-sm-3 control-label">{{trans('sale.employee')}}</label> <div class="col-sm-9"> <input type="text" class="form-control" id="employee" value="{{ Auth::user()->name }}" readonly/> </div> </div> </div> <div class="col-md-7"> <div class="form-group"> <label for="customer_id" class="col-sm-4 control-label">{{trans('sale.customer')}}</label> <div class="col-sm-8"> {!! Form::select('customer_id', $customer, Input::old('customer_id'), array('class' => 'form-control')) !!} </div> </div> <div class="form-group"> <label for="payment_type" class="col-sm-4 control-label">{{trans('sale.payment_type')}}</label> <div class="col-sm-8"> {!! Form::select('payment_type', array('Cash' => 'Cash', 'Check' => 'Check', 'Debit Card' => 'Debit Card', 'Credit Card' => 'Credit Card'), Input::old('payment_type'), array('class' => 'form-control')) !!} </div> </div> </div> </div> <table class="table table-bordered"> <tr><th>{{trans('sale.item_id')}}</th><th>{{trans('sale.item_name')}}</th><th>{{trans('sale.price')}}</th><th>{{trans('sale.quantity')}}</th><th>{{trans('sale.total')}}</th><th>&nbsp;</th></tr> <tr ng-repeat="newsaletemp in saletemp"> <td>@{{newsaletemp.item_id}}</td><td>@{{newsaletemp.item.item_name}}</td><td>@{{newsaletemp.item.selling_price | currency}}</td><td><input type="text" style="text-align:center" autocomplete="off" name="quantity" ng-change="updateSaleTemp(newsaletemp)" ng-model="newsaletemp.quantity" size="2"></td><td>@{{newsaletemp.item.selling_price * newsaletemp.quantity | currency}}</td><td><button class="btn btn-danger btn-xs" type="button" ng-click="removeSaleTemp(newsaletemp.id)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td> </tr> </table> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="total" class="col-sm-4 control-label">{{trans('sale.add_payment')}}</label> <div class="col-sm-8"> <div class="input-group"> <div class="input-group-addon">$</div> <input type="text" class="form-control" id="add_payment" ng-model="add_payment"/> </div> </div> </div> <div>&nbsp;</div> <div class="form-group"> <label for="employee" class="col-sm-4 control-label">{{trans('sale.comments')}}</label> <div class="col-sm-8"> <input type="text" class="form-control" name="comments" id="comments" /> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="supplier_id" class="col-sm-4 control-label">{{trans('sale.grand_total')}}</label> <div class="col-sm-8"> <p class="form-control-static"><b>@{{sum(saletemp) | currency}}</b></p> </div> </div> <div class="form-group"> <label for="amount_due" class="col-sm-4 control-label">{{trans('sale.amount_due')}}</label> <div class="col-sm-8"> <p class="form-control-static">@{{add_payment - sum(saletemp) | currency}}</p> </div> </div> <div class="form-group"> <div class="col-sm-12"> <button type="submit" class="btn btn-success btn-block">{{trans('sale.submit')}}</button> </div> </div> </div> </div> {!! Form::close() !!} </div> </div> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/item/edit.blade.php
resources/views/item/edit.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('item.update_item')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::model($item, array('route' => array('items.update', $item->id), 'method' => 'PUT', 'files' => true)) !!} <div class="form-group"> {!! Form::label('upc_ean_isbn', trans('item.upc_ean_isbn')) !!} {!! Form::text('upc_ean_isbn', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('item_name', trans('item.item_name')) !!} {!! Form::text('item_name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('size', trans('item.size')) !!} {!! Form::text('size', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('description', trans('item.description')) !!} {!! Form::text('description', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('item.choose_avatar')) !!} {!! Form::file('avatar', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('cost_price', trans('item.cost_price')) !!} {!! Form::text('cost_price', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('selling_price', trans('item.selling_price')) !!} {!! Form::text('selling_price', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('quantity', trans('item.quantity')) !!} {!! Form::text('quantity', null, array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('item.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/item/index.blade.php
resources/views/item/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('item.list_items')}}</div> <div class="panel-body"> <a class="btn btn-small btn-success" href="{{ URL::to('items/create') }}">{{trans('item.new_item')}}</a> <hr /> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('item.item_id')}}</td> <td>{{trans('item.upc_ean_isbn')}}</td> <td>{{trans('item.item_name')}}</td> <td>{{trans('item.size')}}</td> <td>{{trans('item.cost_price')}}</td> <td>{{trans('item.selling_price')}}</td> <td>{{trans('item.quantity')}}</td> <td>&nbsp;</td> <td>{{trans('item.avatar')}}</td> </tr> </thead> <tbody> @foreach($item as $value) <tr> <td>{{ $value->id }}</td> <td>{{ $value->upc_ean_isbn }}</td> <td>{{ $value->item_name }}</td> <td>{{ $value->size }}</td> <td>{{ $value->cost_price }}</td> <td>{{ $value->selling_price }}</td> <td>{{ $value->quantity }}</td> <td> <a class="btn btn-small btn-success" href="{{ URL::to('inventory/' . $value->id . '/edit') }}">{{trans('item.inventory')}}</a> <a class="btn btn-small btn-info" href="{{ URL::to('items/' . $value->id . '/edit') }}">{{trans('item.edit')}}</a> {!! Form::open(array('url' => 'items/' . $value->id, 'class' => 'pull-right')) !!} {!! Form::hidden('_method', 'DELETE') !!} {!! Form::submit(trans('item.delete'), array('class' => 'btn btn-warning')) !!} {!! Form::close() !!} </td> <td>{!! Html::image(url() . '/images/items/' . $value->avatar, 'a picture', array('class' => 'thumb')) !!}</td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/item/create.blade.php
resources/views/item/create.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('item.new_item')}}</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} {!! Form::open(array('url' => 'items', 'files' => true)) !!} <div class="form-group"> {!! Form::label('upc_ean_isbn', trans('item.upc_ean_isbn')) !!} {!! Form::text('upc_ean_isbn', Input::old('upc_ean_isbn'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('item_name', trans('item.item_name').' *') !!} {!! Form::text('item_name', Input::old('item_name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('size', trans('item.size')) !!} {!! Form::text('size', Input::old('size'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('description', trans('item.description')) !!} {!! Form::textarea('description', Input::old('description'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('avatar', trans('item.choose_avatar')) !!} {!! Form::file('avatar', Input::old('avatar'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('cost_price', trans('item.cost_price').' *') !!} {!! Form::text('cost_price', Input::old('cost_price'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('selling_price', trans('item.selling_price').' *') !!} {!! Form::text('selling_price', Input::old('selling_price'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('quantity', trans('item.quantity')) !!} {!! Form::text('quantity', Input::old('quantity'), array('class' => 'form-control')) !!} </div> {!! Form::submit(trans('item.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/itemkit/index.blade.php
resources/views/itemkit/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('itemkit.item_kits')}}</div> <div class="panel-body"> <a class="btn btn-small btn-success" href="{{ URL::to('item-kits/create') }}">{{trans('itemkit.new_item_kit')}}</a> <hr /> @if (Session::has('message')) <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p> @endif <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('itemkit.item_kit_id')}}</td> <td>{{trans('itemkit.item_kit_name')}}</td> <td>{{trans('itemkit.cost_price')}}</td> <td>{{trans('itemkit.selling_price')}}</td> <td>{{trans('itemkit.item_kit_description')}}</td> <td>&nbsp;</td> </tr> </thead> <tbody> @foreach($itemkits as $value) <tr> <td>{{$value->id}}</td> <td>{{$value->item_name}}</td> <td>{{$value->cost_price}}</td> <td>{{$value->selling_price}}</td> <td>{{$value->description}}</td> <td>..</td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/itemkit/create.blade.php
resources/views/itemkit/create.blade.php
@extends('app') @section('content') {!! Html::script('js/angular.min.js', array('type' => 'text/javascript')) !!} {!! Html::script('js/item.kits.js', array('type' => 'text/javascript')) !!} <div class="container-fluid"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading"><span class="glyphicon glyphicon-inbox" aria-hidden="true"></span> {{trans('itemkit.new_item_kit')}}</div> <div class="panel-body"> @if (Session::has('message')) <div class="alert alert-info">{{ Session::get('message') }}</div> @endif {!! Html::ul($errors->all()) !!} <div class="row" ng-controller="SearchItemCtrl"> <div class="col-md-3"> <label>{{trans('itemkit.search_item')}} <input ng-model="searchKeyword" class="form-control"></label> <table class="table table-hover"> <tr ng-repeat="item in items | filter: searchKeyword | limitTo:10"> <td>@{{item.item_name}}</td><td><button class="btn btn-primary btn-xs" type="button" ng-click="addItemKitTemp(item)"><span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span></button></td> </tr> </table> </div> <div class="col-md-9"> <div class="row"> {!! Form::open(array('url' => 'store-item-kits', 'class' => 'form-horizontal')) !!} <div class="col-md-6"> <div class="form-group"> <label for="item_kit_name" class="col-sm-4 control-label">{{trans('itemkit.item_kit_name')}}</label> <div class="col-sm-8"> <input type="text" class="form-control" name="item_kit_name" id="item_kit_name"/> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="description" class="col-sm-4 control-label">{{trans('itemkit.description')}}</label> <div class="col-sm-8"> <input type="text" class="form-control" name="description" id="description"/> </div> </div> </div> </div> <table class="table table-bordered"> <tr><th>{{trans('itemkit.item_id')}}</th><th>{{trans('itemkit.item_name')}}</th><th>{{trans('itemkit.quantity')}}</th><th>&nbsp;</th></tr> <tr ng-repeat="newitemkittemp in itemkittemp"> <td>@{{newitemkittemp.item_id}}</td><td>@{{newitemkittemp.item.item_name}}</td><td><input type="text" style="text-align:center" autocomplete="off" name="quantity" ng-change="updateItemKitTemp(newitemkittemp)" ng-model="newitemkittemp.quantity" size="2"></td><td><button class="btn btn-danger btn-xs" type="button" ng-click="removeItemKitTemp(newitemkittemp.id)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td> </tr> </table> <div class="row"> <div class="col-md-7"> <div class="form-group"> <label for="cost_price" class="col-sm-4 control-label">{{trans('itemkit.cost_price')}}</label> <div class="col-sm-8"> <div class="input-group"> <input type="text" class="form-control" name="cost_price_ori" id="cost_price_ori" ng-model="sumCost(itemkittemp)" readonly/> <div class="input-group-addon">$</div> <input type="text" class="form-control" name="cost_price" id="cost_price" ng-model="cp"/> </div> </div> </div> <div>&nbsp;</div> <div class="form-group"> <label for="selling_price" class="col-sm-4 control-label">{{trans('itemkit.selling_price')}}</label> <div class="col-sm-8"> <div class="input-group"> <input type="text" class="form-control" name="selling_price_ori" id="selling_price_ori" ng-model="sumSell(itemkittemp)" readonly/> <div class="input-group-addon">$</div> <input type="text" class="form-control" name="selling_price" id="selling_price" ng-model="sp"/> </div> </div> </div> </div> <div class="col-md-5"> <div class="form-group"> <label for="supplier_id" class="col-sm-5 control-label">{{trans('itemkit.profit')}}</label> <div class="col-sm-7"> <p class="form-control-static"><b>@{{sp - cp}}</b></p> </div> </div> <div>&nbsp;</div> <div class="form-group"> <div class="col-sm-12"> <button type="submit" class="btn btn-warning btn-block">{{trans('itemkit.submit')}}</button> </div> </div> </div> </div> {!! Form::close() !!} </div> </div> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/employee/edit.blade.php
resources/views/employee/edit.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('employee.update_employee')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::model($employee, array('route' => array('employees.update', $employee->id), 'method' => 'PUT')) !!} <div class="form-group"> {!! Form::label('name', trans('employee.name').' *') !!} {!! Form::text('name', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('employee.email').' *') !!} {!! Form::text('email', null, array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('password', trans('employee.password')) !!} <input type="password" class="form-control" name="password" placeholder="Password"> </div> <div class="form-group"> {!! Form::label('password_confirmation', trans('employee.confirm_password')) !!} <input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password"> </div> {!! Form::submit(trans('employee.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/employee/index.blade.php
resources/views/employee/index.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('employee.list_employees')}}</div> <div class="panel-body"> <a class="btn btn-small btn-success" href="{{ URL::to('employees/create') }}">{{trans('employee.new_employee')}}</a> <hr /> @if (Session::has('message')) <p class="alert {{ Session::get('alert-class', 'alert-info') }}">{{ Session::get('message') }}</p> @endif <table class="table table-striped table-bordered"> <thead> <tr> <td>{{trans('employee.person_id')}}</td> <td>{{trans('employee.name')}}</td> <td>{{trans('employee.email')}}</td> <td>&nbsp;</td> </tr> </thead> <tbody> @foreach($employee as $value) <tr> <td>{{ $value->id }}</td> <td>{{ $value->name }}</td> <td>{{ $value->email }}</td> <td> <a class="btn btn-small btn-info" href="{{ URL::to('employees/' . $value->id . '/edit') }}">{{trans('employee.edit')}}</a> {!! Form::open(array('url' => 'employees/' . $value->id, 'class' => 'pull-right')) !!} {!! Form::hidden('_method', 'DELETE') !!} {!! Form::submit(trans('employee.delete'), array('class' => 'btn btn-warning')) !!} {!! Form::close() !!} </td> </tr> @endforeach </tbody> </table> </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
tutacare/tutapos
https://github.com/tutacare/tutapos/blob/2e07e73ad355162caacf2e5509125894001b84a5/resources/views/employee/create.blade.php
resources/views/employee/create.blade.php
@extends('app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">{{trans('employee.new_employee')}}</div> <div class="panel-body"> {!! Html::ul($errors->all()) !!} {!! Form::open(array('url' => 'employees')) !!} <div class="form-group"> {!! Form::label('name', trans('employee.name').' *') !!} {!! Form::text('name', Input::old('name'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('email', trans('employee.email').' *') !!} {!! Form::text('email', Input::old('email'), array('class' => 'form-control')) !!} </div> <div class="form-group"> {!! Form::label('password', trans('employee.password').' *') !!} <input type="password" class="form-control" name="password" placeholder="Password"> </div> <div class="form-group"> {!! Form::label('password_confirmation', trans('employee.confirm_password').' *') !!} <input type="password" class="form-control" name="password_confirmation" placeholder="Confirm Password"> </div> {!! Form::submit(trans('employee.submit'), array('class' => 'btn btn-primary')) !!} {!! Form::close() !!} </div> </div> </div> </div> </div> @endsection
php
MIT
2e07e73ad355162caacf2e5509125894001b84a5
2026-01-05T05:00:20.248800Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/LaravelExceptionNotifierFacade.php
src/LaravelExceptionNotifierFacade.php
<?php namespace jeremykenedy\laravelexceptionnotifier; use Illuminate\Support\Facades\Facade; class LaravelExceptionNotifierFacade extends Facade { /** * Gets the facade accessor. * * @return string The facade accessor. */ protected static function getFacadeAccessor() { return 'laravelexceptionnotifier'; } }
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/LaravelExceptionNotifier.php
src/LaravelExceptionNotifier.php
<?php namespace jeremykenedy\laravelexceptionnotifier; use Illuminate\Support\ServiceProvider; class LaravelExceptionNotifier extends ServiceProvider { private $_packageTag = 'laravelexceptionnotifier'; /** * Indicates if loading of the provider is deferred. * * @var bool */ protected $defer = false; /** * Bootstrap the application services. * * @return void */ public function boot() { // } /** * Register the application services. * * @return void */ public function register() { $this->loadViewsFrom(__DIR__.'/resources/views/', $this->_packageTag); $this->mergeConfigFrom(__DIR__.'/config/exceptions.php', $this->_packageTag); $this->publishFiles(); } /** * Publish files for package. * * @return void */ private function publishFiles() { $publishTag = $this->_packageTag; // Publish Mailer $this->publishes([ __DIR__.'/App/Mail/ExceptionOccurred.php' => app_path('Mail/ExceptionOccurred.php'), ], $publishTag); // Publish email view $this->publishes([ __DIR__.'/resources/views/emails/exception.blade.php' => resource_path('views/emails/exception.blade.php'), ], $publishTag); // Publish config file $this->publishes([ __DIR__.'/config/exceptions.php' => config_path('exceptions.php'), ], $publishTag); } }
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/App/Mail/ExceptionOccurred.php
src/App/Mail/ExceptionOccurred.php
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Envelope; use Illuminate\Queue\SerializesModels; class ExceptionOccurred extends Mailable { use Queueable, SerializesModels; private array $content; /** * Create a new message instance. */ public function __construct($content) { $this->content = $content; } /** * Get the message envelope. */ public function envelope(): Envelope { $emailsTo = config('exceptions.emailExceptionsTo', false) ? str_getcsv(config('exceptions.emailExceptionsTo')) : null; $emailsCc = config('exceptions.emailExceptionCCto', false) ? str_getcsv(config('exceptions.emailExceptionCCto')) : null; $emailsBcc = config('exceptions.emailExceptionBCCto', false) ? str_getcsv(config('exceptions.emailExceptionBCCto')) : null; $fromSender = config('exceptions.emailExceptionFrom'); $subject = config('exceptions.emailExceptionSubject'); return new Envelope( from: $fromSender, to: $emailsTo, cc: $emailsCc, bcc: $emailsBcc, subject: $subject ); } /** * Get the message content definition. */ public function content(): Content { $view = config('exceptions.emailExceptionView'); return new Content( view: $view, with: [ 'content' => $this->content, ] ); } }
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/App/Traits/ExceptionNotificationHandlerTrait.php
src/App/Traits/ExceptionNotificationHandlerTrait.php
<?php namespace App\Traits; use App\Mail\ExceptionOccurred; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; use Throwable; trait ExceptionNotificationHandlerTrait { /** * A list of the exception types that should not be reported. * * @var array */ protected $dontReport = [ \Illuminate\Auth\AuthenticationException::class, \Illuminate\Auth\Access\AuthorizationException::class, \Symfony\Component\HttpKernel\Exception\HttpException::class, \Illuminate\Database\Eloquent\ModelNotFoundException::class, \Illuminate\Session\TokenMismatchException::class, \Illuminate\Validation\ValidationException::class, ]; /** * Register the exception handling callbacks for the application. */ public function register(): void { $this->reportable(function (Throwable $e) { $enableEmailExceptions = config('exceptions.emailExceptionEnabled'); if ($enableEmailExceptions) { $this->sendEmail($e); } }); } /** * Sends an email upon exception. */ public function sendEmail(Throwable $exception): void { try { $content = [ 'message' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'url' => request()->url(), 'body' => request()->all(), 'ip' => request()->ip(), ]; Mail::send(new ExceptionOccurred($content)); } catch (Throwable $exception) { Log::error($exception); } } }
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/config/exceptions.php
src/config/exceptions.php
<?php return [ /* |-------------------------------------------------------------------------- | Exception Email Enabled |-------------------------------------------------------------------------- | | Enable/Disable exception email notifications | */ 'emailExceptionEnabled' => env('EMAIL_EXCEPTION_ENABLED', true), /* |-------------------------------------------------------------------------- | Exception Email From |-------------------------------------------------------------------------- | | This is the email your exception will be from. | */ 'emailExceptionFrom' => env('EMAIL_EXCEPTION_FROM'), /* |-------------------------------------------------------------------------- | Exception Email To |-------------------------------------------------------------------------- | | This is the email(s) the exceptions will be emailed to. | */ 'emailExceptionsTo' => env('EMAIL_EXCEPTION_TO'), /* |-------------------------------------------------------------------------- | Exception Email CC |-------------------------------------------------------------------------- | | This is the email(s) the exceptions will be CC emailed to. | */ 'emailExceptionCCto' => env('EMAIL_EXCEPTION_CC'), /* |-------------------------------------------------------------------------- | Exception Email BCC |-------------------------------------------------------------------------- | | This is the email(s) the exceptions will be BCC emailed to. | */ 'emailExceptionBCCto' => env('EMAIL_EXCEPTION_BCC'), /* |-------------------------------------------------------------------------- | Exception Email Subject |-------------------------------------------------------------------------- | | This is the subject of the exception email | */ 'emailExceptionSubject' => env('EMAIL_EXCEPTION_SUBJECT', 'Error on '.config('app.env')), /* |-------------------------------------------------------------------------- | Exception Email View |-------------------------------------------------------------------------- | | This is the view that will be used for the email. | */ 'emailExceptionView' => 'emails.exception', ];
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/src/resources/views/emails/exception.blade.php
src/resources/views/emails/exception.blade.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta name="robots" content="noindex,nofollow" /> <style> body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; } a { cursor: pointer; text-decoration: none; } a:hover { text-decoration: underline; } abbr[title] { border-bottom: none; cursor: help; text-decoration: none; } code, pre { font: 13px/1.5 Consolas, Monaco, Menlo, "Ubuntu Mono", "Liberation Mono", monospace; } table, tr, th, td { background: #FFF; border-collapse: collapse; vertical-align: top; } table { background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 1em 0; width: 100%; } table th, table td { border: solid #E0E0E0; border-width: 1px 0; padding: 8px 10px; } table th { background-color: #E0E0E0; font-weight: bold; text-align: left; } .hidden-xs-down { display: none; } .block { display: block; } .break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; } .text-muted { color: #999; } .container { max-width: 1024px; margin: 0 auto; padding: 0 15px; } .container::after { content: ""; display: table; clear: both; } .exception-summary { background: #B0413E; border-bottom: 2px solid rgba(0, 0, 0, 0.1); border-top: 1px solid rgba(0, 0, 0, .3); flex: 0 0 auto; margin-bottom: 30px; } .exception-message-wrapper { display: flex; align-items: center; min-height: 70px; } .exception-message { flex-grow: 1; padding: 30px 0; } .exception-message, .exception-message a { color: #FFF; font-size: 21px; font-weight: 400; margin: 0; } .exception-message.long { font-size: 18px; } .exception-message a { border-bottom: 1px solid rgba(255, 255, 255, 0.5); font-size: inherit; text-decoration: none; } .exception-message a:hover { border-bottom-color: #ffffff; } .exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; } .trace + .trace { margin-top: 30px; } .trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; } .trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; } .trace-file-path, .trace-file-path a { color: #222; margin-top: 3px; font-size: 13px; } .trace-class { color: #B0413E; } .trace-type { padding: 0 2px; } .trace-method { color: #B0413E; font-weight: bold; } .trace-arguments { color: #777; font-weight: normal; padding-left: 2px; } @media (min-width: 575px) { .hidden-xs-down { display: initial; } }</style> </head> <body> <div class="exception-summary"> <div class="container"> <div class="exception-message-wrapper"> <h1 class="break-long-words exception-message">{{ $content['message'] ?? '' }}</h1> <div class="exception-illustration hidden-xs-down"></div> </div> </div> </div> <div class="container"> <div class="trace trace-as-html"> <table class="trace-details"> <thead class="trace-head"><tr><th> <h3 class="trace-class"> <span class="text-muted">(1/1)</span> <span class="exception_title"><span title="ErrorException">ErrorException</span></span> </h3> <p class="break-long-words trace-message">{{ $content['message'] ?? '' }}</p> <p class="">URL: {{ $content['url'] ?? '' }}</p> <p class="">IP: {{ $content['ip'] ?? '' }}</p> </th></tr></thead> <tbody> <tr> <td> <span class="block trace-file-path">in <span title="{{ $content['file'] ?? '' }}"><strong>{{ $content['file'] ?? '' }}</strong> line {{ $content['line'] ?? '' }}</span></span> </td> </tr> @foreach(($content['trace'] ?? []) as $value) <tr> <td> at <span class="trace-class"><span title="{{ $value['class'] ?? '' }}">{{ basename($value['class'] ?? '') }}</span></span><span class="trace-type">-></span><span class="trace-method">{{ $value['function'] ?? '' }}</span>(<span class="trace-arguments"></span>)<span class="block trace-file-path">in <span title=""><strong>{{ $value['file'] ?? '' }}</strong> line {{ $value['line'] ?? '' }}</span></span> </td> </tr> @endforeach </tbody> </table> </div> </div> </body> </html>
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
jeremykenedy/laravel-exception-notifier
https://github.com/jeremykenedy/laravel-exception-notifier/blob/f9ca3992fe9e8491cd17599bf6935a3980827649/tests/TestCase.php
tests/TestCase.php
<?php namespace jeremykenedy\laravelexceptionnotifier\Test; use jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier; use Orchestra\Testbench\TestCase as OrchestraTestCase; class TestCase extends OrchestraTestCase { /** * Load package service provider. * * @param \Illuminate\Foundation\Application $app * @return jeremykenedy\laravelexceptionnotifier\LaravelExceptionNotifier */ protected function getPackageProviders($app) { return [LaravelExceptionNotifier::class]; } /** * Load package alias. * * @param \Illuminate\Foundation\Application $app * @return array */ protected function getPackageAliases($app) { return [ 'laravelexceptionnotifier', ]; } }
php
MIT
f9ca3992fe9e8491cd17599bf6935a3980827649
2026-01-05T05:00:25.309463Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Lexer.php
src/ReverseRegex/Lexer.php
<?php namespace ReverseRegex; use Doctrine\Common\Lexer as BaseLexer; use ReverseRegex\Exception as LexerException; /** * Lexer to split expression syntax * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Lexer extends BaseLexer { // ---------------------------------------------------------------------------- # Char Constants /** * @integer an escape character */ const T_ESCAPE_CHAR = -1; /** * The literal type ie a=a ^=^ */ const T_LITERAL_CHAR = 0; /** * Numeric literal 1=1 100=100 */ const T_LITERAL_NUMERIC = 1; /** * The opening character for group. [(] */ const T_GROUP_OPEN = 2; /** * The closing character for group [)] */ const T_GROUP_CLOSE = 3; /** * Opening character for Quantifier ({) */ const T_QUANTIFIER_OPEN = 4; /** * Closing character for Quantifier (}) */ const T_QUANTIFIER_CLOSE = 5; /** * Star quantifier character (*) */ const T_QUANTIFIER_STAR = 6; /** * Pluse quantifier character (+) */ const T_QUANTIFIER_PLUS = 7; /** * The one but optonal character (?) */ const T_QUANTIFIER_QUESTION = 8; /** * Start of string character (^) */ const T_START_CARET = 9; /** * End of string character ($) */ const T_END_DOLLAR = 10; /** * Range character inside set ([) */ const T_SET_OPEN = 11; /** * Range character inside set (]) */ const T_SET_CLOSE = 12; /** * Range character inside set (-) */ const T_SET_RANGE = 13; /** * Negated Character in set ([^) */ const T_SET_NEGATED = 14; /** * The either character (|) */ const T_CHOICE_BAR = 15; /** * The dot character (.) */ const T_DOT = 16; // ---------------------------------------------------------------------------- # Shorthand constants /** * One Word boundry */ const T_SHORT_W = 100; const T_SHORT_NOT_W = 101; const T_SHORT_D = 102; const T_SHORT_NOT_D = 103; const T_SHORT_S = 104; const T_SHORT_NOT_S = 105; /** * Unicode sequences /p{} /pNum */ const T_SHORT_P = 106; /** * Hex Sequences /x{} /xNum */ const T_SHORT_X = 108; /** * Unicode hex sequence /X{} /XNum */ const T_SHORT_UNICODE_X = 109; // ---------------------------------------------------------------------------- # Lexer Modes /** * @var boolean The lexer has detected escape character */ protected $escape_mode = false; /** * @var boolean The lexer is parsing a char set */ protected $set_mode = false; /** * @var integer the number of groups open */ protected $group_set = 0; /** * @var number of characters parsed inside the set */ protected $set_internal_counter = 0; // ---------------------------------------------------------------------------- # Doctrine\Common\Lexer Methods /** * Creates a new query scanner object. * * @param string $input a query string */ public function __construct($input) { $this->setInput($input); } /** * @inheritdoc */ protected function getCatchablePatterns() { return array( '.' ); } /** * @inheritdoc */ protected function getNonCatchablePatterns() { return array('\s+'); } /** * @inheritdoc */ protected function getType(&$value) { $type = null; switch (true) { case ($value === '\\' && $this->escape_mode === false) : $this->escape_mode = true; $type = self::T_ESCAPE_CHAR; if($this->set_mode === true) { $this->set_internal_counter++; } break; // Groups case ($value === '(' && $this->escape_mode === false && $this->set_mode === false) : $type = self::T_GROUP_OPEN; $this->group_set++; break; case ($value === ')' && $this->escape_mode === false && $this->set_mode === false) : $type = self::T_GROUP_CLOSE; $this->group_set--; break; // Charset case ($value === '[' && $this->escape_mode === false && $this->set_mode === true) : throw new LexerException("Can't have a second character class while first remains open"); break; case ($value === ']' && $this->escape_mode === false && $this->set_mode === false) : throw new LexerException("Can't close a character class while none is open"); break; case ($value === '[' && $this->escape_mode === false && $this->set_mode === false) : $this->set_mode = true; $type = self::T_SET_OPEN; $this->set_internal_counter = 1; break; case ($value === ']' && $this->escape_mode === false && $this->set_mode === true) : $this->set_mode = false; $type = self::T_SET_CLOSE; $this->set_internal_counter = 0; break; case ($value === '-' && $this->escape_mode === false && $this->set_mode === true) : $this->set_internal_counter++; return self::T_SET_RANGE; break; case ($value === '^' && $this->escape_mode === false && $this->set_mode === true && $this->set_internal_counter === 1) : $this->set_internal_counter++; return self::T_SET_NEGATED; break; // Quantifers case ($value === '{' && $this->escape_mode === false && $this->set_mode === false) : return self::T_QUANTIFIER_OPEN; case ($value === '}' && $this->escape_mode === false && $this->set_mode === false) : return self::T_QUANTIFIER_CLOSE; case ($value === '*' && $this->escape_mode === false && $this->set_mode === false) : return self::T_QUANTIFIER_STAR; case ($value === '+' && $this->escape_mode === false && $this->set_mode === false) : return self::T_QUANTIFIER_PLUS; case ($value === '?' && $this->escape_mode === false && $this->set_mode === false) : return self::T_QUANTIFIER_QUESTION; // Recognize symbols case ($value === '.' && $this->escape_mode === false && $this->set_mode === false) : return self::T_DOT; case ($value === '|' && $this->escape_mode === false && $this->set_mode === false) : return self::T_CHOICE_BAR; case ($value === '^' && $this->escape_mode === false && $this->set_mode === false) : return self::T_START_CARET; case ($value === '$' && $this->escape_mode === false && $this->set_mode === false) : return self::T_END_DOLLAR; // ShortCodes case ($value === 'd' && $this->escape_mode === true) : $type = self::T_SHORT_D; $this->escape_mode = false; break; case ($value === 'D' && $this->escape_mode === true) : $type = self::T_SHORT_NOT_D; $this->escape_mode = false; break; case ($value === 'w' && $this->escape_mode === true) : $type = self::T_SHORT_W; $this->escape_mode = false; break; case ($value === 'W' && $this->escape_mode === true) : $type = self::T_SHORT_NOT_W; $this->escape_mode = false; break; case ($value === 's' && $this->escape_mode === true) : $type = self::T_SHORT_S; $this->escape_mode = false; break; case ($value === 'S' && $this->escape_mode === true) : $type = self::T_SHORT_NOT_S; $this->escape_mode = false; break; case ($value === 'x' && $this->escape_mode === true) : $type = self::T_SHORT_X; $this->escape_mode = false; if($this->set_mode === true) { $this->set_internal_counter++; } break; case ($value === 'X' && $this->escape_mode === true) : $type = self::T_SHORT_UNICODE_X; $this->escape_mode = false; if($this->set_mode === true) { $this->set_internal_counter++; } break; case (($value === 'p' || $value === 'P') && $this->escape_mode === true) : $type = self::T_SHORT_P; $this->escape_mode = false; if($this->set_mode === true) { $this->set_internal_counter++; } break; // Default default : if(is_numeric($value) === true) { $type = self::T_LITERAL_NUMERIC; } else { $type = self::T_LITERAL_CHAR; } if($this->set_mode === true) { $this->set_internal_counter++; } $this->escape_mode = false; } return $type; } /** * Scans the input string for tokens. * * @param string $input a query string */ protected function scan($input) { # reset default for scan $this->group_set = 0; $this->escape_mode = false; $this->set_mode = false; static $regex; if ( ! isset($regex)) { $regex = '/(' . implode(')|(', $this->getCatchablePatterns()) . ')|' . implode('|', $this->getNonCatchablePatterns()) . '/ui'; } parent::scan($input); if($this->group_set > 0) { throw new LexerException('Opening group char "(" has no matching closing character'); } if($this->group_set < 0) { throw new LexerException('Closing group char "(" has no matching opening character'); } if($this->set_mode === true) { throw new LexerException('Character Class that been closed'); } } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Exception.php
src/ReverseRegex/Exception.php
<?php namespace ReverseRegex; /** * Base class for exceptions * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Exception extends \Exception { } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/ArrayCollection.php
src/ReverseRegex/ArrayCollection.php
<?php namespace ReverseRegex; use Doctrine\Common\Collections\ArrayCollection as BaseCollection; class ArrayCollection extends BaseCollection { /** * Sort the values using a ksort * * @access public * @return ArrayCollection */ public function sort() { $values = $this->toArray(); ksort($values); $this->clear(); foreach($values as $index => $value) { $this->set($index,$value); } return $this; } /** * Fetch a value using ones based position * * @access public * @param integer $position * @return mixed | null if bad position */ public function getAt($position) { if($position < $this->count() && $position < 0) { return null; } $this->first(); while($position > 1) { $this->next(); --$position; } return $this->current(); } } /* End of Class */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser.php
src/ReverseRegex/Parser.php
<?php namespace ReverseRegex; use ReverseRegex\Exception as ParserException; use ReverseRegex\Lexer; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; /** * Parser to convert regex into Group * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Parser { /** * @var Lexer */ protected $lexer; /** * @var ReverseRegex\Generator\Scope */ protected $result; /** * @var ReverseRegex\Generator\Scope the current head */ protected $head; /** * @var ReverseRegex\Generator\Scope Last attached scope */ protected $left; /** * Class Constructor * * @access public * @param Lexer $lexer */ public function __construct(Lexer $lexer, Scope $result, Scope $head = null) { $this->lexer = $lexer; $this->result = $result; if($head === null) { $this->head = new Scope(); } else { $this->head = $head; } $this->result->attach($head); $this->left = $head; } /** * Fetch the regex lexer * * @access public * @return Lexer */ public function getLexer() { return $this->lexer; } /** * Will parse the regex into generator * * @access public * @return */ public function parse($sub = false) { try { while($this->lexer->moveNext()) { $result = null; $scope = null; $parser = null; switch(true) { case($this->lexer->isNextToken(Lexer::T_GROUP_OPEN)) : # is the group character the first token? is the regex wrapped in brackets. //if($this->lexer->token === null) { // continue; //} # note this is a new group create new parser instance. $parser = new Parser($this->lexer,new Scope(),new Scope()); $this->left = $parser->parse(true)->getResult(); $this->head->attach($this->left); break; case($this->lexer->isNextToken(Lexer::T_GROUP_CLOSE)) : # group is finished don't want to contine this loop break = 2 break 2; break; case ($this->lexer->isNextTokenAny(array(Lexer::T_LITERAL_CHAR,Lexer::T_LITERAL_NUMERIC))): # test for literal characters (abcd) $this->left = new LiteralScope(); $this->left->addLiteral($this->lexer->lookahead['value']); $this->head->attach($this->left); break; case($this->lexer->isNextToken(Lexer::T_SET_OPEN)) : # character classes [a-z] $this->left = new LiteralScope(); self::createSubParser('character')->parse($this->left,$this->head,$this->lexer); $this->head->attach($this->left); break; case ($this->lexer->isNextTokenAny(array( Lexer::T_DOT, Lexer::T_SHORT_D, Lexer::T_SHORT_NOT_D, Lexer::T_SHORT_W, Lexer::T_SHORT_NOT_W, Lexer::T_SHORT_S, Lexer::T_SHORT_NOT_S))): # match short (. \d \D \w \W \s \S) $this->left = new LiteralScope(); self::createSubParser('short')->parse($this->left,$this->head,$this->lexer); $this->head->attach($this->left); break; case ($this->lexer->isNextTokenAny(array( Lexer::T_SHORT_P, Lexer::T_SHORT_UNICODE_X, Lexer::T_SHORT_X))): # match short (\p{L} \x \X ) $this->left = new LiteralScope(); self::createSubParser('unicode')->parse($this->left,$this->head,$this->lexer); $this->head->attach($this->left); break; case ($this->lexer->isNextTokenAny(array( Lexer::T_QUANTIFIER_OPEN, Lexer::T_QUANTIFIER_PLUS, Lexer::T_QUANTIFIER_QUESTION, Lexer::T_QUANTIFIER_STAR, Lexer::T_QUANTIFIER_OPEN ))): # match quantifiers self::createSubParser('quantifer')->parse($this->left,$this->head,$this->lexer); break; case ($this->lexer->isNextToken(Lexer::T_CHOICE_BAR)): # match alternations $this->left = $this->head; $this->head = new Scope(); $this->result->useAlternatingStrategy(); $this->result->attach($this->head); break; default: # ignore character } } } catch(ParserException $e) { $pos = $this->lexer->lookahead['position']; $compressed = $this->compress(); throw new ParserException(sprintf('Error found STARTING at position %s after `%s` with msg %s ',$pos,$compressed,$e->getMessage())); } return $this; } /** * Compress the lexer into value string until current lookahead * * @access public * @return string the compressed value string */ public function compress() { $current = $this->lexer->lookahead['position']; $this->lexer->reset(); $string = ''; while($this->lexer->moveNext() && $this->lexer->lookahead['position'] <= $current) { $string .= $this->lexer->lookahead['value']; } return $string; } /** * Return the result of the parse */ public function getResult() { return $this->result; } public static $sub_parsers = array( 'character' => '\\ReverseRegex\\Parser\\CharacterClass', 'unicode' => '\\ReverseRegex\\Parser\\Unicode', 'quantifer' => '\\ReverseRegex\\Parser\\Quantifier', 'short' => '\\ReverseRegex\\Parser\\Short' ); /** * Return an instance os subparser * * @access public * @static * @return ReverseRegex\Parser\StrategyInterface * @param string $name the short name */ static function createSubParser($name) { if(isset(self::$sub_parsers[$name]) === false) { throw new ParserException('Unknown subparser at '.$name); } if(is_object(self::$sub_parsers[$name]) === false) { self::$sub_parsers[$name] = new self::$sub_parsers[$name](); } return self::$sub_parsers[$name]; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/UnicodeTest.php
src/ReverseRegex/Test/UnicodeTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; use ReverseRegex\Parser\Unicode; class UnicodeTest extends Basic { public function testUnsupportedShortProperty() { $lexer = new Lexer('\p'); $scope = new Scope(); $parser = new Unicode(); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Property \p (Unicode Property) not supported use \x to specify unicode character or range'); $parser->parse($scope,$scope,$lexer); } public function testErrorNoOpeningBrace() { $lexer = new Lexer('\Xaaaaa'); $scope = new Scope(); $parser = new Unicode(); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Expecting character { after \X none found'); $parser->parse($scope,$scope,$lexer); } public function testErrorNested() { $lexer = new Lexer('\X{aa{aa}'); $scope = new Scope(); $parser = new Unicode(); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Nesting hex value ranges is not allowed'); $parser->parse($scope,$scope,$lexer); } public function testErrorUnclosed() { $lexer = new Lexer('\X{aaaa'); $scope = new Scope(); $parser = new Unicode(); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Closing quantifier token `}` not found'); $parser->parse($scope,$scope,$lexer); } public function testErrorEmptyToken() { $lexer = new Lexer('\X{}'); $scope = new Scope(); $parser = new Unicode(); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('No hex number found inside the range'); $parser->parse($scope,$scope,$lexer); } public function testsExampleA() { $lexer = new Lexer('\X{FA24}'); $scope = new Scope(); $parser = new Unicode(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); $this->assertEquals('﨤',$result[0]); } public function testShortErrorWhenBraces() { $lexer = new Lexer('\x{64'); $scope = new Scope(); $parser = new Unicode(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Braces not supported here'); $parser->parse($head,$scope,$lexer); } public function testShortX() { $lexer = new Lexer('\x64'); $scope = new Scope(); $parser = new Unicode(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); $this->assertEquals('d',$result[0]); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/ShortTest.php
src/ReverseRegex/Test/ShortTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; use ReverseRegex\Parser\Short; class ShortTest extends Basic { public function testDigit() { $lexer = new Lexer('\d'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertRegExp('/\d/',$value); } } public function testNotDigit() { $lexer = new Lexer('\D'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertRegExp('/\D/',$value); } } public function testWhitespace() { $lexer = new Lexer('\s'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertTrue(!empty($value)); } } public function testNonWhitespace() { $lexer = new Lexer('\S'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertTrue(!empty($value)); } } public function testWord() { $lexer = new Lexer('\w'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertRegExp('/\w/',$value); } } public function testNonWord() { $lexer = new Lexer('\W'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); foreach($result as $value) { $this->assertRegExp('/\W/',$value); } } public function testDotRange() { $lexer = new Lexer('.'); $scope = new Scope(); $parser = new Short(); $head = new LiteralScope('lit1',$scope); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $result = $head->getLiterals(); // match 0..127 char in ASSCI Chart $this->assertCount(128,$result); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/CharacterClassTest.php
src/ReverseRegex/Test/CharacterClassTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; use ReverseRegex\Parser\CharacterClass; class CharacterClassTest extends Basic { public function testNormalizeNoUnicode() { $lexer = new Lexer('[a-mnop]'); $scope = new Scope(); $parser = new CharacterClass(); $lexer->moveNext(); $result = $parser->normalize($scope,$scope,$lexer); $this->assertEquals('[a-mnop]',$result); } public function testNormalizeWithUnicodeValue() { $lexer = new Lexer('[\X{00ff}nop]'); $scope = new Scope(); $parser = new CharacterClass(); $lexer->moveNext(); $result = $parser->normalize($scope,$scope,$lexer); $this->assertEquals('[\\ÿnop]',$result); } public function testNormalizeWithUnicodeRange() { $lexer = new Lexer('[\X{00FF}-\X{00FF}mnop]'); $scope = new Scope(); $parser = new CharacterClass(); $lexer->moveNext(); $result = $parser->normalize($scope,$scope,$lexer); $this->assertEquals('[\\ÿ-\\ÿmnop]',$result); } public function testFillRangeAscii() { $start = '!'; $end = '&'; $range = '!"#$%&'; $scope = new LiteralScope(); $parser = new CharacterClass(); $parser->fillRange($scope,$start,$end); $this->assertEquals($range,implode('',$scope->getLiterals()->toArray())); } public function testFillRangeUnicode() { $start = 'Ꭰ'; $end = 'Ꭵ'; $range = 'ᎠᎡᎢᎣᎤᎥ'; $scope = new LiteralScope(); $parser = new CharacterClass(); $parser->fillRange($scope,$start,$end); $this->assertEquals($range,implode('',$scope->getLiterals()->toArray())); } public function testFillRangeOutofOrder() { $start = 'z'; $end = 'a'; $scope = new LiteralScope(); $parser = new CharacterClass(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Character class range z - a is out of order'); $parser->fillRange($scope,$start,$end); } public function testParseNoRanges() { $lexer = new Lexer('[amnop]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->toArray(); $this->assertEquals(array('a','m','n','o','p'),array_values($values)); } public function testParseNoUnicodeShorts() { $lexer = new Lexer('[a-k]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->toArray(); $this->assertEquals(array('a','b','c','d','e','f','g','h','i','j','k'),array_values($values)); } public function testParseNoUnicodeShortsMultiRange() { $lexer = new Lexer('[a-k-n]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->toArray(); $this->assertEquals(array('a','b','c','d','e','f','g','h','i','j','k','l','m','n'),array_values($values)); } public function testParseUnicodeShort() { $lexer = new Lexer('[\X{0061}-\X{006B}]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->toArray(); $this->assertEquals(array('a','b','c','d','e','f','g','h','i','j','k'),array_values($values)); } public function testParseHexShort() { $lexer = new Lexer('[\x61-\x6B]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->toArray(); $this->assertEquals(array('a','b','c','d','e','f','g','h','i','j','k'),array_values($values)); } public function testParseHexShortMultirange() { $lexer = new Lexer('[z\x61-\x6B-\x6E]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); $values = $head->getLiterals()->getValues(); $this->assertEquals(array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','z'),$values); } public function testParseHexShortBraceError() { $lexer = new Lexer('[\x{61}-\x6B-\x6E]'); $scope = new Scope(); $head = new LiteralScope(); $parser = new CharacterClass(); $this->expectException(RegexException::class); $this->expectExceptionMessage('Braces not supported here'); $lexer->moveNext(); $parser->parse($head,$scope,$lexer); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/ScopeTest.php
src/ReverseRegex/Test/ScopeTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; use ReverseRegex\Generator\LiteralScope; class ScopeTest extends Basic { public function testScopeImplementsRepeatInterface() { $scope = new Scope('scope1'); $this->assertInstanceOf('ReverseRegex\Generator\RepeatInterface',$scope); } public function testScopeImplementsContextInterface() { $scope = new Scope('scope1'); $this->assertInstanceOf('ReverseRegex\Generator\ContextInterface',$scope); } public function testScopeExtendsNode() { $scope = new Scope('scope1'); $this->assertInstanceOf('ReverseRegex\Generator\Node',$scope); } public function testScopeImplementsAlternateInterface() { $scope = new Scope('scope1'); $this->assertInstanceOf('ReverseRegex\Generator\AlternateInterface',$scope); } public function testAlternateInterface() { $scope = new Scope('scope1'); $this->assertFalse($scope->usingAlternatingStrategy()); $scope->useAlternatingStrategy(true); $this->assertTrue($scope->usingAlternatingStrategy()); } public function testRepeatInterface() { $scope = new Scope('scope1'); $scope->setMaxOccurances(10); $scope->setMinOccurances(5); $this->assertEquals(10,$scope->getMaxOccurances()); $this->assertEquals(5,$scope->getMinOccurances()); $this->assertEquals(5,$scope->getOccuranceRange()); } public function testAttachChild() { $scope = new Scope('scope1'); $scope2 = new Scope('scope2'); $scope->attach($scope2)->rewind(); $this->assertEquals($scope2,$scope->current()); } public function testRepeatQuota() { $gen = new MersenneRandom(703); $scope = new Scope('scope1'); $scope->setMinOccurances(1); $scope->setMaxOccurances(6); $this->assertEquals(3,$scope->calculateRepeatQuota($gen)); } public function testGenerateErrorNotChildren() { $gen = new MersenneRandom(700); $scope = new Scope('scope1'); $scope->setMinOccurances(1); $scope->setMaxOccurances(6); $result = ''; $this->expectException(RegexException::class); $this->expectExceptionMessage("No child scopes to call must be atleast 1"); $scope->generate($result,$gen); } public function testGenerate() { $gen = new MersenneRandom(700); $result = ''; $scope = new Scope('scope1'); $scope->setMinOccurances(6); $scope->setMaxOccurances(6); $child = $this->getMockBuilder('ReverseRegex\Generator\Scope')->setMethods(['generate'])->getMock(); $child->expects($this->exactly(6)) ->method('generate') ->with($this->isType('string'),$this->equalTo($gen)) ->will($this->returnCallback(function(&$sResult){ return $sResult .= 'a'; })); $scope->attach($child); $result = $scope->generate($result,$gen); $this->assertEquals('aaaaaa',$result); } public function testGetNode() { $scope = new Scope('scope1'); for($i = 1; $i <= 6; $i++) { $scope->attach(new Scope('label_'.$i)); } $other_scope = $scope->get(6); $this->assertInstanceOf('ReverseRegex\Generator\Scope',$other_scope); $this->assertEquals('label_6',$other_scope->getLabel()); $other_scope = $scope->get(1); $this->assertInstanceOf('ReverseRegex\Generator\Scope',$other_scope); $this->assertEquals('label_1',$other_scope->getLabel()); $other_scope = $scope->get(3); $this->assertInstanceOf('ReverseRegex\Generator\Scope',$other_scope); $this->assertEquals('label_3',$other_scope->getLabel()); $other_scope = $scope->get(0); $this->assertEquals(null,$other_scope); } public function testGenerateWithAlternatingStrategy() { $scope = new Scope('scope1'); $gen = new MersenneRandom(700); $result = ''; $scope->setMinOccurances(7); $scope->setMaxOccurances(7); for($i = 1; $i <= 6; $i++) { $lit = new LiteralScope('label_'.$i); $lit->addLiteral($i); $scope->attach($lit); $lit = null; } $scope->useAlternatingStrategy(); $scope->generate($result,$gen); $this->assertRegExp('/[1-6]{7}/',$result); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/QuantifierParserTest.php
src/ReverseRegex/Test/QuantifierParserTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Lexer; use ReverseRegex\Parser\Quantifier; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; class QuantifierParserTest extends Basic { public function testQuantifierParserPatternA() { $pattern = '{1,5}'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(1,$scope->getMinOccurances()); $this->assertEquals(5,$scope->getMaxOccurances()); } public function testQuantiferSingleValue() { $pattern = '{5}'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(5,$scope->getMinOccurances()); $this->assertEquals(5,$scope->getMaxOccurances()); } public function testQuantiferSpacesIncluded() { $pattern = '{ 1 , 5 }'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(1,$scope->getMinOccurances()); $this->assertEquals(5,$scope->getMaxOccurances()); } public function testFailerAlphaCaracters() { $pattern = '{ 1 , 5a }'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage("Quantifier expects and integer compitable string"); $qual->parse($scope,$scope,$lexer); } public function testFailerMissingMaximumCaracters() { $pattern = '{ 1 ,}'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage("Quantifier expects and integer compitable string"); $qual->parse($scope,$scope,$lexer); } public function testFailerMissingMinimumCaracters() { $pattern = '{,1}'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage("Quantifier expects and integer compitable string"); $qual->parse($scope,$scope,$lexer); } public function testMissingClosureCharacter() { $pattern = '{1,1'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage("Closing quantifier token `}` not found"); $qual->parse($scope,$scope,$lexer); } public function testNestingQuantifiers() { $pattern = '{1,1{1,1}'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $this->expectException(RegexException::class); $this->expectExceptionMessage("Nesting Quantifiers is not allowed"); $qual->parse($scope,$scope,$lexer); } public function testStarQuantifier() { $pattern = 'az*'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $lexer->moveNext(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(0,$scope->getMinOccurances()); $this->assertEquals(PHP_INT_MAX,$scope->getMaxOccurances()); } public function testCrossQuantifier() { $pattern = 'az+'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $lexer->moveNext(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(1,$scope->getMinOccurances()); $this->assertEquals(PHP_INT_MAX,$scope->getMaxOccurances()); } public function testQuestionQuantifier() { $pattern = 'az?'; $lexer = new Lexer($pattern); $scope = new Scope(); $qual = new Quantifier(); $lexer->moveNext(); $lexer->moveNext(); $lexer->moveNext(); $qual->parse($scope,$scope,$lexer); $this->assertEquals(0,$scope->getMinOccurances()); $this->assertEquals(1,$scope->getMaxOccurances()); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/Basic.php
src/ReverseRegex/Test/Basic.php
<?php namespace ReverseRegex\Test; use PHPUnit\Framework\TestCase; use ReverseRegex\PimpleBootstrap; use Pimple\Pimple; abstract class Basic extends TestCase { public function createApplication() { $boot = new PimpleBootstrap(); $pimple = $boot->boot(new Pimple()); return $pimple; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/LexerTest.php
src/ReverseRegex/Test/LexerTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Lexer; class LexerTest extends Basic { public function testInheritsDoctrineLexer() { $lexer = new Lexer('[a-z]'); $this->assertInstanceOf('\Doctrine\Common\Lexer',$lexer); } public function testLexerPatternA() { $lexer = new Lexer('[a-z]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('a',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('-',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_RANGE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('z',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); //$lexer->moveNext(); //$this->assertEquals(null,$lexer->lookahead['value']); } public function testLexerPatternB() { $lexer = new Lexer('\[a-z\]'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('a',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('-',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('z',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); //$lexer->moveNext(); //$this->assertEquals(null,$lexer->lookahead['value']); } public function testLexerPatternC() { $lexer = new Lexer('[1-9]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('1',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('-',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_RANGE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('9',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); //$lexer->moveNext(); //$this->assertEquals(null,$lexer->lookahead['value']); } public function testLexerPatternD() { $lexer = new Lexer('[1-9\x{56}]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('1',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('-',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_RANGE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('9',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('x',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_X,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('{',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('5',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('6',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('}',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); //$lexer->moveNext(); //$this->assertEquals(null,$lexer->lookahead['value']); } public function testLexerPatternE() { $lexer = new Lexer('([^1-8\[]){0,9}*?+'); $lexer->moveNext(); $this->assertEquals('(',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('^',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_NEGATED,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('1',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('-',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_RANGE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('8',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(')',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_CLOSE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('{',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('0',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(',',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('9',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('}',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_CLOSE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('*',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_STAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('?',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_QUESTION,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('+',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_PLUS,$lexer->lookahead['type']); //$lexer->moveNext(); //$this->assertEquals(null,$lexer->lookahead['value']); } public function testParrentShortCodes() { $lexer = new Lexer('\W'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('W',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_NOT_W,$lexer->lookahead['type']); $lexer = new Lexer('\w'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('w',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_W,$lexer->lookahead['type']); $lexer = new Lexer('\S'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('S',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_NOT_S,$lexer->lookahead['type']); $lexer = new Lexer('\s'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('s',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_S,$lexer->lookahead['type']); $lexer = new Lexer('\D'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('D',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_NOT_D,$lexer->lookahead['type']); $lexer = new Lexer('\d'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('d',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_D,$lexer->lookahead['type']); } public function testLexerPatternF() { $lexer = new Lexer('[\']'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); # in the above expression using php metasequence \' to escape a single quote # the reg only see the expression ['] and NOT [\'] $lexer->moveNext(); $this->assertEquals("'",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testLexerEscapedBlackslash() { $lexer = new Lexer('\\\\'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); } public function testLexerBrackets() { $lexer = new Lexer('[\p{}]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("\\",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("p",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_P,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("{",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("}",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); $lexer = new Lexer('\p{}'); $lexer->moveNext(); $this->assertEquals("\\",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("p",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_P,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("{",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals("}",$lexer->lookahead['value']); $this->assertEquals(Lexer::T_QUANTIFIER_CLOSE,$lexer->lookahead['type']); } public function testAlternation() { $lexer = new Lexer('A|a'); $lexer->moveNext(); $this->assertEquals('A',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('|',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_CHOICE_BAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('a',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); # no alternation in char classes $lexer = new Lexer('[A|a]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('A',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('|',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('a',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testDotCharacter() { $lexer = new Lexer('.'); $lexer->moveNext(); $this->assertEquals('.',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_DOT,$lexer->lookahead['type']); $lexer = new Lexer('\.'); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('.',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); # normal char in a char class $lexer = new Lexer('[.]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('.',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testLexerPatternG() { $lexer = new Lexer('abcd&\*\(\)'); $lexer->moveNext(); $this->assertEquals('a',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('b',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('c',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('d',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('&',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('*',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('(',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(')',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); } public function testUnicodePropertyinCharacterClass() { $lexer = new Lexer('[np\p{L}]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('n',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('p',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('p',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_P,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('{',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('L',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('}',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testUnicodeReferencePropertyinCharacterClass() { $lexer = new Lexer('[no\X{00FF}]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('n',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('o',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('X',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SHORT_UNICODE_X,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('{',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('0',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('0',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_NUMERIC,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('F',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('F',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('}',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testCarretAndDollar() { $lexer = new Lexer('^$'); $lexer->moveNext(); $this->assertEquals('^',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_START_CARET,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('$',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_END_DOLLAR,$lexer->lookahead['type']); $lexer = new Lexer('[\^$]'); $lexer->moveNext(); $this->assertEquals('[',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('\\',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_ESCAPE_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('^',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR, $lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('$',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_LITERAL_CHAR,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(']',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_SET_CLOSE,$lexer->lookahead['type']); } public function testLexerPatternHGroupNesting() { $lexer = new Lexer('(())'); $lexer->moveNext(); $this->assertEquals('(',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals('(',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_OPEN,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(')',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_CLOSE,$lexer->lookahead['type']); $lexer->moveNext(); $this->assertEquals(')',$lexer->lookahead['value']); $this->assertEquals(Lexer::T_GROUP_CLOSE,$lexer->lookahead['type']); } public function testGroupNestingErrorStillOpen() { $this->expectException(RegexException::class); $this->expectExceptionMessage('Opening group char "(" has no matching closing character'); $lexer = new Lexer('(()'); } public function testGroupNestingErrorClosedNotOpened() { $this->expectException(RegexException::class); $this->expectExceptionMessage('Closing group char "(" has no matching opening character'); $lexer = new Lexer('())'); } public function testCharSetNestingError() { $this->expectException(RegexException::class); $this->expectExceptionMessage("Can't have a second character class while first remains open"); $lexer = new Lexer('[[]]'); } public function testCharSetOpenError() { $this->expectException(RegexException::class); $this->expectExceptionMessage("Can't close a character class while none is open"); $lexer = new Lexer(']'); } public function testCharSetOpenNotClosed() { $this->expectException(RegexException::class); $this->expectExceptionMessage("Character Class that been closed"); $lexer = new Lexer('['); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/ParserTest.php
src/ReverseRegex/Test/ParserTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Exception as RegexException; use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; class ParserTest extends Basic { public function testParserExampleA() { $lexer = new Lexer('ex1{5,5}'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertEquals('ex11111',$result); } public function testParserExampleB() { //$lexer = new Lexer('\(0[23478]\)-[0-9]{4} [0-9]{4}'); $lexer = new Lexer('(\(0[23478]\)){4}'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertEquals('(02)(04)(02)(08)',$result); } public function testExampleC() { $lexer = new Lexer('509[0-9][A-K]'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertEquals('5090J',$result); } public function testExampleD() { $lexer = new Lexer('\d\d\d'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertRegExp('/\d\d\d/',$result); } public function testExampleE() { $lexer = new Lexer('\d\d\d([a-zA-Z])\w.'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(10034343); $generator->generate($result,$random); $this->assertRegExp('/\d\d\d([a-zA-Z])\w./',$result); } public function testParserExamplePhoneNumber() { $lexer = new Lexer('\(0[23478]\)[0-9]{4}-[0-9]{4}'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertEquals('(02)2595-1288',$result); } public function testParserExamplePostCode() { # Australian Post Codes. # ACT: 0200-0299 and 2600-2639. # NSW: 1000-1999, 2000-2599 and 2640-2914. # NT: 0900-0999 and 0800-0899. # QLD: 9000-9999 and 4000-4999. # SA: 5000-5999. # TAS: 7800-7999 and 7000-7499. # VIC: 8000-8999 and 3000-3999. # WA: 6800-6999 and 6000-6799 $lexer = new Lexer("(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})"); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $random = new MersenneRandom(10789); for($i = 100; $i > 0; $i--) { $result =''; $generator->generate($result,$random); $this->assertRegExp('/^(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})$/',$result); } # Generate Postcode for ACT only $lexer = new Lexer('02[0-9]{2}|26[0-3][0-9]'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $result =''; $random = new MersenneRandom(100); $generator->generate($result,$random); $this->assertEquals('0225',$result); $result =''; $generator->generate($result,$random); $this->assertEquals('2631',$result); $result =''; $generator->generate($result,$random); $this->assertEquals('0288',$result); $result =''; $generator->generate($result,$random); $this->assertEquals('0243',$result); $result =''; $generator->generate($result,$random); $this->assertEquals('0284',$result); $result =''; $generator->generate($result,$random); $this->assertEquals('0210',$result); } public function testHellowWorld() { $lexer = new Lexer("Hello|World|Is|Good"); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $random = new MersenneRandom(10789); for($i = 10; $i > 0; $i--) { $result =''; $generator->generate($result,$random); $this->assertRegExp('/^Hello|World|Is|Good$/',$result); } } public function testLimitingQuantifer() { $lexer = new Lexer("(Hello){5,9}"); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $random = new MersenneRandom(10789); for($i = 10; $i > 0; $i--) { $result =''; $generator->generate($result,$random); $this->assertRegExp('/(Hello){5,9}/',$result); } $lexer = new Lexer("(Hello)?"); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); $random = new MersenneRandom(107559); $result =''; $generator->generate($result,$random); $this->assertRegExp('/(Hello)?/',$result); } public function testParserLexerError() { $this->expectException(RegexException::class); $this->expectExceptionMessage("Error found STARTING at position 3 after `\(0[` with msg Negated Character Set ranges not supported at this time"); $lexer = new Lexer('\(0[^23478]\)[0-9]{4}-[0-9]{4}'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $generator = $parser->parse()->getResult(); } public function testParserLexerErrorB() { $lexer = new Lexer('\(0[23478]\)[9-4]{4}-[0-9]{4}'); $container = new Scope(); $head = new Scope(); $parser = new Parser($lexer,$container,$head); $this->expectException(RegexException::class); $this->expectExceptionMessage("Error found STARTING at position 16 after `\(0[23478]\)[9-4]` with msg Character class range 9 - 4 is out of order"); $generator = $parser->parse()->getResult(); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Test/LiteralScopeTest.php
src/ReverseRegex/Test/LiteralScopeTest.php
<?php namespace ReverseRegex\Test; use ReverseRegex\Generator\LiteralScope; class LiteralScopeTest extends Basic { public function testExtendsScope() { $literal = new LiteralScope('scope1'); $this->assertInstanceOf('ReverseRegex\Generator\Scope',$literal); } public function testAddLiteral() { $literal = new LiteralScope('scope1'); $literal->addLiteral('a'); $literal->addLiteral('b'); $literal->addLiteral('c'); $collection = $literal->getLiterals(); $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection',$collection); $this->assertEquals('a',$collection->get(0)); $this->assertEquals('b',$collection->get(1)); $this->assertEquals('c',$collection->get(2)); } public function testGenerateNoRepeats() { $literal = new LiteralScope('scope1'); $literal->addLiteral('a'); $literal->setMinOccurances(1); $literal->setMaxOccurances(1); $generator_mock = $this->createMock('ReverseRegex\Random\GeneratorInterface', array('generate','seed','max')); $generator_mock->expects($this->exactly(0)) ->method('generate'); $result = ''; $literal->generate($result,$generator_mock); $this->assertEquals('a',$result); } public function testGenerateRepeatsTwice() { $literal = new LiteralScope('scope1'); $literal->addLiteral('a'); $literal->addLiteral('b'); $literal->setMinOccurances(2); $literal->setMaxOccurances(2); $generator_mock = $this->createMock('ReverseRegex\Random\GeneratorInterface', array('generate','seed','max')); $generator_mock->expects($this->exactly(2)) ->method('generate') ->with($this->equalTo(1),$this->equalTo(2)) ->will($this->returnValue(0)); $result = ''; $literal->generate($result,$generator_mock); $this->assertEquals('aa',$result); } public function testGenerateWithSmallRange() { $literal = new LiteralScope('scope1'); $literal->addLiteral('a'); $literal->setMinOccurances(1); $literal->setMaxOccurances(2); $gen = new \ReverseRegex\Random\SrandRandom(0); $result = ''; $literal->generate($result,$gen); $this->assertLessThanOrEqual(2, strlen($result)); $this->assertGreaterThanOrEqual(1, strlen($result)); } public function testGenerateWithMulipleLiterals() { $literal = new LiteralScope('scope1'); $literal->addLiteral('a'); $literal->addLiteral('b'); $literal->addLiteral('c'); $literal->addLiteral('d'); $literal->setMinOccurances(1); $literal->setMaxOccurances(4); $gen = new \ReverseRegex\Random\SrandRandom(0); $result = ''; $literal->generate($result,$gen); $this->assertLessThanOrEqual(4, strlen($result)); $this->assertGreaterThanOrEqual(1, strlen($result)); } public function testSetLiteral() { $literal = new LiteralScope('scope1'); $literal->setLiteral('0001','a'); $literal->setLiteral('0002','b'); $literal->setLiteral('0003','c'); $literal->setLiteral('0004','d'); $result = $literal->getLiterals()->toArray(); $this->assertArrayHasKey('0001',$result); $this->assertArrayHasKey('0002',$result); $this->assertArrayHasKey('0003',$result); $this->assertArrayHasKey('0004',$result); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser/Short.php
src/ReverseRegex/Parser/Short.php
<?php namespace ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; use ReverseRegex\Lexer; use ReverseRegex\Exception as ParserException; /** * Parse a following Shorts (\d, \w, \D, \W, \s, \S, dot) * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Short implements StrategyInterface { /** * Parse the current token for Short Codes `.` `\d` `\w` * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $set * @param ReverseRegex\Lexer $lexer */ public function parse(Scope $head, Scope $set, Lexer $lexer) { switch(true) { case ($lexer->isNextToken(Lexer::T_DOT)) : $this->convertDotToRange($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_SHORT_D)) : case ($lexer->isNextToken(Lexer::T_SHORT_NOT_D)) : $this->convertDigitToRange($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_SHORT_W)) : case ($lexer->isNextToken(Lexer::T_SHORT_NOT_W)) : $this->convertWordToRange($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_SHORT_S)) : case ($lexer->isNextToken(Lexer::T_SHORT_NOT_S)) : $this->convertWhiteSpaceToRange($head,$set,$lexer); break; default : //do nothing no token matches found } } public function convertDotToRange(Scope $head, Scope $result, Lexer $lexer) { for($i = 0; $i <= 127; $i++) { $head->addLiteral(chr($i)); } } public function convertDigitToRange(Scope $head, Scope $result, Lexer $lexer) { if($lexer->isNextToken(Lexer::T_SHORT_D)) { # digits only (0048 - 0057) digits $min = 48; $max = 57; while($min <= $max) { $head->addLiteral(chr($min)); $min++; } } else { # not digits every assci character expect (0048 - 0057) digits $min = 0; $max = 47; while($min <= $max) { $head->addLiteral(chr($min)); $min++; } $min = 58; $max = 127; while($min <= $max) { $head->addLiteral(chr($min)); $min++; } } } public function convertWordToRange(Scope $head, Scope $result, Lexer $lexer) { if($lexer->isNextToken(Lexer::T_SHORT_W)) { # `[a-zA-Z0-9_]` # 48 - 57 for($i = 48; $i <= 57; $i++) { $head->addLiteral(chr($i)); } # 65 - 90 for($i = 65; $i <= 90; $i++) { $head->addLiteral(chr($i)); } # 95 $head->addLiteral(chr(95)); # 97 - 122 for($i = 97; $i <= 122; $i++) { $head->addLiteral(chr($i)); } } else { # `![a-zA-Z0-9_]` # 0 - 47 for($i = 0; $i <= 47; $i++) { $head->addLiteral(chr($i)); } # 58 - 64 for($i = 58; $i <= 64; $i++) { $head->addLiteral(chr($i)); } # 91 - 94 for($i = 91; $i <= 94; $i++) { $head->addLiteral(chr($i)); } # 96 $head->addLiteral(chr(96)); # 123 - 127 for($i = 123; $i <= 127; $i++) { $head->addLiteral(chr($i)); } } } public function convertWhiteSpaceToRange(Scope $head, Scope $result, Lexer $lexer) { if($lexer->isNextToken(Lexer::T_SHORT_S)) { # spaces, tabs, and line breaks #0009 #0010 #0012 #0013 #0032 $head->addLiteral(chr(9)); $head->addLiteral(chr(10)); $head->addLiteral(chr(12)); $head->addLiteral(chr(13)); $head->addLiteral(chr(32)); } else { # not spaces, tabs, and line breaks #0000-0008 #0011 #0014 - #0031 for($i=0; $i <= 8; $i++) { $head->addLiteral(chr($i)); } $head->addLiteral(chr(11)); for($i=14; $i <= 31; $i++) { $head->addLiteral(chr($i)); } } } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser/Quantifier.php
src/ReverseRegex/Parser/Quantifier.php
<?php namespace ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Lexer; use ReverseRegex\Exception as ParserException; /** * Parse a group quantifer e.g (abghb){1,5} , (abghb){5} , (abghb)* , (abghb)? , (abghb)+ * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Quantifier implements StrategyInterface { /** * Parse the current token for new Quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $set * @param ReverseRegex\Lexer $lexer */ public function parse(Scope $head, Scope $set, Lexer $lexer) { switch(true) { case ($lexer->isNextToken(Lexer::T_QUANTIFIER_PLUS)) : $head = $this->quantifyPlus($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_QUANTIFIER_QUESTION)) : $head = $this->quantifyQuestion($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_QUANTIFIER_STAR)) : $head = $this->quantifyStar($head,$set,$lexer); break; case ($lexer->isNextToken(Lexer::T_QUANTIFIER_OPEN)) : $head = $this->quantifyClosure($head,$set,$lexer); break; default : //do nothing no token matches found } return $head; } /** * Parse the current token for + quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $result * @param ReverseRegex\Lexer $lexer */ public function quantifyPlus(Scope $head, Scope $result, Lexer $lexer) { $min = 1; $max = PHP_INT_MAX; $head->setMaxOccurances($max); $head->setMinOccurances($min); return $head; } /** * Parse the current token for * quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $result * @param ReverseRegex\Lexer $lexer */ public function quantifyStar(Scope $head, Scope $result, Lexer $lexer) { $min = 0; $max = PHP_INT_MAX; $head->setMaxOccurances($max); $head->setMinOccurances($min); return $head; } /** * Parse the current token for ? quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $result * @param ReverseRegex\Lexer $lexer */ public function quantifyQuestion(Scope $head, Scope $result, Lexer $lexer) { $min = 0; $max = 1; $head->setMaxOccurances($max); $head->setMinOccurances($min); return $head; } /** * Parse the current token for closers : {###} { ## } {##,##} * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $result * @param ReverseRegex\Lexer $lexer */ public function quantifyClosure(Scope $head, Scope $result, Lexer $lexer) { $tokens = array(); $min = $head->getMinOccurances(); $max = $head->getMaxOccurances(); # move to the first token inside the quantifer. # parse for the minimum , move lookahead until read end of the closure or the `,` while($lexer->moveNext() === true && !$lexer->isNextToken(Lexer::T_QUANTIFIER_CLOSE) && $lexer->lookahead['value'] !== ',' ) { if($lexer->isNextToken(Lexer::T_QUANTIFIER_OPEN)) { throw new ParserException('Nesting Quantifiers is not allowed'); } $tokens[] = $lexer->lookahead; } $min = $this->convertInteger($tokens); # do we have a maximum after the comma? if($lexer->lookahead['value'] === ',' ) { # make sure we have values to gather ie not {778,} $tokens = array(); # move to the first token after the `,` character # grab the remaining numbers while($lexer->moveNext() && !$lexer->isNextToken(Lexer::T_QUANTIFIER_CLOSE)) { if($lexer->isNextToken(Lexer::T_QUANTIFIER_OPEN)) { throw new ParserException('Nesting Quantifiers is not allowed'); } $tokens[] = $lexer->lookahead; } $max = $this->convertInteger($tokens); } else { $max = $min; } $head->setMaxOccurances($max); $head->setMinOccurances($min); # skip the lexer to the closing token $lexer->skipUntil(Lexer::T_QUANTIFIER_CLOSE); # check if the last matched token was the closing bracket # not going to stop errors like {#####,###{[a-z]} {#####{[a-z]} if(!$lexer->isNextToken(Lexer::T_QUANTIFIER_CLOSE)) { throw new ParserException('Closing quantifier token `}` not found'); } return $head; } /** * Convert a collection of Lexer::T_LITERAL_NUMERIC tokens into integer * * @access public * @return integer the size * @param array $tokens collection of tokens from lexer */ protected function convertInteger(array $tokens) { $number_string = array_map(function($item) { return $item['value']; }, $tokens); $number_string = trim(implode('',$number_string)); $value = preg_match('/^(0|(-{0,1}[1-9]\d*))$/', $number_string); if ($value == 0) { throw new ParserException('Quantifier expects and integer compitable string'); } return intval($number_string); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser/CharacterClass.php
src/ReverseRegex/Parser/CharacterClass.php
<?php namespace ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Generator\LiteralScope; use ReverseRegex\Lexer; use ReverseRegex\Exception as ParserException; use Patchwork\Utf8; /** * Parse a character class [0-9][a-z] * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class CharacterClass implements StrategyInterface { /** * Will return a normalized ie unicode sequences been evaluated. * * @return string a normalized character class string * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $set * @param Lexer $lexer the lexer to normalize */ public function normalize(Scope $head, Scope $set, Lexer $lexer) { $collection = array(); $unicode = new Unicode(); while($lexer->moveNext() && !$lexer->isNextToken(Lexer::T_SET_CLOSE)) { $value = null; switch(true) { case($lexer->isNextTokenAny(array(Lexer::T_SHORT_UNICODE_X, Lexer::T_SHORT_P,Lexer::T_SHORT_X))): $collection[] = $unicode->evaluate($lexer); break; case($lexer->isNextTokenAny(array(Lexer::T_LITERAL_CHAR, Lexer::T_LITERAL_NUMERIC))): $collection[] = $lexer->lookahead['value']; break; case($lexer->isNextToken(Lexer::T_SET_RANGE)): $collection[] = '-'; break; case($lexer->isNextToken(Lexer::T_ESCAPE_CHAR)): $collection[] = '\\'; break; default : throw new ParserException('Illegal meta character detected in character class'); } } /* if($lexer->lookahead['type'] === null) { throw new ParserException('Closing character set token not found'); } */ return '['. implode('',$collection) .']'; } /** * Parse the current token for new Quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $set * @param ReverseRegex\Lexer $lexer */ public function parse(Scope $head, Scope $set, Lexer $lexer) { if($lexer->lookahead['type'] !== Lexer::T_SET_OPEN) { throw new ParserException('Opening character set token not found'); } $peek = $lexer->glimpse(); if($peek['type'] === Lexer::T_SET_NEGATED) { throw new ParserException('Negated Character Set ranges not supported at this time'); } $normal_lexer = new Lexer($this->normalize($head,$set,$lexer)); while( $normal_lexer->moveNext() && !$normal_lexer->isNextToken(Lexer::T_SET_CLOSE)) { $glimpse = $normal_lexer->glimpse(); if($glimpse['type'] === Lexer::T_SET_RANGE) { continue; //value be included in range when `-` character is passed } switch(true) { case($normal_lexer->isNextToken(Lexer::T_SET_RANGE)) : $range_start = $normal_lexer->token['value']; $normal_lexer->moveNext(); if($normal_lexer->isNextToken(Lexer::T_ESCAPE_CHAR)) { $normal_lexer->moveNext(); } $range_end = $normal_lexer->lookahead['value']; $this->fillRange($head,$range_start,$range_end); break; case($normal_lexer->isNextToken(Lexer::T_LITERAL_NUMERIC) || $normal_lexer->isNextToken(Lexer::T_LITERAL_CHAR)) : $index = (integer)Utf8::ord($normal_lexer->lookahead['value']); $head->setLiteral($index,$normal_lexer->lookahead['value']); break; default: # ignore } } $head->getLiterals()->sort(); return $head; } /** * Fill a range given starting and ending character * * @return void * @access public */ public function fillRange(Scope $head,$start,$end) { $start_index = Utf8::ord($start); $ending_index = Utf8::ord($end); if($ending_index < $start_index ) { throw new ParserException(sprintf('Character class range %s - %s is out of order',$start,$end)); } for($i = $start_index; $i <= $ending_index; $i++) { $head->setLiteral($i,Utf8::chr($i)); } } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser/Unicode.php
src/ReverseRegex/Parser/Unicode.php
<?php namespace ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Lexer; use ReverseRegex\Exception as ParserException; use Patchwork\Utf8; /** * Parse a unicode sequence e.g \x54 \X{4444} * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Unicode implements StrategyInterface { /** * Parse the current token for new Quantifiers * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\LiteralScope $head * @param ReverseRegex\Generator\Scope $set * @param ReverseRegex\Lexer $lexer */ public function parse(Scope $head, Scope $set, Lexer $lexer) { $character = $this->evaluate($lexer); $head->addLiteral($character); return $head; } /** * Parse a reference */ public function evaluate(Lexer $lexer) { switch(true) { case ($lexer->isNextToken(Lexer::T_SHORT_P)) : throw new ParserException('Property \p (Unicode Property) not supported use \x to specify unicode character or range'); break; case ($lexer->isNextToken(Lexer::T_SHORT_UNICODE_X)) : $lexer->moveNext(); if($lexer->lookahead['value'] !== '{' ) { throw new ParserException('Expecting character { after \X none found'); } $tokens = array(); while($lexer->moveNext() && $lexer->lookahead !== null && $lexer->lookahead['value'] !== '}') { # check if we nested eg.{ddd{d} if($lexer->lookahead['value'] === '{') { throw new ParserException('Nesting hex value ranges is not allowed'); } if($lexer->lookahead['value'] !== " " && ctype_xdigit($lexer->lookahead['value']) === false) { throw new ParserException(sprintf('Character %s is not a hexdeciaml digit',$lexer->lookahead['value'])); } $tokens[] = $lexer->lookahead['value']; } # check that current lookahead is a closing character as it's possible to iterate to end of string (i.e. lookahead === null) if($lexer->lookahead === null || $lexer->lookahead['value'] !== '}') { throw new ParserException('Closing quantifier token `}` not found'); } if(count($tokens) === 0) { throw new ParserException('No hex number found inside the range'); } $number = trim(implode('',$tokens)); return Utf8::chr(hexdec($number)); break; case ($lexer->isNextToken(Lexer::T_SHORT_X)) : // only allow another 2 hex characters $glimpse = $lexer->glimpse(); if($glimpse['value'] === '{') { throw new ParserException('Braces not supported here'); } $tokens = array(); $count = 2; while($count > 0 && $lexer->moveNext()) { $tokens[] = $lexer->lookahead['value']; --$count; } $value = trim(implode('',$tokens)); return Utf8::chr(hexdec($value)); break; default : throw new ParserException('No Unicode expression to evaluate'); } } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Parser/StrategyInterface.php
src/ReverseRegex/Parser/StrategyInterface.php
<?php namespace ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Lexer; /** * Interface for all parser strategy object * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ interface StrategyInterface { /** * Parse the current token and return a new head * * @access public * @return ReverseRegex\Generator\Scope a new head * @param ReverseRegex\Generator\Scope $head * @param ReverseRegex\Generator\Scope $set * @param ReverseRegex\Lexer $lexer */ public function parse(Scope $head, Scope $set, Lexer $lexer); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Random/GeneratorInterface.php
src/ReverseRegex/Random/GeneratorInterface.php
<?php namespace ReverseRegex\Random; use PHPStats\Generator\GeneratorInterface as CommonInterface; /** * Interface that all generators should implement * * @access Lewis Dyer <getintouch@icomefromthenet.com> */ interface GeneratorInterface extends CommonInterface { /** * Generate a value between $min - $max * * @param integer $max * @param integer $max */ public function generate($min = 0,$max = null); /** * Set the seed to use * * @param $seed integer the seed to use * @access public */ public function seed($seed = null); /** * Return the hights possible random value * * @access public * @return double */ public function max(); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Random/SrandRandom.php
src/ReverseRegex/Random/SrandRandom.php
<?php namespace ReverseRegex\Random; use ReverseRegex\Exception as ReverseRegexException; /* * class SrandRandom * * Wrapper to mt_random with seed option * * Won't work when suhosin.srand.ignore = Off or suhosin.mt_srand.ignore = Off * is set. * * @author Lewis Dyer <getintouch@icomefromthenet.com> * */ class SrandRandom implements GeneratorInterface { /** * @var integer the seed to use on each pass */ protected $seed; /** * @var integer the max */ protected $max; /** * @var integer the min */ protected $min; /* * __construct() * * @param integer $seed the starting seed * @return void * @access public */ public function __construct($seed = 0) { $this->seed($seed); } /** * Return the maxium random number * * @access public * @return double */ public function max($value = null) { if($value === null && $this->max === null) { $max = getrandmax(); } elseif($value === null) { $max = $this->max; } else { $max = $this->max = $value; } return $max; } public function min($value = null) { if($value === null && $this->max === null) { $min = 0; } elseif($value === null) { $min = $this->min; } else { $min = $this->min = $value; } return $min; } /** * Generate a value between $min - $max * * @param integer $max * @param integer $max */ public function generate($min = 0,$max = null) { if($max === null) { $max = $this->max; } if($min === null) { $min = $this->min; } return rand($min,$max); } /** * Set the seed to use * * @param $seed integer the seed to use * @access public */ public function seed($seed = null) { $this->seed = $seed; srand($this->seed); return $this; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Random/SimpleRandom.php
src/ReverseRegex/Random/SimpleRandom.php
<?php namespace ReverseRegex\Random; use ReverseRegex\Exception as ReverseRegexException; /** * Simple Random * * @link http://www.sitepoint.com/php-random-number-generator/ * @author Craig Buckler */ class SimpleRandom implements GeneratorInterface { /** * @var integer the seed value to use */ protected $seed = 0; /** * @var integer the max */ protected $max; /** * @var integer the min */ protected $min; /** * Constructor * * @return void * @access public * @param integer $seed */ public function __construct($seed = null) { if ($seed === null || $seed === 0) { $this->seed(mt_rand()); } $this->seed($seed); } public function max($value = null) { if($value === null && $this->max === null) { $max = 2147483647; } elseif($value === null) { $max = $this->max; } else { $max = $this->max = $value; } return $max; } public function min($value = null) { if($value === null && $this->max === null) { $min = 0; } elseif($value === null) { $min = $this->min; } else { $min = $this->min = $value; } return $min; } /** * Set the seed to use for generator * * @param integer $seed the seed to use * @access public */ public function seed($seed = null) { if($seed === null) { $seed = 0; } return $this->seed = abs(intval($seed)) % 9999999 + 1; } /** * Generate a random numer * * @param integer $max * @param integer $max 2,796,203 largest possible max */ public function generate($min = 0, $max = null) { if($max === null) { $max = 2796203; } if($max > 2796203) { throw new ReverseRegexException('Max param has exceeded the maxium 2796203'); } if ($this->seed == 0) { $this->seed(mt_rand()); } $this->seed = ($this->seed * 125) % 2796203; return $this->seed % ($max - $min + 1) + $min; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Random/MersenneRandom.php
src/ReverseRegex/Random/MersenneRandom.php
<?php namespace ReverseRegex\Random; use ReverseRegex\Exception as ReverseRegexException; /** * Mersenne Twiseter Implementation * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @link http://boxrefuge.com/?tag=random-number */ class MersenneRandom implements GeneratorInterface { /** * @var integer a seed use count */ protected $index; /** * @var integer the seed value to use */ protected $seed; /** * @var integer previous seed value used */ protected $ps; /** * @var integer the max */ protected $max; /** * @var integer the min */ protected $min; public function __construct($seed = null) { $this->seed($seed); $this->index = -1; $this->ps = null; $this->max = null; $this->min = null; } public function max($value = null) { if($value === null && $this->max === null) { $max = 2147483647; } elseif($value === null) { $max = $this->max; } else { $max = $this->max = $value; } return $max; } public function min($value = null) { if($value === null && $this->max === null) { $min = 0; } elseif($value === null) { $min = $this->min; } else { $min = $this->min = $value; } return $min; } public function generate($min = 0,$max = null) { if($max === null) { $max = $this->max; } if($min === null) { $min = $this->min; } return abs($this->mt(++$this->index,$min,$max)); } public function seed($seed = null) { if($seed === null){ $seed = mt_rand(0,PHP_INT_MAX); } $this->seed = $seed; } /** * Mersenne Twister Random Number Generator * Returns a random number. Depending on the application, you likely don't have to reseed every time as you can simply select a different index * from the last seed and get a different number. * * Note: This has been tweaked for performance. It still generates the same numbers as the original algorithm but it's slightly more complicated * because it maintains both speed and elegance. Though not a crucial difference under normal use, on 1 million iterations, * re-seeding each time, it will save 5 minutes of time from the orginal algorithm - at least on my system. * * @param $index An index indicating the index of the internal array to select the number to generate the random number from * @param $min The minimum number to return * @param $max The maximum number to return * @return float the random number * @link http://boxrefuge.com/?tag=random-number * @author Justin unknown * **/ public function mt($index = null, $min = 0, $max = 1000) { static $op = array(0x0, 0x9908b0df); // Used for efficiency below to eliminate if statement static $mt = array(); // 624 element array used to get random numbers // Regenerate when reseeding or seeding initially if($this->seed !== $this->ps) { $s = $this->seed & 0xffffffff; $mt = array(&$s, 624 => &$s); $this->ps = $this->seed; for($i = 1; $i < 624; ++$i) $mt[$i] = (0x6c078965 * ($mt[$i - 1] ^ ($mt[$i - 1] >> 30)) + $i) & 0xffffffff; // This has been tweaked for maximum speed and elegance // Explanation of possibly confusing variables: // $p = previous index // $sp = split parts of array - the numbers at which to stop and continue on // $n = number to iterate to - we loop up to 227 adding 397 after which we finish looping up to 624 subtracting 227 to continue getting out 397 indices ahead reference // $m = 397 or -227 to add to $i to keep our 397 index difference // $i = the previous element in $sp, our starting index in this iteration for($j = 1, $sp = array(0, 227, 397); $j < count($sp); ++$j) { for($p = $j - 1, $i = $sp[$p], $m = ((624 - $sp[$j]) * ($p ? -1 : 1)), $n = ($sp[$j] + $sp[$p]); $i < $n; ++$i) { $y = ($mt[$i] & 0x80000000) | ($mt[$i + 1] & 0x7fffffff); $mt[$i] = $mt[$i + $m] ^ ($y >> 1) ^ $op[$y & 0x1]; } } } // Select a number from the array and randomize it $y = $mt[$this->index = $this->index % 624]; $y ^= $y >> 11; $y ^= ($y << 7) & 0x9d2c5680; $y ^= ($y << 15) & 0xefc60000; $y ^= $y >> 18; return $y % ($max - $min + 1) + $min; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Random/GeneratorFactory.php
src/ReverseRegex/Random/GeneratorFactory.php
<?php namespace ReverseRegex\Random; use ReverseRegex\Exception as ReverseRegexException; /** * Generator Factory * * @author Lewis Dyer <getintouch@icomefromthenet.com> */ class GeneratorFactory { /** * @var string[] list of Generators * * Each Generator must implement the ReverseRegex\RandomInterface */ protected static $types = array( 'srand' => '\\ReverseRegex\\Random\\SrandRandom', 'mersenne' => '\\ReverseRegex\\Random\\MersenneRandom', 'simple' => '\\ReverseRegex\\Random\\SimpleRandom', ); public static function registerExtension($index,$namespace) { $index = strtolower($index); return self::$types[$index] = $namespace; } public static function registerExtensions(array $extension) { foreach($extension as $key => $ns) { self::registerExtension($key,$ns); } } // ---------------------------------------------------------------------------- /** * Resolve a Dcotrine DataType Class * * @param string the random generator type name * @access public * @return ReverseRegex\RandomInterface * @throws PHPStats\Exception */ public function create($type,$seed = null) { $type = strtolower($type); # check extension list if(isset(self::$types[$type]) === true) { # assign platform the full namespace if(class_exists(self::$types[$type]) === false) { throw new ReverseRegexException('Unknown Generator at::'.$type); } $type = self::$types[$type]; } else { throw new ReverseRegexException('Unknown Generator at::'.$type); } return new $type($seed); } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/AlternateInterface.php
src/ReverseRegex/Generator/AlternateInterface.php
<?php namespace ReverseRegex\Generator; /** * Allows a scope to select children using alternating strategy * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ interface AlternateInterface { /** * Tell the scope to select childing use alternating strategy * * @access public * @return void */ public function useAlternatingStrategy(); /** * Return true if setting been activated * * @access public * @return boolean true */ public function usingAlternatingStrategy(); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/LiteralScope.php
src/ReverseRegex/Generator/LiteralScope.php
<?php namespace ReverseRegex\Generator; use ReverseRegex\Generator\Scope; use PHPStats\Generator\GeneratorInterface; use ReverseRegex\ArrayCollection; use ReverseRegex\Exception as GeneratorException; /** * Scope for Literal Values * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class LiteralScope extends Scope { /** * @var ReverseRegex\ArrayCollection container for literals values */ protected $literals; /** * Class Constructor * * @access public * @param string $label * @param Node $parent */ public function __construct($label = 'label') { parent::__construct($label); $this->literals = new ArrayCollection(); } /** * Adds a literal value to internal collection * * @access public * @param mixed $literal */ public function addLiteral($literal) { $this->literals->add($literal); } /** * Sets a value on the internal collection using a key * * @access public * @param string $hex a hexidecimal number * @param string $literal the literal to store */ public function setLiteral($hex,$literal) { $this->literals->set($hex,$literal); } /** * Return the literal ArrayCollection * * @access public * @return Doctrine\Common\Collections\ArrayCollection */ public function getLiterals() { return $this->literals; } /** * Generate a text string appending to the result argument * * @access public * @param string $result * @param GeneratorInterface $generator */ public function generate(&$result,GeneratorInterface $generator) { if($this->literals->count() === 0) { throw new GeneratorException('There are no literals to choose from'); } $repeat_x = $this->calculateRepeatQuota($generator); while($repeat_x > 0) { $randomIndex = 0; if($this->literals->count() > 1) { $randomIndex = \round($generator->generate(1,($this->literals->count()))); } $result .= $this->literals->getAt($randomIndex); --$repeat_x; } return $result; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/Node.php
src/ReverseRegex/Generator/Node.php
<?php namespace ReverseRegex\Generator; use \ArrayObject; use \SplObjectStorage; use \ArrayAccess; use \Countable; use \Iterator; /** * Base to all Generator Scopes * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Node implements ArrayAccess, Countable, Iterator { /** * @var string name of the node */ protected $label; /** * @var ArrayObject container for node metadata */ protected $attrs; /** * @var SplObjectStorage container for node relationships */ protected $links; /** * Class Constructor * * @access public * @param string $label */ public function __construct($label = 'node') { $this->attrs = new ArrayObject(); $this->links = new SplObjectStorage(); $this->setLabel($label); } /** * Fetch the nodes label * * @access public * @return string the nodes label */ public function getLabel() { return $this->label; } /** * Sets the node label * * @access public * @param string $label the nodes label */ public function setLabel($label) { if (!(is_scalar($label) || is_null($label))) { return false; } $this->label = $label; } /** * Attach a node * * @access public * @param Node $node the node to attach * @return Node */ public function &attach(Node $node) { $this->links->attach($node); return $this; } /** * Detach a node * * @access public * @return Node * @param Node $node the node to remove */ public function &detach(Node $node) { foreach ($this->links as $linked_node) { if ($linked_node == $node) { $this->links->detach($node); } } return $this; } /** * Search for node in its relations * * @access public * @return boolean true if found * @param Node $node the node to search for */ public function contains(Node $node) { foreach ($this->links as $linked_node) { if ($linked_node == $node) { return true; } } return false; } /** * Apply a closure to all relations * * @access public * @param Closer the function to apply */ public function map(Closure $function) { foreach ($this->links as $node) { $function($node); } } //------------------------------------------------------------------ # Countable public function count() { return count($this->links); } //------------------------------------------------------------------ # Iterator public function current() { return $this->links->current(); } public function key() { return $this->links->key(); } public function next() { return $this->links->next(); } public function rewind() { return $this->links->rewind(); } public function valid() { return $this->links->valid(); } //------------------------------------------------------------------ # ArrayAccess Implementation public function offsetGet($key) { return $this->attrs->offsetGet($key); } public function offsetSet($key, $value) { $this->attrs->offsetSet($key, $value); } public function offsetExists($key) { return $this->attrs->offsetExists($key); } public function offsetUnset($key) { return $this->attrs->offsetUnset($key); } } /* End of Class */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/Scope.php
src/ReverseRegex/Generator/Scope.php
<?php namespace ReverseRegex\Generator; use PHPStats\Generator\GeneratorInterface; use ReverseRegex\Exception as GeneratorException; /** * Base Class for Scopes * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ class Scope extends Node implements ContextInterface, RepeatInterface, AlternateInterface { const REPEAT_MIN_INDEX = 'repeat_min'; const REPEAT_MAX_INDEX = 'repeat_max'; const USE_ALTERNATING_INDEX = 'use_alternating'; /** * Class Constructor */ public function __construct($label = 'node') { parent::__construct($label); $this[self::USE_ALTERNATING_INDEX] = false; $this->setMinOccurances(1); $this->setMaxOccurances(1); } // ---------------------------------------------------------------------------- # Conext Interface /** * Generate a text string appending to result arguments * * @access public * @param string $result * @param GeneratorInterface $generator */ public function generate(&$result,GeneratorInterface $generator) { if($this->count() === 0) { throw new GeneratorException('No child scopes to call must be atleast 1'); } $repeat_x = $this->calculateRepeatQuota($generator); # rewind the current item $this->rewind(); while($repeat_x > 0) { if($this->usingAlternatingStrategy()) { $randomIndex = \round($generator->generate(1,($this->count()))); $this->get($randomIndex)->generate($result,$generator); } else { foreach($this as $current) { $current->generate($result,$generator); } } $repeat_x = $repeat_x -1; } return $result; } /** * Fetch a node given an `one-based index` * * @access public * @return Scope | null if none found */ public function get($index) { if($index > $this->count() || $index <= 0) { return null; } $this->rewind(); while(($index - 1) > 0) { $this->next(); $index = $index - 1; } return $this->current(); } // ---------------------------------------------------------------------------- # Repeat Interface /** * Fetches the max occurances * * @access public * @return integer the maximum number of occurances */ public function getMaxOccurances() { return $this[self::REPEAT_MAX_INDEX]; } /** * Sets the maximum re-occurances * * @access public * @param integer $num */ public function setMaxOccurances($num) { if(is_integer($num) === false){ throw new GeneratorException('Number must be an integer'); } $this[self::REPEAT_MAX_INDEX] = $num; } /** * Fetch the Minimum Occurances * * @access public * @return integer */ public function getMinOccurances() { return $this[self::REPEAT_MIN_INDEX]; } /** * Sets the Minimum number of re-occurances * * @access public * @param integer $num */ public function setMinOccurances($num) { if(is_integer($num) === false){ throw new GeneratorException('Number must be an integer'); } $this[self::REPEAT_MIN_INDEX] = $num; } /** * Return the occurance range * * @access public * @return integer the range */ public function getOccuranceRange() { return (integer)($this->getMaxOccurances() - $this->getMinOccurances()); } /** * Calculate a random numer of repeats given the current min-max range * * @access public * @param GeneratorInterface $generator * @return Integer */ public function calculateRepeatQuota(GeneratorInterface $generator) { $repeat_x = $this->getMinOccurances(); if($this->getOccuranceRange() > 0) { $repeat_x = (integer) \round($generator->generate($this->getMinOccurances(),$this->getMaxOccurances())); } return $repeat_x; } //------------------------------------------------------------------ # AlternateInterface /** * Tell the scope to select childing use alternating strategy * * @access public * @return void */ public function useAlternatingStrategy() { $this[self::USE_ALTERNATING_INDEX] = true; } /** * Return true if setting been activated * * @access public * @return boolean true */ public function usingAlternatingStrategy() { return (boolean) $this[self::USE_ALTERNATING_INDEX]; } } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/RepeatInterface.php
src/ReverseRegex/Generator/RepeatInterface.php
<?php namespace ReverseRegex\Generator; /** * Represent a group has max and min number of occurances * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ interface RepeatInterface { /** * Fetches the max re-occurances * * @access public * @return integer the maximum number of occurances */ public function getMaxOccurances(); /** * Sets the maximum re-occurances * * @access public * @param integer $num */ public function setMaxOccurances($num); /** * Fetch the Minimum re-occurances * * @access public * @return integer */ public function getMinOccurances(); /** * Sets the Minimum number of re-occurances * * @access public * @param integer $num */ public function setMinOccurances($num); /** * Return the occurance range * * @access public * @return integer the range */ public function getOccuranceRange(); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/ReverseRegex/Generator/ContextInterface.php
src/ReverseRegex/Generator/ContextInterface.php
<?php namespace ReverseRegex\Generator; use PHPStats\Generator\GeneratorInterface; /** * Conext interface for Generator * * @author Lewis Dyer <getintouch@icomefromthenet.com> * @since 0.0.1 */ interface ContextInterface { /** * Generate a text string appending to result arguments * * @access public * @param string $result * @param GeneratorInterface $generator */ public function generate(&$result,GeneratorInterface $generator); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/src/PHPStats/Generator/GeneratorInterface.php
src/PHPStats/Generator/GeneratorInterface.php
<?php namespace PHPStats\Generator; /** * Interface that all generators should implement * * @access Lewis Dyer <getintouch@icomefromthenet.com> */ interface GeneratorInterface { /** * Generate a value between $min - $max * * @param integer $max * @param integer $max */ public function generate($min = 0,$max = null); /** * Set the seed to use * * @param $seed integer the seed to use * @access public */ public function seed($seed = null); /** * Return the hights possible random value * * @access public * @return double */ public function max(); } /* End of File */
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/examples/ausphone.php
examples/ausphone.php
<?php use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; # require composer require '../vendor/autoload.php'; # parse the regex $lexer = new Lexer('\(0[23478]\) 9[0-9]{3}-[0-9]{4}'); $parser = new Parser($lexer,new Scope(),new Scope()); $generator = $parser->parse()->getResult(); # run the generator $random = new MersenneRandom(777); for($i = 20; $i > 0; $i--) { $result = ''; $generator->generate($result,$random); echo $result; echo PHP_EOL; }
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/examples/mobilenumbers.php
examples/mobilenumbers.php
<?php use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; # require composer require '../vendor/autoload.php'; # parse the regex $lexer = new Lexer("6104([01]\d{3}|(2[1-9]|3[0-57-9]|4[7-9]|5[0-35-9]|6[679]|7[078]|8[178]|9[7-9])\d{2}|(20[2-9]|444|68[3-9]|79[01]|820|901)\d|(200[01]|2010|8984))\d{4}"); $parser = new Parser($lexer,new Scope(),new Scope()); $generator = $parser->parse()->getResult(); # run the generator $random = new MersenneRandom(777); for($i = 50; $i > 0; $i--) { $result = ''; $generator->generate($result,$random); echo $result; echo PHP_EOL; }
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/examples/auspostcode.php
examples/auspostcode.php
<?php use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; # require composer require '../vendor/autoload.php'; # parse the regex $lexer = new Lexer("(0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2})"); $parser = new Parser($lexer,new Scope(),new Scope()); $generator = $parser->parse()->getResult(); # run the generator $random = new MersenneRandom(777); for($i = 20; $i > 0; $i--) { $result = ''; $generator->generate($result,$random); echo $result; echo PHP_EOL; }
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
icomefromthenet/ReverseRegex
https://github.com/icomefromthenet/ReverseRegex/blob/2d93f783505194ce520a179e1771a0328511530d/examples/simple.php
examples/simple.php
<?php use ReverseRegex\Lexer; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; use ReverseRegex\Random\MersenneRandom; # require composer require '../vendor/autoload.php'; # parse the regex $lexer = new Lexer("[a-z]{10}"); $parser = new Parser($lexer,new Scope(),new Scope()); $generator = $parser->parse()->getResult(); # run the generator $random = new MersenneRandom(777); for($i = 50; $i > 0; $i--) { $result = ''; $generator->generate($result,$random); echo $result; echo PHP_EOL; }
php
MIT
2d93f783505194ce520a179e1771a0328511530d
2026-01-05T05:00:26.761859Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/RajaOngkir.php
src/RajaOngkir.php
<?php namespace Kavist\RajaOngkir; use Kavist\RajaOngkir\Contracts\HttpClientContract; use Kavist\RajaOngkir\Contracts\SearchDriverContract; use Kavist\RajaOngkir\HttpClients\AbstractClient; use Kavist\RajaOngkir\HttpClients\BasicClient; use Kavist\RajaOngkir\Resources\Kota; use Kavist\RajaOngkir\Resources\OngkosKirim; use Kavist\RajaOngkir\Resources\Provinsi; use Kavist\RajaOngkir\SearchDrivers\AbstractDriver; use Kavist\RajaOngkir\SearchDrivers\BasicDriver; class RajaOngkir { /** @var \Kavist\RajaOngkir\Contracts\HttpClientContract */ protected $httpClient; /** @var \Kavist\RajaOngkir\Contracts\SearchDriverContract */ protected $searchDriver; /** @var array */ protected $options; /** @var string */ private $apiKey; /** @var string */ private $package; /** * @param string $apiKey * @param string $package */ public function __construct(string $apiKey, string $package = 'starter') { $this->apiKey = $apiKey; $this->package = $package; $this->setHttpClient(new BasicClient); } /** * @param \Kavist\RajaOngkir\Contracts\HttpClientContract $httpClient * @return self */ public function setHttpClient(HttpClientContract $httpClient): self { $this->httpClient = $httpClient; $this->httpClient->setApiKey($this->apiKey); $this->httpClient->setPackage($this->package); return $this; } /** * @param \Kavist\RajaOngkir\Contracts\SearchDriverContract $searchDriver * @return self */ public function setSearchDriver(SearchDriverContract $searchDriver): self { $this->searchDriver = $searchDriver; return $this; } /** * @return \Kavist\RajaOngkir\Resources\Provinsi; */ public function provinsi(): Provinsi { $resource = new Provinsi($this->httpClient); if (null === $this->searchDriver) { $resource->setSearchDriver(new BasicDriver); $resource->setSearchColumn(); } return $resource; } /** * @return \Kavist\RajaOngkir\Resources\Kota; */ public function kota(): Kota { $resource = new Kota($this->httpClient); if (null === $this->searchDriver) { $resource->setSearchDriver(new BasicDriver); $resource->setSearchColumn(); } return $resource; } /** * @param array $payload * @return \Kavist\RajaOngkir\Resources\OngkosKirim; */ public function ongkosKirim(array $payload): OngkosKirim { return new OngkosKirim($this->httpClient, $payload); } /** * @return \Kavist\RajaOngkir\Resources\OngkosKirim; */ public function ongkir(array $payload): OngkosKirim { return $this->ongkosKirim($payload); } /** * @return \Kavist\RajaOngkir\Resources\OngkosKirim; */ public function biaya(array $payload): OngkosKirim { return $this->ongkosKirim($payload); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Exceptions/BasicHttpClientException.php
src/Exceptions/BasicHttpClientException.php
<?php namespace Kavist\RajaOngkir\Exceptions; class BasicHttpClientException extends \Exception { // }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Exceptions/ApiResponseException.php
src/Exceptions/ApiResponseException.php
<?php namespace Kavist\RajaOngkir\Exceptions; class ApiResponseException extends \Exception { // }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Exceptions/InvalidConfigurationException.php
src/Exceptions/InvalidConfigurationException.php
<?php namespace Kavist\RajaOngkir\Exceptions; class InvalidConfigurationException extends \Exception { public static function apiKeyNotSpecified() { return new static('API key untuk RajaOngkir belum diatur.'); } public static function invalidApiPackage() { return new static('Tipe akun RajaOngkir yang diatur tidak sesuai. Pilih salah satu: starter, basic, pro.'); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/HttpClients/BasicClient.php
src/HttpClients/BasicClient.php
<?php namespace Kavist\RajaOngkir\HttpClients; use EngineException; use Kavist\RajaOngkir\Exceptions\ApiResponseException; use Kavist\RajaOngkir\Exceptions\BasicHttpClientException; class BasicClient extends AbstractClient { /** @var resource */ protected $context; /** @var array */ protected $contextOptions = [ 'max_redirects' => 5, 'timeout' => 30, 'protocol_version' => 1.1, 'method' => 'GET', ]; public function request(array $payload = []): array { $contextOptions = [ 'method' => $this->httpMethod, 'header' => $this->buildHttpHeaders(), ]; if ('POST' === $this->httpMethod) { $contextOptions['content'] = http_build_query($payload); } $this->initialize($contextOptions); return $this->executeRequest($this->buildUrl($payload)); } protected function initialize(array $contextOptions = []) { $this->context = stream_context_create([ 'http' => array_merge($this->contextOptions, $contextOptions), ]); } protected function buildUrl(array $payload = []): string { $url = parent::buildUrl(); if ('GET' === $this->httpMethod) { $url .= '?'.http_build_query($payload); } return $url; } private function buildHttpHeaders(): string { $headers = $this->httpHeaders; if ('POST' === $this->httpMethod) { $headers += ['Content-Type' => 'application/x-www-form-urlencoded']; } foreach ($headers as $headerKey => $headerValue) { $headers[$headerKey] = $headerKey.':'.$headerValue."\r\n"; } return implode($headers); } private function executeRequest(string $url): array { set_error_handler(function ($severity, $message) { throw new BasicHttpClientException('Client Error: '.$message, $severity); }); $rawResponse = file_get_contents($url, false, $this->context); restore_error_handler(); $this->stopIfClientReturnsError($rawResponse); $response = json_decode($rawResponse, true)['rajaongkir']; $this->stopIfApiReturnsError($response['status']); return $response['results']; } private function stopIfClientReturnsError($status) { if (false === $status) { throw new BasicHttpClientException('Client Error'); } } private function stopIfApiReturnsError(array $status) { if (400 == $status['code']) { throw new ApiResponseException('RajaOngkir API Error: '.$status['description']); } } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/HttpClients/AbstractClient.php
src/HttpClients/AbstractClient.php
<?php namespace Kavist\RajaOngkir\HttpClients; use Kavist\RajaOngkir\Contracts\HttpClientContract; abstract class AbstractClient implements HttpClientContract { /** @var array */ protected $apiUrls = [ 'starter' => 'https://api.rajaongkir.com/starter', 'basic' => 'https://api.rajaongkir.com/basic', 'pro' => 'https://pro.rajaongkir.com/api', ]; /** @var string */ protected $apiUrl; /** @var string */ protected $entity; /** @var array */ protected $httpHeaders; /** @var string */ protected $httpMethod; /** * @param string $apiKey * @return self */ public function setApiKey(string $apiKey) { $this->httpHeaders['Key'] = $apiKey; return $this; } /** * @param string $package * @return self */ public function setPackage(string $package) { $this->apiUrl = $this->apiUrls[$package]; return $this; } /** * @param string $entity * @return self */ public function setEntity(string $entity) { $this->entity = $entity; return $this; } /** * @param string $httpMethod * @return self */ public function setHttpMethod(string $httpMethod) { $this->httpMethod = $httpMethod; return $this; } /** * @param string $entity * @return string */ protected function buildUrl(): string { return $this->apiUrl.'/'.$this->entity; } /** * @param array $payload * @return array */ abstract public function request(array $payload = []): array; }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/SearchDrivers/BasicDriver.php
src/SearchDrivers/BasicDriver.php
<?php namespace Kavist\RajaOngkir\SearchDrivers; class BasicDriver extends AbstractDriver { /** * @param string $searchQuery * @return array */ public function search(string $searchQuery): array { $result = []; $q = trim(strtolower($searchQuery)); $rowColumn = array_column($this->collection, $this->searchColumn); $data = array_map('strtolower', $rowColumn); $cari = preg_quote($q, '/'); $res = preg_grep('/'.$cari.'/', $data); $resKey = array_keys($res); foreach ($this->collection as $key => $val) { if (in_array($key, $resKey)) { $result[] = $val; } } return $result; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/SearchDrivers/AbstractDriver.php
src/SearchDrivers/AbstractDriver.php
<?php namespace Kavist\RajaOngkir\SearchDrivers; use Kavist\RajaOngkir\Contracts\SearchDriverContract; abstract class AbstractDriver implements SearchDriverContract { /** @var array */ protected $collection; /** @var string */ protected $searchColumn; /** * @param string $searchColumn * @return self */ public function setSearchColumn(string $searchColumn) { $this->searchColumn = $searchColumn; return $this; } /** * @param array $collection * @return self */ public function setData(array $collection) { $this->collection = $collection; return $this; } /** * @param string $searchQuery * @return array */ abstract public function search(string $searchQuery): array; }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Contracts/LocationResourceContract.php
src/Contracts/LocationResourceContract.php
<?php namespace Kavist\RajaOngkir\Contracts; interface LocationResourceContract { /** * @param \Kavist\RajaOngkir\Contracts\SearchDriverContract $searchDriver * @return self */ public function setSearchDriver(SearchDriverContract $searchDriver); /** * @return self */ public function setSearchColumn(); /** * @return array */ public function all(): array; /** * @param int|string $id * @return array */ public function find($id): array; /** * @return array */ public function get(): array; /** * @param string $searchTerm * @return self */ public function search(string $searchTerm); }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Contracts/SearchDriverContract.php
src/Contracts/SearchDriverContract.php
<?php namespace Kavist\RajaOngkir\Contracts; interface SearchDriverContract { /** * @param string $searchColumn * @return self */ public function setSearchColumn(string $searchColumn); /** * @param array $collection * @return self */ public function setData(array $collection); /** * @param string $searchQuery * @return array */ public function search(string $searchQuery): array; }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Contracts/HttpClientContract.php
src/Contracts/HttpClientContract.php
<?php namespace Kavist\RajaOngkir\Contracts; interface HttpClientContract { /** * @param string $apiKey * @return self */ public function setApiKey(string $apiKey); /** * @param string $package * @return self */ public function setPackage(string $package); /** * @param string $entity * @return self */ public function setEntity(string $entity); /** * @param string $httpMethod * @return self */ public function setHttpMethod(string $httpMethod); /** * @param array $payload * @return array */ public function request(array $payload = []): array; }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Facades/RajaOngkir.php
src/Facades/RajaOngkir.php
<?php namespace Kavist\RajaOngkir\Facades; use Illuminate\Support\Facades\Facade; class RajaOngkir extends Facade { protected static function getFacadeAccessor() { return 'rajaongkir'; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Resources/AbstractResource.php
src/Resources/AbstractResource.php
<?php namespace Kavist\RajaOngkir\Resources; abstract class AbstractResource { /** @var array */ protected $result = []; /** @var \Kavist\RajaOngkir\HttpClients\AbstractClient */ protected $httpClient; public function get(): array { return $this->result; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Resources/AbstractLocation.php
src/Resources/AbstractLocation.php
<?php namespace Kavist\RajaOngkir\Resources; use Kavist\RajaOngkir\Contracts\LocationResourceContract; use Kavist\RajaOngkir\Contracts\SearchDriverContract; abstract class AbstractLocation extends AbstractResource implements LocationResourceContract { /** @var \Kavist\RajaOngkir\Contracts\SearchDriverContract */ protected $searchDriver; /** * @param \Kavist\RajaOngkir\Contracts\SearchDriverContract $searchDriver * @return self */ public function setSearchDriver(SearchDriverContract $searchDriver) { $this->searchDriver = $searchDriver; return $this; } /** * @return self */ abstract public function setSearchColumn(); /** * @return array */ public function all(): array { return $this->httpClient->request(); } /** * @param int|string $id * @return array */ public function find($id): array { return $this->httpClient->request(compact('id')); } /** * @param string $searchTerm * @return self */ public function search(string $searchTerm) { if (empty($this->result)) { $this->result = $this->all(); } $this->result = $this->searchDriver->setData($this->result)->search($searchTerm); return $this; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Resources/Kota.php
src/Resources/Kota.php
<?php namespace Kavist\RajaOngkir\Resources; use Kavist\RajaOngkir\HttpClients\AbstractClient; class Kota extends AbstractLocation { /** * @param \Kavist\RajaOngkir\HttpClients\AbstractClient $httpClient */ public function __construct(AbstractClient $httpClient) { $this->httpClient = $httpClient; $this->httpClient->setEntity('city'); $this->httpClient->setHttpMethod('GET'); } /** * @return self */ public function setSearchColumn() { $this->searchDriver->setSearchColumn('city_name'); return $this; } /** * @param int|string $provinceId * @return self */ public function dariProvinsi($provinceId): self { $this->result = $this->httpClient->request(['province' => $provinceId]); return $this; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Resources/OngkosKirim.php
src/Resources/OngkosKirim.php
<?php namespace Kavist\RajaOngkir\Resources; use Kavist\RajaOngkir\HttpClients\AbstractClient; class OngkosKirim extends AbstractResource { /** * @param \Kavist\RajaOngkir\HttpClients\AbstractClient $httpClient */ public function __construct(AbstractClient $httpClient, array $payload) { $this->httpClient = $httpClient; $this->httpClient->setEntity('cost'); $this->httpClient->setHttpMethod('POST'); $this->callRequest($payload); } private function callRequest(array $payload) { $this->result = $this->httpClient->request($payload); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Resources/Provinsi.php
src/Resources/Provinsi.php
<?php namespace Kavist\RajaOngkir\Resources; use Kavist\RajaOngkir\HttpClients\AbstractClient; class Provinsi extends AbstractLocation { /** * @param \Kavist\RajaOngkir\HttpClients\AbstractClient $httpClient */ public function __construct(AbstractClient $httpClient) { $this->httpClient = $httpClient; $this->httpClient->setEntity('province'); $this->httpClient->setHttpMethod('GET'); } /** * @return self */ public function setSearchColumn() { $this->searchDriver->setSearchColumn('province'); return $this; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/src/Providers/LaravelServiceProvider.php
src/Providers/LaravelServiceProvider.php
<?php namespace Kavist\RajaOngkir\Providers; use Illuminate\Support\ServiceProvider; use Kavist\RajaOngkir\Exceptions\InvalidConfigurationException; use Kavist\RajaOngkir\HttpClients\BasicClient; use Kavist\RajaOngkir\RajaOngkir; use Kavist\RajaOngkir\SearchDrivers\BasicDriver; class LaravelServiceProvider extends ServiceProvider { /** * @return void */ public function boot() { $this->publishes([ __DIR__.'/../../config/rajaongkir.php' => config_path('rajaongkir.php'), ]); } /** * @return void */ public function register() { $this->mergeConfigFrom(__DIR__.'/../../config/rajaongkir.php', 'rajaongkir'); $this->app->bind(BasicClient::class, function () { return new BasicClient; }); $this->app->bind(BasicDriver::class, function () { return new BasicDriver; }); $this->app->bind(RajaOngkir::class, function () { $config = config('rajaongkir'); $this->guardAgainstInvalidConfiguration($config); return new RajaOngkir($config['api_key'], $config['package']); }); $this->app->alias(RajaOngkir::class, 'rajaongkir'); } protected function guardAgainstInvalidConfiguration(array $config = null) { if (empty($config['api_key'] || 'some32charstring' === $config['api_key'])) { throw InvalidConfigurationException::apiKeyNotSpecified(); } if (! in_array($config['package'], ['starter', 'basic', 'pro'])) { throw InvalidConfigurationException::invalidApiPackage(); } } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/tests/Integration/RajaOngkirServiceProviderTest.php
tests/Integration/RajaOngkirServiceProviderTest.php
<?php namespace Kavist\RajaOngkir\Tests\Integration; use Kavist\RajaOngkir\Exceptions\BasicHttpClientException; use Kavist\RajaOngkir\Exceptions\InvalidConfigurationException; use Kavist\RajaOngkir\Facades\RajaOngkir; class RajaOngkirServiceProviderTest extends TestCase { /** @test */ public function it_has_config_file() { $this->assertTrue(is_array(config('rajaongkir'))); } /** @test */ public function it_will_throw_an_exception_if_the_api_key_is_not_set() { $this->app['config']->set('rajaongkir.api_key', ''); $this->expectException(InvalidConfigurationException::class); RajaOngkir::provinsi()->all(); } /** @test */ public function it_will_throw_an_exception_if_the_api_key_is_incorrect() { $this->app['config']->set('rajaongkir.api_key', 'wrongapikey'); $this->expectException(BasicHttpClientException::class); RajaOngkir::provinsi()->all(); } /** @test */ public function it_will_throw_an_exception_if_the_package_is_incorrect() { $this->app['config']->set('rajaongkir.package', 'a'); $this->expectException(InvalidConfigurationException::class); RajaOngkir::provinsi()->all(); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/tests/Integration/TestCase.php
tests/Integration/TestCase.php
<?php namespace Kavist\RajaOngkir\Tests\Integration; use Kavist\RajaOngkir\Facades\RajaOngkir; use Kavist\RajaOngkir\Providers\LaravelServiceProvider as RajaOngkirServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; abstract class TestCase extends Orchestra { public function setUp(): void { parent::setUp(); } protected function getPackageProviders($app): array { return [ RajaOngkirServiceProvider::class, ]; } protected function getPackageAliases($app): array { return [ 'RajaOngkir' => RajaOngkir::class, ]; } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/tests/Unit/TestCase.php
tests/Unit/TestCase.php
<?php namespace Kavist\RajaOngkir\Tests\Unit; use Faker\Factory as FakerFactory; use Faker\Generator as FakerGenerator; use Kavist\RajaOngkir\Contracts\HttpClientContract; use Kavist\RajaOngkir\Contracts\SearchDriverContract; use Kavist\RajaOngkir\HttpClients\BasicClient; use Kavist\RajaOngkir\RajaOngkir; use Kavist\RajaOngkir\SearchDrivers\BasicDriver; use Kavist\RajaOngkir\SearchDrivers\FuseDriver; use Mockery; use PHPUnit\Framework\TestCase as PHPUnitTestCase; class TestCase extends PHPUnitTestCase { /** @var \Kavist\RajaOngkir\Contracts\HttpClientContract|\Mockery\Mock */ protected $httpClient; /** @var \Kavist\RajaOngkir\Contracts\SearchDriverContract|\Mockery\Mock */ protected $searchDriver; /** @var \Kavist\RajaOngkir\RajaOngkir */ protected $rajaOngkir; public function setUp(): void { $this->httpClient = Mockery::mock(BasicClient::class, HttpClientContract::class) ->shouldIgnoreMissing(); $this->searchDriver = Mockery::mock(BasicDriver::class, SearchDriverContract::class) ->shouldIgnoreMissing(); $this->betterSearchDriver = Mockery::mock(FuseDriver::class, SearchDriverContract::class) ->shouldIgnoreMissing(); $this->rajaOngkir = new RajaOngkir('d41d8cd98f00b204e9800998ecf8427e', 'starter'); $this->rajaOngkir->setHttpClient($this->httpClient); } public function tearDown(): void { Mockery::close(); } protected function mock(string $resourceName, int $id = null) { $mockdata = __DIR__.'/../mockdata/'.$resourceName.'.json'; $data = json_decode(file_get_contents($mockdata), true); if (! null === $id) { foreach ($data as $row) { if ($row[$resourceName.'_id'] == $id) { return $row; } } } return $data; } /** * @param string $resourceName * @param int $repeat * @param bool $strict * @return array */ protected function fake(string $resourceName, int $repeat = 1): array { $faker = FakerFactory::create(); $result = []; if (in_array($resourceName, ['ongkosKirim'])) { $result[] = $this->{'generate'.ucwords($resourceName)}($faker, $repeat); } return count($result) > 1 ? $result : $result[0]; } protected function generateOngkosKirim(FakerGenerator $faker, int $repeat = 1): array { $code = $faker->word(1, true); $name = $faker->word(3); $costs = []; for ($i = 0; $i < $repeat; $i++) { $costs[] = [ 'service' => $faker->word(1, true), 'description' => $faker->sentence, 'cost' => [ 'value' => $faker->numberBetween(5, 55) * 1000, 'etd' => $faker->numerify('#-#'), 'note' => '', ], ]; } return compact('code', 'name', 'costs'); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/tests/Unit/RajaOngkirTest.php
tests/Unit/RajaOngkirTest.php
<?php namespace Kavist\RajaOngkir\Tests\Unit; class RajaOngkirTest extends TestCase { /** @var int */ private $provinceId = 5; /** @var int */ private $cityId = 80; /** @var string */ private $provinceSearchTerm = 'ja t'; /** @var string */ private $citySearchTerm = 'su'; /** @test */ public function it_can_fetch_provinces() { $mock = $this->mock('provinsi'); $this->httpClient ->expects()->request() ->andReturn($mock); $response = $this->rajaOngkir->provinsi()->all(); $this->assertEquals($mock, $response); } /** @test */ public function it_can_fetch_province_by_id() { $mock = $this->mock('provinsi', $this->provinceId); $this->httpClient ->expects()->request(['id' => $this->provinceId]) ->andReturn($mock); $response = $this->rajaOngkir->provinsi()->find($this->provinceId); $this->assertEquals($mock, $response); } /** @test */ public function it_can_search_provinces_by_name() { $mock = $this->mock('provinsi'); $expectedSearchResult = [ ['province_id' => '10', 'province' => 'Jawa Tengah'], ['province_id' => '11', 'province' => 'Jawa Timur'], ]; $this->httpClient ->expects()->request() ->andReturn($mock); $response = $this->rajaOngkir->provinsi()->search($this->provinceSearchTerm)->get(); $this->assertEquals($expectedSearchResult, $response); } /** @test */ public function it_can_fetch_cities() { $mock = $this->mock('kota'); $this->httpClient ->expects()->request() ->andReturn($mock); $response = $this->rajaOngkir->kota()->all(); $this->assertEquals($mock, $response); } /** @test */ public function it_can_fetch_city_by_id() { $mock = $this->mock('kota', $this->cityId); $this->httpClient ->expects()->request(['id' => $this->cityId]) ->andReturn($mock); $response = $this->rajaOngkir->kota()->find($this->cityId); $this->assertEquals($mock, $response); } /** @test */ public function it_can_fetch_cities_by_its_province() { $mock = $this->mock('kota', $this->cityId); $this->httpClient ->expects()->request(['province' => $this->provinceId]) ->andReturn($mock); $response = $this->rajaOngkir->kota()->dariProvinsi($this->provinceId)->get(); $this->assertEquals($mock, $response); } /** @test */ public function it_can_search_cities_by_name() { $mock = $this->mock('kota'); $expectedSearchResult = [ [ 'city_id' => '441', 'province_id' => '11', 'province' => 'Jawa Timur', 'type' => 'Kabupaten', 'city_name' => 'Sumenep', 'postal_code' => '69413', ], [ 'city_id' => '444', 'province_id' => '11', 'province' => 'Jawa Timur', 'type' => 'Kota', 'city_name' => 'Surabaya', 'postal_code' => '60119', ], ]; $this->httpClient ->expects()->request() ->andReturn($mock); $response = $this->rajaOngkir->kota()->search($this->citySearchTerm)->get(); $this->assertEquals($expectedSearchResult, $response); } /** @test */ public function it_can_fetch_delivery_cost() { $fake = $this->fake('ongkosKirim', 3); $expectedArguments = [ 'origin' => 42, 'destination' => 43, 'weight' => 1325, 'courier' => 'jne', ]; $this->httpClient ->expects()->request($expectedArguments) ->andReturn($fake); $response = $this->rajaOngkir->ongkosKirim($expectedArguments)->get(); $this->assertEquals($fake, $response); } }
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
kavist/rajaongkir
https://github.com/kavist/rajaongkir/blob/a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e/config/rajaongkir.php
config/rajaongkir.php
<?php return [ /* * Atur API key yang dibutuhkan untuk mengakses API Raja Ongkir. * Dapatkan API key dengan mengakses halaman panel akun Anda. */ 'api_key' => env('RAJAONGKIR_API_KEY', 'some32charstring'), /* * Atur tipe akun sesuai paket API yang Anda pilih di Raja Ongkir. * Pilihan yang tersedia: ['starter', 'basic', 'pro']. */ 'package' => env('RAJAONGKIR_PACKAGE', 'starter'), ];
php
MIT
a5f33e0e8c2b7c08fb11663c7ed8138d6d923a8e
2026-01-05T05:00:41.098726Z
false
wenpeng/curl
https://github.com/wenpeng/curl/blob/78b84dfd3fb958a38e143cb655399ca4a34e62e9/src/Curl.php
src/Curl.php
<?php /** * Author: Wenpeng * Email: imwwp@outlook.com * Version: 1.0.0 * * https://github.com/wenpeng/curl * 一个轻量级的网络操作类,实现GET、POST、UPLOAD、DOWNLOAD常用操作,支持链式写法。 */ namespace Wenpeng\Curl; use Exception; class Curl { private $post; private $retry = 0; private $custom = array(); private $option = array( 'CURLOPT_HEADER' => 0, 'CURLOPT_TIMEOUT' => 30, 'CURLOPT_ENCODING' => '', 'CURLOPT_IPRESOLVE' => 1, 'CURLOPT_RETURNTRANSFER' => true, 'CURLOPT_SSL_VERIFYPEER' => false, 'CURLOPT_CONNECTTIMEOUT' => 10, ); private $info; private $data; private $error; private $message; private static $instance; /** * Instance * @return self */ public static function init() { if (self::$instance === null) { self::$instance = new self; } return self::$instance; } /** * Task info * * @return array */ public function info() { return $this->info; } /** * Result Data * * @return string */ public function data() { return $this->data; } /** * Error status * * @return integer */ public function error() { return $this->error; } /** * Error message * * @return string */ public function message() { return $this->message; } /** * Set POST data * @param array|string $data * @param null|string $value * @return self */ public function post($data, $value = null) { if (is_array($data)) { foreach ($data as $key => $val) { $this->post[$key] = $val; } } else { if ($value === null) { $this->post = $data; } else { $this->post[$data] = $value; } } return $this; } /** * File upload * @param string $field * @param string $path * @param string $type * @param string $name * @return self */ public function file($field, $path, $type, $name) { $name = basename($name); if (class_exists('CURLFile')) { $this->set('CURLOPT_SAFE_UPLOAD', true); $file = curl_file_create($path, $type, $name); } else { $file = "@{$path};type={$type};filename={$name}"; } return $this->post($field, $file); } /** * Save file * @param string $path * @return self * @throws Exception */ public function save($path) { if ($this->error) { throw new Exception($this->message, $this->error); } $fp = @fopen($path, 'w'); if ($fp === false) { throw new Exception('Failed to save the content', 500); } fwrite($fp, $this->data); fclose($fp); return $this; } /** * Request URL * @param string $url * @return self * @throws Exception */ public function url($url) { if (filter_var($url, FILTER_VALIDATE_URL)) { return $this->set('CURLOPT_URL', $url)->process(); } throw new Exception('Target URL is required.', 500); } /** * Set option * @param array|string $item * @param null|string $value * @return self */ public function set($item, $value = null) { if (is_array($item)) { foreach($item as $key => $val){ $this->custom[$key] = $val; } } else { $this->custom[$item] = $value; } return $this; } /** * Set retry times * @param int $times * @return self */ public function retry($times = 0) { $this->retry = $times; return $this; } /** * Task process * @param int $retry * @return self */ private function process($retry = 0) { $ch = curl_init(); $option = array_merge($this->option, $this->custom); foreach($option as $key => $val) { if (is_string($key)) { $key = constant(strtoupper($key)); } curl_setopt($ch, $key, $val); } if ($this->post) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $this->convert($this->post)); } $this->data = (string) curl_exec($ch); $this->info = curl_getinfo($ch); $this->error = curl_errno($ch); $this->message = $this->error ? curl_error($ch) : ''; curl_close($ch); if ($this->error && $retry < $this->retry) { $this->process($retry + 1); } $this->post = array(); $this->retry = 0; return $this; } /** * Convert array * @param array $input * @param string $pre * @return array */ private function convert($input, $pre = null){ if (is_array($input)) { $output = array(); foreach ($input as $key => $value) { $index = is_null($pre) ? $key : "{$pre}[{$key}]"; if (is_array($value)) { $output = array_merge($output, $this->convert($value, $index)); } else { $output[$index] = $value; } } return $output; } return $input; } }
php
MIT
78b84dfd3fb958a38e143cb655399ca4a34e62e9
2026-01-05T05:00:48.744155Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/NovaPermissions.php
src/NovaPermissions.php
<?php namespace Pktharindu\NovaPermissions; use Illuminate\Http\Request; use Laravel\Nova\Nova; use Laravel\Nova\Tool; use Pktharindu\NovaPermissions\Nova\Role; class NovaPermissions extends Tool { protected $roleResource = Role::class; private $customRole = false; /** * Perform any tasks that need to happen when the tool is booted. */ public function boot() { Nova::script('NovaPermissions', __DIR__.'/../dist/js/tool.js'); if (! $this->customRole) { Nova::resources([ $this->roleResource, ]); } } /** * @param string $roleResource * * @return mixed */ public function roleResource(string $roleResource) { $this->customRole = true; $this->roleResource = $roleResource; return $this; } public function menu(Request $request) { return null; } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/Role.php
src/Role.php
<?php namespace Pktharindu\NovaPermissions; use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Model; use Pktharindu\NovaPermissions\Policies\Policy; class Role extends Model { protected $fillable = [ 'slug', 'name', 'permissions', ]; protected $appends = [ 'permissions', ]; protected $casts = [ 'permissions' => 'array', ]; public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setTable(config('nova-permissions.table_names.roles', 'roles')); } public function users() { return $this->belongsToMany(config('nova-permissions.user_model', 'App\Models\User'), config('nova-permissions.table_names.role_user', 'role_user'), 'role_id', 'user_id'); } public function getPermissions() { return $this->hasMany(Permission::class); } /** * Replace all existing permissions with a new set of permissions. * * @param array $permissions */ public function setPermissions(array $permissions) { if (! $this->id) { $this->save(); } $this->revokeAll(); collect($permissions)->each(function ($permission) { $this->grant($permission); }); $this->setRelations([]); } /** * Check if a user has a given permission. * * @param string $permission * * @return bool */ public function hasPermission($permission) { return $this->getPermissions->contains('permission_slug', $permission); } /** * Give Permission to a Role. * * @param string $permission * * @return bool */ public function grant($permission) { if ($this->hasPermission($permission)) { return true; } if (! array_key_exists($permission, Gate::abilities())) { abort(403, 'Unknown permission'); } return Permission::create([ 'role_id' => $this->id, 'permission_slug' => $permission, ]); } /** * Revokes a Permission from a Role. * * @param string $permission * * @return bool */ public function revoke($permission) { if (\is_string($permission)) { Permission::findOrFail($permission)->delete(); $this->setRelations([]); return true; } return false; } /** * Remove all permissions from this Role. */ public function revokeAll() { $this->getPermissions()->delete(); $this->setRelations([]); return true; } /** * Get a list of permissions. * * @return array */ public function getPermissionsAttribute() { return Permission::where('role_id', $this->id)->get()->pluck('permission_slug')->toArray(); } /** * Replace all existing permissions with a new set of permissions. * * @param array $permissions */ public function setPermissionsAttribute(array $permissions) { if (! $this->id) { $this->save(); } $this->revokeAll(); collect($permissions)->map(function ($permission) { if (! \in_array($permission, Policy::all(), true)) { return; } $this->grant($permission); }); } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/ToolServiceProvider.php
src/ToolServiceProvider.php
<?php namespace Pktharindu\NovaPermissions; use Illuminate\Support\Collection; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\ServiceProvider; class ToolServiceProvider extends ServiceProvider { /** * Bootstrap the application services. */ public function boot(Filesystem $filesystem) { $this->publishes([ __DIR__.'/../config/nova-permissions.php' => config_path('nova-permissions.php'), ], 'config'); $this->publishes([ __DIR__.'/../database/migrations/create_gates_table.php.stub' => $this->getMigrationFileName($filesystem), ], 'migrations'); } /** * Register the application services. */ public function register() { $this->mergeConfigFrom( __DIR__.'/../config/nova-permissions.php', 'nova-permissions' ); } /** * Returns existing migration file if found, else uses the current timestamp. * * @param Filesystem $filesystem * * @return string */ protected function getMigrationFileName(Filesystem $filesystem): string { $timestamp = date('Y_m_d_His'); return Collection::make($this->app->databasePath().\DIRECTORY_SEPARATOR.'migrations'.\DIRECTORY_SEPARATOR) ->flatMap(function ($path) use ($filesystem) { return $filesystem->glob($path.'*_create_gates_table.php'); })->push($this->app->databasePath()."/migrations/{$timestamp}_create_gates_table.php") ->first(); } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/Checkboxes.php
src/Checkboxes.php
<?php namespace Pktharindu\NovaPermissions; use Laravel\Nova\Fields\Field; use Laravel\Nova\Http\Requests\NovaRequest; class Checkboxes extends Field { /** * The field's component. * * @var string */ public $component = 'field-checkboxes'; /** * Specify the available options. * * @param array $options * * @return self */ public function options(array $options) { return $this->withMeta(['options' => $options]); } /** * Disable type casting of array keys to numeric values to return the unmodified keys. */ public function withGroups() { return $this->withMeta(['withGroups' => true]); } /** * Hydrate the given attribute on the model based on the incoming request. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request * @param string $requestAttribute * @param object $model * @param string $attribute */ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute) { if ($request->exists($requestAttribute)) { /* * When editing entries, they are returned as comma seperated string (unsure why). * As a result we need to include this check and explode the values if required. */ if (! \is_array($choices = $request[$requestAttribute])) { $permissions = collect(explode(',', $choices))->reject(function ($name) { return empty($name); })->all(); } $model->setPermissions($permissions); } } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/Permission.php
src/Permission.php
<?php namespace Pktharindu\NovaPermissions; use Illuminate\Database\Eloquent\Model; class Permission extends Model { protected $primaryKey = 'permission_slug'; public $incrementing = false; protected $fillable = [ 'role_id', 'permission_slug', ]; public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setTable(config('nova-permissions.table_names.role_permission', 'role_permission')); } public function roles() { return $this->belongsToMany(Role::class, config('nova-permissions.table_names.role_permission', 'role_permission'), 'permission_slug', 'role_id'); } public function hasUsers() { return (bool) $this->roles()->has('users')->count(); } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/Traits/HasRoles.php
src/Traits/HasRoles.php
<?php namespace Pktharindu\NovaPermissions\Traits; use Pktharindu\NovaPermissions\Role; trait HasRoles { /** * Get all Roles given to this user. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function roles() { return $this->belongsToMany(Role::class, config('nova-permissions.table_names.role_user', 'role_user'), 'user_id')->with('getPermissions'); } /** * Scope a query to eager load `roles` relationship * to reduce database queries. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeWithRoles($query) { return $query->with('roles'); } /** * Determine if any of the assigned roles to this user * have a specific permission. * * @param string $permission * * @return bool */ public function hasPermissionTo($permission) { return $this->roles->contains(function ($role) use ($permission) { return $role->getPermissions->contains('permission_slug', $permission); }); } /** * Determine if the model has any of the given permissions. * * @param array ...$permissions * * @throws \Exception * * @return bool */ public function hasAnyPermission(...$permissions): bool { if (\is_array($permissions[0])) { $permissions = $permissions[0]; } foreach ($permissions as $permission) { if ($this->hasPermissionTo($permission)) { return true; } } return false; } /** * Determine if the model has all of the given permissions. * * @param array ...$permissions * * @throws \Exception * * @return bool */ public function hasAllPermissions(...$permissions): bool { if (\is_array($permissions[0])) { $permissions = $permissions[0]; } foreach ($permissions as $permission) { if (! $this->hasPermissionTo($permission)) { return false; } } return true; } /** * Assign a role to this user. * * @param string|Role $role * * @return bool */ public function assignRole($role) { if (\is_string($role)) { return $this->roles()->attach(Role::where('slug', $role)->first()); } return $this->roles()->attach($role); } /** * Remove a role from this user. * * @param string|Role $role * * @return bool */ public function removeRole($role) { if (\is_string($role)) { return $this->roles()->detach(Role::where('slug', $role)->first()); } return $this->roles()->detach($role); } /** * Reassign roles from an id or an array of role Ids. * * @param int|array $roles */ public function setRolesById($roles) { $roles = \is_array($roles) ? $roles : [$roles]; return $this->roles()->sync($roles); } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false
pktharindu/nova-permissions
https://github.com/pktharindu/nova-permissions/blob/6f4fcb125558d41304440cd3029944a0a840df19/src/Traits/ValidatesPermissions.php
src/Traits/ValidatesPermissions.php
<?php namespace Pktharindu\NovaPermissions\Traits; use Pktharindu\NovaPermissions\Permission; trait ValidatesPermissions { /** * If nobody has this permission, grant access to everyone * This avoids you from being locked out of your application. * * @param string $permission * * @return boolean */ protected function nobodyHasAccess($permission) { if (! $requestedPermission = Permission::find($permission)) { return true; } return ! $requestedPermission->hasUsers(); } }
php
MIT
6f4fcb125558d41304440cd3029944a0a840df19
2026-01-05T05:01:00.821895Z
false