code
stringlengths
15
9.96M
docstring
stringlengths
1
10.1k
func_name
stringlengths
1
124
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
6
186
url
stringlengths
50
236
license
stringclasses
4 values
public static function detailQuery(NovaRequest $request, $query) { return parent::detailQuery($request, $query); }
Build a "detail" query for the given resource. @param \Laravel\Nova\Http\Requests\NovaRequest $request @param \Illuminate\Database\Eloquent\Builder $query @return \Illuminate\Database\Eloquent\Builder
detailQuery
php
mikebronner/laravel-governor
src/Nova/Resource.php
https://github.com/mikebronner/laravel-governor/blob/master/src/Nova/Resource.php
MIT
public static function relatableQuery(NovaRequest $request, $query) { return parent::relatableQuery($request, $query); }
Build a "relatable" query for the given resource. This query determines which instances of the model may be attached to other resources. @param \Laravel\Nova\Http\Requests\NovaRequest $request @param \Illuminate\Database\Eloquent\Builder $query @return \Illuminate\Database\Eloquent\Builder
relatableQuery
php
mikebronner/laravel-governor
src/Nova/Resource.php
https://github.com/mikebronner/laravel-governor/blob/master/src/Nova/Resource.php
MIT
public function boot() { Nova::script('genealabs-laravel-governor', __DIR__.'/../../../dist/js/tool.js'); Nova::style('genealabs-laravel-governor', __DIR__ . '/../../../dist/css/tool.css'); Nova::style('genealabs-laravel-governor', __DIR__ . '/../../../dist/css/vue-multiselect.min.css'); }
Perform any tasks that need to happen when the tool is booted. @return void
boot
php
mikebronner/laravel-governor
src/Nova/Tools/Governor.php
https://github.com/mikebronner/laravel-governor/blob/master/src/Nova/Tools/Governor.php
MIT
public function renderNavigation() { return view('genealabs-laravel-governor::navigation'); }
Build the view that renders the navigation links for the tool. @return \Illuminate\View\View
renderNavigation
php
mikebronner/laravel-governor
src/Nova/Tools/Governor.php
https://github.com/mikebronner/laravel-governor/blob/master/src/Nova/Tools/Governor.php
MIT
public function up() { Schema::create('provinces', function (Blueprint $table) { $table->tinyIncrements('id'); $table->string('name'); $table->string('slug')->unique()->index(); $table->text('description')->nullable(); }); }
Run the migrations. @return void
up
php
sanjabteam/baloot
database/migrations/2014_10_11_000000_create_provinces_table.php
https://github.com/sanjabteam/baloot/blob/master/database/migrations/2014_10_11_000000_create_provinces_table.php
MIT
public function down() { Schema::dropIfExists('provinces'); }
Reverse the migrations. @return void
down
php
sanjabteam/baloot
database/migrations/2014_10_11_000000_create_provinces_table.php
https://github.com/sanjabteam/baloot/blob/master/database/migrations/2014_10_11_000000_create_provinces_table.php
MIT
public function up() { Schema::create('cities', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('slug')->unique()->index(); $table->text('description')->nullable(); $table->unsignedTinyInteger('province_id'); $table->foreign('province_id')->references('id')->on('provinces')->onDelete('cascade')->onUpdate('cascade'); }); }
Run the migrations. @return void
up
php
sanjabteam/baloot
database/migrations/2014_10_11_000001_create_cities_table.php
https://github.com/sanjabteam/baloot/blob/master/database/migrations/2014_10_11_000001_create_cities_table.php
MIT
public function down() { Schema::dropIfExists('cities'); }
Reverse the migrations. @return void
down
php
sanjabteam/baloot
database/migrations/2014_10_11_000001_create_cities_table.php
https://github.com/sanjabteam/baloot/blob/master/database/migrations/2014_10_11_000001_create_cities_table.php
MIT
function en_to_fa($text) { $en_num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; $fa_num = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; return str_replace($en_num, $fa_num, $text); }
Convert english digits to farsi. @param string $text @return string
en_to_fa
php
sanjabteam/baloot
src/helpers.php
https://github.com/sanjabteam/baloot/blob/master/src/helpers.php
MIT
function fa_to_en($text) { $fa_num = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', '٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']; $en_num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; return str_replace($fa_num, $en_num, $text); }
Convert farsi/arabic digits to english. @param string $text @return string
fa_to_en
php
sanjabteam/baloot
src/helpers.php
https://github.com/sanjabteam/baloot/blob/master/src/helpers.php
MIT
function str_to_slug(string $string, string $separator = '-') { $string = fa_to_en(trim(mb_strtolower($string))); $string = preg_replace('!['.preg_quote($separator === '-' ? '_' : '-').']+!u', $separator, $string); return preg_replace( '/\\'.$separator.'{2,}/', $separator, preg_replace('/[^A-Za-z0-9\x{0620}-\x{064A}\x{0698}\x{067E}\x{0686}\x{06AF}\x{06CC}\x{06A9}]/ui', $separator, $string) ); }
Returns slug for string. @param string $string @param string $separator @return string
str_to_slug
php
sanjabteam/baloot
src/helpers.php
https://github.com/sanjabteam/baloot/blob/master/src/helpers.php
MIT
public function boot() { $this->publishes([ __DIR__.'/../config/config.php' => config_path('baloot.php'), ], 'config'); Validator::resolver(function ($translator, $data, $rules, $messages = [], $customAttributes = []) { return new BalootValidator($translator, $data, $rules, $messages, $customAttributes); }); if (config('baloot.geo')) { $this->loadMigrationsFrom([ realpath(__DIR__.'/../database/migrations/2014_10_11_000000_create_provinces_table.php'), realpath(__DIR__.'/../database/migrations/2014_10_11_000001_create_cities_table.php'), ]); $this->bindCityRoutes(); } $this->registerQueryBuilderMacros(); }
Bootstrap the application services.
boot
php
sanjabteam/baloot
src/BalootServiceProvider.php
https://github.com/sanjabteam/baloot/blob/master/src/BalootServiceProvider.php
MIT
public function register() { $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'baloot'); app(\Faker\Generator::class)->addProvider(new BalootFakerProvider(app(\Faker\Generator::class))); }
Register the application services.
register
php
sanjabteam/baloot
src/BalootServiceProvider.php
https://github.com/sanjabteam/baloot/blob/master/src/BalootServiceProvider.php
MIT
public function validateIranMobile($attribute, $value, $parameters, $validator) { if (isset($parameters[0]) and $parameters[0] == 'true') { return preg_match("/^0?9[0-1-2-3-9]\d{8}$/", $value); } return preg_match("/^09[0-1-2-3-9]\d{8}$/", $value); }
Validate iran mobile. @param string $attribute @param string $value @param array $parameters @param \Illuminate\Validation\Validator $validator @return bool
validateIranMobile
php
sanjabteam/baloot
src/BalootValidator.php
https://github.com/sanjabteam/baloot/blob/master/src/BalootValidator.php
MIT
public function validateIranPhone($attribute, $value, $parameters, $validator) { return preg_match("/^0[1-8]\d{9}$/", $value); }
Validate iran phone. @param string $attribute @param string $value @param array $parameters @param \Illuminate\Validation\Validator $validator @return bool
validateIranPhone
php
sanjabteam/baloot
src/BalootValidator.php
https://github.com/sanjabteam/baloot/blob/master/src/BalootValidator.php
MIT
public function validateIranNationalCode($attribute, $value, $parameters, $validator) { if (! preg_match('/^[0-9]{10}$/', $value)) { return false; } for ($i = 0; $i < 10; $i++) { if ($value == str_repeat($i, 10)) { return false; } } $sum = 0; for ($i = 0; $i < 9; $i++) { $sum += ((10 - $i) * intval(substr($value, $i, 1))); } $ret = $sum % 11; $parity = intval(substr($value, 9, 1)); if (($ret < 2 && $ret == $parity) || ($ret >= 2 && $ret == 11 - $parity)) { return true; } return false; }
Validate iran national code. @param string $attribute @param string $value @param array $parameters @param \Illuminate\Validation\Validator $validator
validateIranNationalCode
php
sanjabteam/baloot
src/BalootValidator.php
https://github.com/sanjabteam/baloot/blob/master/src/BalootValidator.php
MIT
public function province() { return $this->belongsTo(Province::class); }
Province of city. @return \Illuminate\Database\Eloquent\Relations\BelongsTo
province
php
sanjabteam/baloot
src/Models/City.php
https://github.com/sanjabteam/baloot/blob/master/src/Models/City.php
MIT
public function cities() { return $this->hasMany(City::class); }
Cities of province. @codeCoverageIgnore @return \Illuminate\Database\Eloquent\Relations\HasMany
cities
php
sanjabteam/baloot
src/Models/Province.php
https://github.com/sanjabteam/baloot/blob/master/src/Models/Province.php
MIT
public function handle($request, Closure $next) { $allInputs = $request->all(); $allInputs = $this->removeArabicCharacters($allInputs); $allInputs = $this->removePersianNumbers($allInputs); $request->replace($allInputs); return $next($request); }
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
handle
php
sanjabteam/baloot
src/Middleware/FixRequestInputs.php
https://github.com/sanjabteam/baloot/blob/master/src/Middleware/FixRequestInputs.php
MIT
public function setBannedFlag() { $this->setAttribute('banned_at', Carbon::now()); return $this; }
Set banned flag. @return $this
setBannedFlag
php
cybercog/laravel-ban
src/Traits/HasBannedAtHelpers.php
https://github.com/cybercog/laravel-ban/blob/master/src/Traits/HasBannedAtHelpers.php
MIT
public function unsetBannedFlag() { $this->setAttribute('banned_at', null); return $this; }
Unset banned flag. @return $this
unsetBannedFlag
php
cybercog/laravel-ban
src/Traits/HasBannedAtHelpers.php
https://github.com/cybercog/laravel-ban/blob/master/src/Traits/HasBannedAtHelpers.php
MIT
public function __construct(Guard $auth) { $this->auth = $auth; }
@param \Illuminate\Contracts\Auth\Guard $auth
__construct
php
cybercog/laravel-ban
src/Http/Middleware/ForbidBannedUser.php
https://github.com/cybercog/laravel-ban/blob/master/src/Http/Middleware/ForbidBannedUser.php
MIT
public function handle($request, Closure $next) { $user = $this->auth->user(); if ($user && $user instanceof BannableContract && $user->isBanned()) { $redirectUrl = config('ban.redirect_url', null); $errors = [ 'login' => 'This account is blocked.', ]; $responseCode = $request->header('X-Inertia') ? 303 : 302; if ($redirectUrl === null) { return redirect()->back($responseCode)->withInput()->withErrors($errors); } else { return redirect($redirectUrl, $responseCode)->withInput()->withErrors($errors); } } return $next($request); }
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed @throws \Exception
handle
php
cybercog/laravel-ban
src/Http/Middleware/ForbidBannedUser.php
https://github.com/cybercog/laravel-ban/blob/master/src/Http/Middleware/ForbidBannedUser.php
MIT
public function __construct(Guard $auth) { $this->auth = $auth; }
@param \Illuminate\Contracts\Auth\Guard $auth
__construct
php
cybercog/laravel-ban
src/Http/Middleware/LogsOutBannedUser.php
https://github.com/cybercog/laravel-ban/blob/master/src/Http/Middleware/LogsOutBannedUser.php
MIT
public function handle($request, Closure $next) { $user = $this->auth->user(); if ($user && $user instanceof BannableContract && $user->isBanned()) { if ($this->auth instanceof StatefulGuardContract) { // TODO: Cover with tests $this->auth->logout(); } $redirectUrl = config('ban.redirect_url', null); $errors = [ 'login' => 'This account is blocked.', ]; $responseCode = $request->header('X-Inertia') ? 303 : 302; if ($redirectUrl === null) { return redirect()->back($responseCode)->withInput()->withErrors($errors); } else { return redirect($redirectUrl, $responseCode)->withInput()->withErrors($errors); } } return $next($request); }
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed @throws \Exception
handle
php
cybercog/laravel-ban
src/Http/Middleware/LogsOutBannedUser.php
https://github.com/cybercog/laravel-ban/blob/master/src/Http/Middleware/LogsOutBannedUser.php
MIT
public function apply(Builder $builder, Model $model) { if (method_exists($model, 'shouldApplyBannedAtScope') && $model->shouldApplyBannedAtScope()) { return $builder->whereNull('banned_at'); } return $builder; }
Apply the scope to a given Eloquent query builder. @param \Illuminate\Database\Eloquent\Builder $builder @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Database\Eloquent\Builder
apply
php
cybercog/laravel-ban
src/Scopes/BannedAtScope.php
https://github.com/cybercog/laravel-ban/blob/master/src/Scopes/BannedAtScope.php
MIT
public function __construct(BannableContract $model) { $this->model = $model; }
@param \Cog\Contracts\Ban\Bannable $model
__construct
php
cybercog/laravel-ban
src/Events/ModelWasUnbanned.php
https://github.com/cybercog/laravel-ban/blob/master/src/Events/ModelWasUnbanned.php
MIT
public function __construct(BannableContract $bannable, BanContract $ban) { $this->model = $bannable; $this->ban = $ban; }
@param \Cog\Contracts\Ban\Bannable $bannable @param \Cog\Contracts\Ban\Ban $ban
__construct
php
cybercog/laravel-ban
src/Events/ModelWasBanned.php
https://github.com/cybercog/laravel-ban/blob/master/src/Events/ModelWasBanned.php
MIT
public function __construct(array $decorators = []) { $this->decorators = $decorators; }
Create a new auto presenter. @param \McCool\LaravelAutoPresenter\Decorators\DecoratorInterface[] $decorators @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenter.php
MIT
public function decorate($subject) { foreach ($this->decorators as $decorator) { if ($decorator->canDecorate($subject)) { return $decorator->decorate($subject); } } return $subject; }
Things go in, get decorated (or not) and are returned. @param mixed $subject @return mixed
decorate
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenter.php
MIT
public function register(DecoratorInterface $decorator) { $this->decorators[] = $decorator; }
Register a decorator. @param \McCool\LaravelAutoPresenter\Decorators\DecoratorInterface $decorator @return void
register
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenter.php
MIT
public function getDecorators() { return $this->decorators; }
Get the registered decorators. @return \McCool\LaravelAutoPresenter\Decorators\DecoratorInterface[]
getDecorators
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenter.php
MIT
public function setWrappedObject($resource) { $this->wrappedObject = $resource; return $this; }
Get the wrapped object. @param object $resource @return $this
setWrappedObject
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function getWrappedObject() { return $this->wrappedObject; }
Get the wrapped object. @return object
getWrappedObject
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function getRouteKey() { return $this->wrappedObject->getRouteKey(); }
Get the value of the model's route key. @return mixed
getRouteKey
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function getRouteKeyName() { return $this->wrappedObject->getRouteKeyName(); }
Get the route key for the model. @return string
getRouteKeyName
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function resolveRouteBinding($routeKey, $field = null) { if (method_exists($this->wrappedObject, 'resolveRouteBinding') && is_callable([$this->wrappedObject, 'resolveRouteBinding'])) { return $this->wrappedObject->resolveRouteBinding($routeKey, $field); } return $this->wrappedObject->where($field ?? $this->wrappedObject->getRouteKeyName(), $routeKey)->first(); }
Retrieve model for route model binding. @param mixed $routeKey @param string|null $field @return mixed
resolveRouteBinding
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function __get(string $key) { if (method_exists($this, $key)) { return $this->{$key}(); } return $this->wrappedObject->$key; }
Magic method access initially tries for local fields, then defers to the decorated object. @param string $key @return mixed
__get
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function __call(string $key, array $args) { if (method_exists($this->wrappedObject, $key)) { return call_user_func_array([$this->wrappedObject, $key], $args); } throw new MethodNotFoundException(get_called_class(), $key); }
Magic Method access for methods called against the presenter looks for a method on the resource, or throws an exception if none is found. @param string $key @param array $args @throws \McCool\LaravelAutoPresenter\Exceptions\MethodNotFoundException @return mixed
__call
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function __isset(string $key) { if (method_exists($this, $key)) { return true; } return isset($this->wrappedObject->$key); }
Is the key set on either the presenter or the wrapped object? @param string $key @return bool
__isset
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function __toString() { return (string) $this->wrappedObject; }
Get the wrapped object, cast to a string. @return string
__toString
php
laravel-auto-presenter/laravel-auto-presenter
src/BasePresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/BasePresenter.php
MIT
public function boot() { $this->setupEventFiring($this->app); $this->setupEventListening($this->app); }
Boot the service provider. @return void
boot
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenterServiceProvider.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenterServiceProvider.php
MIT
public function register() { $this->registerAutoPresenter($this->app); }
Register the service provider. @return void
register
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenterServiceProvider.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenterServiceProvider.php
MIT
public function registerAutoPresenter(Container $app) { $app->singleton('autopresenter', function (Container $app) { $autoPresenter = new AutoPresenter(); $autoPresenter->register(new AtomDecorator($autoPresenter, $app)); $autoPresenter->register(new ArrayDecorator($autoPresenter)); $autoPresenter->register(new PaginatorDecorator($autoPresenter)); return $autoPresenter; }); $app->alias('autopresenter', AutoPresenter::class); }
Register the presenter decorator. @param \Illuminate\Contracts\Container\Container $app @return void
registerAutoPresenter
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenterServiceProvider.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenterServiceProvider.php
MIT
public function provides() { return [ 'autopresenter', ]; }
Get the services provided by the provider. @return string[]
provides
php
laravel-auto-presenter/laravel-auto-presenter
src/AutoPresenterServiceProvider.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/AutoPresenterServiceProvider.php
MIT
public function __construct(AutoPresenter $autoPresenter) { $this->autoPresenter = $autoPresenter; }
Create a new paginator decorator. @param \McCool\LaravelAutoPresenter\AutoPresenter $autoPresenter @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/PaginatorDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/PaginatorDecorator.php
MIT
public function canDecorate($subject) { return $subject instanceof Paginator; }
Can the subject be decorated? @param mixed $subject @return bool
canDecorate
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/PaginatorDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/PaginatorDecorator.php
MIT
protected function getItems(Paginator $subject) { $object = new ReflectionObject($subject); $items = $object->getProperty('items'); $items->setAccessible(true); return $items->getValue($subject); }
Decorate a paginator instance. We're using hacky reflection for now because there is no public getter. @param \Illuminate\Contracts\Pagination\Paginator $subject @return \Illuminate\Support\Collection
getItems
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/PaginatorDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/PaginatorDecorator.php
MIT
public function getAutoPresenter() { return $this->autoPresenter; }
Get the auto presenter instance. @codeCoverageIgnore @return \McCool\LaravelAutoPresenter\AutoPresenter
getAutoPresenter
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/PaginatorDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/PaginatorDecorator.php
MIT
public function __construct(AutoPresenter $autoPresenter) { $this->autoPresenter = $autoPresenter; }
Create a new array decorator. @param \McCool\LaravelAutoPresenter\AutoPresenter $autoPresenter @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/ArrayDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/ArrayDecorator.php
MIT
public function canDecorate($subject) { return is_array($subject) || $subject instanceof Collection; }
Can the subject be decorated? @param mixed $subject @return bool
canDecorate
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/ArrayDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/ArrayDecorator.php
MIT
public function getAutoPresenter() { return $this->autoPresenter; }
Get the auto presenter instance. @codeCoverageIgnore @return \McCool\LaravelAutoPresenter\AutoPresenter
getAutoPresenter
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/ArrayDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/ArrayDecorator.php
MIT
public function __construct(AutoPresenter $autoPresenter, Container $container) { $this->autoPresenter = $autoPresenter; $this->container = $container; }
Create a new atom decorator. @param \McCool\LaravelAutoPresenter\AutoPresenter $autoPresenter @param \Illuminate\Contracts\Container\Container $container @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/AtomDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/AtomDecorator.php
MIT
public function canDecorate($subject) { return $subject instanceof Decoratable; }
Can the subject be decorated? @param mixed $subject @return bool
canDecorate
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/AtomDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/AtomDecorator.php
MIT
public function getAutoPresenter() { return $this->autoPresenter; }
Get the auto presenter instance. @codeCoverageIgnore @return \McCool\LaravelAutoPresenter\AutoPresenter
getAutoPresenter
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/AtomDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/AtomDecorator.php
MIT
public function getContainer() { return $this->container; }
Get the container instance. @codeCoverageIgnore @return \Illuminate\Contracts\Container\Container
getContainer
php
laravel-auto-presenter/laravel-auto-presenter
src/Decorators/AtomDecorator.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Decorators/AtomDecorator.php
MIT
protected static function getFacadeAccessor() { return 'autopresenter'; }
Get the registered name of the component. @return string
getFacadeAccessor
php
laravel-auto-presenter/laravel-auto-presenter
src/Facades/AutoPresenter.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Facades/AutoPresenter.php
MIT
public function __construct(string $class, string $method, string $message = null) { $this->method = $method; if (!$message) { $message = "The method '$method' was not found on the presenter class '$class'."; } parent::__construct($class, $message); }
Create a new method not found exception. @param string $class @param string $method @param string|null $message @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Exceptions/MethodNotFoundException.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Exceptions/MethodNotFoundException.php
MIT
public function getMethod() { return $this->method; }
Get the requested method. @return string
getMethod
php
laravel-auto-presenter/laravel-auto-presenter
src/Exceptions/MethodNotFoundException.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Exceptions/MethodNotFoundException.php
MIT
public function __construct(string $class, string $message) { $this->class = $class; parent::__construct($message); }
Create a new not found exception. @param string $class @param string $message @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Exceptions/NotFoundException.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Exceptions/NotFoundException.php
MIT
public function getClass() { return $this->class; }
Get the class name. @return string
getClass
php
laravel-auto-presenter/laravel-auto-presenter
src/Exceptions/NotFoundException.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Exceptions/NotFoundException.php
MIT
public function __construct(string $class, string $message = null) { if (!$message) { $message = "The presenter class '$class' was not found."; } parent::__construct($class, $message); }
Create a new presenter not found exception. @param string $class @param string|null $message @return void
__construct
php
laravel-auto-presenter/laravel-auto-presenter
src/Exceptions/PresenterNotFoundException.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/src/Exceptions/PresenterNotFoundException.php
MIT
protected function getServiceProviderClass() { return AutoPresenterServiceProvider::class; }
Get the service provider class. @return string
getServiceProviderClass
php
laravel-auto-presenter/laravel-auto-presenter
tests/AbstractTestCase.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/AbstractTestCase.php
MIT
protected function getPaths() { return [ realpath(__DIR__.'/../src'), realpath(__DIR__), ]; }
Get the code paths to analyze. @return string[]
getPaths
php
laravel-auto-presenter/laravel-auto-presenter
tests/AnalysisTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/AnalysisTest.php
MIT
public function setUpProperties() { $this->decorator = new ArrayDecorator(Mockery::mock(AutoPresenter::class)); }
@before
setUpProperties
php
laravel-auto-presenter/laravel-auto-presenter
tests/Decorators/ArrayDecoratorTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Decorators/ArrayDecoratorTest.php
MIT
public function setUpProperties() { $this->decorator = new AtomDecorator(Mockery::mock(AutoPresenter::class), Mockery::mock(Container::class)); }
@before
setUpProperties
php
laravel-auto-presenter/laravel-auto-presenter
tests/Decorators/AtomDecoratorTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Decorators/AtomDecoratorTest.php
MIT
public function setUpProperties() { $this->decorator = new PaginatorDecorator(Mockery::mock(AutoPresenter::class)); }
@before
setUpProperties
php
laravel-auto-presenter/laravel-auto-presenter
tests/Decorators/PaginatorDecoratorTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Decorators/PaginatorDecoratorTest.php
MIT
protected function getEnvironmentSetUp($app) { parent::getEnvironmentSetUp($app); $app->view->addNamespace('stubs', realpath(__DIR__.'/stubs')); }
Setup the application environment. @param \Illuminate\Contracts\Foundation\Application $app @return void
getEnvironmentSetUp
php
laravel-auto-presenter/laravel-auto-presenter
tests/Functional/ViewDataTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Functional/ViewDataTest.php
MIT
protected function getFacadeAccessor() { return 'autopresenter'; }
Get the facade accessor. @return string
getFacadeAccessor
php
laravel-auto-presenter/laravel-auto-presenter
tests/Facades/AutoPresenterTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Facades/AutoPresenterTest.php
MIT
protected function getFacadeClass() { return Facade::class; }
Get the facade class. @return string
getFacadeClass
php
laravel-auto-presenter/laravel-auto-presenter
tests/Facades/AutoPresenterTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Facades/AutoPresenterTest.php
MIT
protected function getFacadeRoot() { return AutoPresenter::class; }
Get the facade root. @return string
getFacadeRoot
php
laravel-auto-presenter/laravel-auto-presenter
tests/Facades/AutoPresenterTest.php
https://github.com/laravel-auto-presenter/laravel-auto-presenter/blob/master/tests/Facades/AutoPresenterTest.php
MIT
public function __construct($options = []) { if (!session_id()) { session_start(); } if (isset($options['cartMaxItem']) && preg_match('/^\d+$/', $options['cartMaxItem'])) { $this->cartMaxItem = $options['cartMaxItem']; } if (isset($options['itemMaxQuantity']) && preg_match('/^\d+$/', $options['itemMaxQuantity'])) { $this->itemMaxQuantity = $options['itemMaxQuantity']; } if (isset($options['useCookie']) && $options['useCookie']) { $this->useCookie = true; } $this->cartId = md5((isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'SimpleCart') . '_cart'; $this->read(); }
Initialize cart. @param array $options
__construct
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getItems() { return $this->items; }
Get items in the cart. @return array
getItems
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function isEmpty() { return empty(array_filter($this->items)); }
Check if the cart is empty. @return bool
isEmpty
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getTotalItem() { $total = 0; foreach ($this->items as $items) { foreach ($items as $item) { ++$total; } } return $total; }
Get the total number of items in the cart. @return int
getTotalItem
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getTotalQuantity() { $quantity = 0; foreach ($this->items as $items) { foreach ($items as $item) { $quantity += $item['quantity']; } } return $quantity; }
Get the total quantity of items in the cart. @return int
getTotalQuantity
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getAttributeTotal($attribute = 'price') { $total = 0; foreach ($this->items as $items) { foreach ($items as $item) { if (isset($item['attributes'][$attribute])) { $total += $item['attributes'][$attribute] * $item['quantity']; } } } return $total; }
Get the sum of a specific attribute (e.g., price) in the cart. @param string $attribute @return int
getAttributeTotal
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function clear() { $this->items = []; $this->write(); }
Remove all items from the cart.
clear
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function isItemExists($id, $attributes = []) { $attributes = (is_array($attributes)) ? array_filter($attributes) : [$attributes]; if (isset($this->items[$id])) { $hash = md5(json_encode($attributes)); foreach ($this->items[$id] as $item) { if ($item['hash'] == $hash) { return true; } } } return false; }
Check if an item exists in the cart. @param string $id @param array $attributes @return bool
isItemExists
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getItem($id, $hash = null) { if ($hash) { $key = array_search($hash, array_column($this->items[$id], 'hash')); if ($key !== false) { return $this->items[$id][$key]; } return false; } else { return reset($this->items[$id]); } }
Get one item from the cart. @param string $id @param string $hash @return array
getItem
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function add($id, $quantity = 1, $attributes = []) { $quantity = (preg_match('/^\d+$/', $quantity)) ? $quantity : 1; $attributes = (is_array($attributes)) ? array_filter($attributes) : [$attributes]; $hash = md5(json_encode($attributes)); if (count($this->items) >= $this->cartMaxItem && $this->cartMaxItem != 0) { return false; } if (isset($this->items[$id])) { foreach ($this->items[$id] as $index => $item) { if ($item['hash'] == $hash) { $this->items[$id][$index]['quantity'] += $quantity; $this->items[$id][$index]['quantity'] = ($this->itemMaxQuantity < $this->items[$id][$index]['quantity'] && $this->itemMaxQuantity != 0) ? $this->itemMaxQuantity : $this->items[$id][$index]['quantity']; $this->write(); return true; } } } $this->items[$id][] = [ 'id' => $id, 'quantity' => ($quantity > $this->itemMaxQuantity && $this->itemMaxQuantity != 0) ? $this->itemMaxQuantity : $quantity, 'hash' => $hash, 'attributes' => $attributes, ]; $this->write(); return true; }
Add an item to the cart. @param string $id @param int $quantity @param array $attributes @return bool
add
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function update($id, $quantity = 1, $attributes = []) { $quantity = (preg_match('/^\d+$/', $quantity)) ? $quantity : 1; if ($quantity == 0) { $this->remove($id, $attributes); return true; } if (isset($this->items[$id])) { $hash = md5(json_encode(array_filter($attributes))); foreach ($this->items[$id] as $index => $item) { if ($item['hash'] == $hash) { $this->items[$id][$index]['quantity'] = $quantity; $this->items[$id][$index]['quantity'] = ($this->itemMaxQuantity < $this->items[$id][$index]['quantity'] && $this->itemMaxQuantity != 0) ? $this->itemMaxQuantity : $this->items[$id][$index]['quantity']; $this->write(); return true; } } } return false; }
Update item quantity. @param string $id @param int $quantity @param array $attributes @return bool
update
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function updateAttributes($id, $hash, $attributes = []) { if (isset($this->items[$id])) { foreach ($this->items[$id] as $index => $item) { if ($item['hash'] == $hash) { foreach ($attributes as $key => $value) { $this->items[$id][$index]['attributes'][$key] = $value; } $this->write(); return true; } } } return false; }
Update the attributes of a specific item in the cart. @param string $id @param string $hash @param array $attributes @return bool
updateAttributes
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function remove($id, $attributes = []) { $attributes = (is_array($attributes)) ? array_filter($attributes) : [$attributes]; if (isset($this->items[$id])) { if (empty($attributes)) { unset($this->items[$id]); } else { $hash = md5(json_encode($attributes)); foreach ($this->items[$id] as $index => $item) { if ($item['hash'] == $hash) { unset($this->items[$id][$index]); if (empty($this->items[$id])) { unset($this->items[$id]); } } } } $this->write(); return true; } return false; }
Remove an item from the cart. @param string $id @param array $attributes @return bool
remove
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function applyDiscount($code, $amount) { $this->discount = $amount; }
Apply a discount code to the cart. @param string $code @param float $amount
applyDiscount
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getTotalWithDiscount() { return $this->getAttributeTotal('price') - $this->discount; }
Get the total after applying the discount. @return float
getTotalWithDiscount
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function setShippingCost($cost) { $this->shippingCost = $cost; }
Set shipping cost for the cart. @param float $cost
setShippingCost
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function getTotalWithShipping() { return $this->getTotalWithDiscount() + $this->shippingCost; }
Get the total after adding shipping cost. @return float
getTotalWithShipping
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function saveToDatabase($userId) { $cartData = serialize($this->items); // Save $cartData to the database associated with the $userId. }
Save cart to database for persistent sessions. @param int $userId
saveToDatabase
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
public function loadFromDatabase($userId) { // Fetch cart data from the database for the given $userId. // Example: $cartData = fetch_cart_data($userId); // $this->items = unserialize($cartData); }
Load cart from database for persistent sessions. @param int $userId
loadFromDatabase
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
protected function write() { if ($this->useCookie) { setcookie($this->cartId, json_encode($this->items), time() + 604800, '/'); } else { $_SESSION[$this->cartId] = $this->items; } }
Save cart data to session or cookie.
write
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
protected function read() { $this->items = ($this->useCookie && isset($_COOKIE[$this->cartId])) ? json_decode($_COOKIE[$this->cartId], true) : ((isset($_SESSION[$this->cartId])) ? $_SESSION[$this->cartId] : []); }
Read cart data from session or cookie.
read
php
seikan/Cart
class.Cart.php
https://github.com/seikan/Cart/blob/master/class.Cart.php
MIT
function returns($value) { if ($value === null) { return 'NULL'; } if (is_array($value)) { return '(array)' . '<pre>' . print_r($value, true) . '</pre>'; } if ($value === true) { return '(bool)TRUE'; } if ($value === false) { return '(bool)FALSE'; } if (is_numeric($value) && is_float($value)) { return '(float)' . $value; } if (is_numeric($value) && is_int($value)) { return '(int)' . $value; } if (is_string($value)) { return '(string)' . $value; } if (is_object($value)) { return '(object)' . get_class($value) . '<pre>' . print_r($value, true) . '</pre>'; } return '(unknown)' . $value; }
Returns of what type the specific value is //TODO: use Debugger::exportVar() instead? @param mixed $value @return mixed Type (NULL, array, bool, float, int, string, object, unknown) + value
returns
php
dereuromark/cakephp-tools
config/bootstrap.php
https://github.com/dereuromark/cakephp-tools/blob/master/config/bootstrap.php
MIT
function extractFileInfo(string $filename, ?string $type = null) { $info = extractPathInfo($filename, $type); if ($info) { return $info; } $pos = strrpos($filename, '.'); $res = ''; switch ($type) { case 'extension': case 'ext': $res = ($pos !== false) ? substr($filename, $pos + 1) : ''; break; case 'filename': case 'file': $res = ($pos !== false) ? substr($filename, 0, $pos) : ''; break; default: break; } return $res; }
Focus is on the filename (without path) @deprecated Use native method instead @param string $filename to check on @param string|null $type (extension/ext, filename/file, basename/base, dirname/dir) @return mixed
extractFileInfo
php
dereuromark/cakephp-tools
config/bootstrap.php
https://github.com/dereuromark/cakephp-tools/blob/master/config/bootstrap.php
MIT
function extractPathInfo(string $filename, ?string $type = null, bool $fromUrl = false) { switch ($type) { case 'extension': case 'ext': $infoType = PATHINFO_EXTENSION; break; case 'filename': case 'file': $infoType = PATHINFO_FILENAME; break; case 'basename': case 'base': $infoType = PATHINFO_BASENAME; break; case 'dirname': case 'dir': $infoType = PATHINFO_DIRNAME; break; default: $infoType = $type; } $result = pathinfo($filename, $infoType); if ($fromUrl) { $pos = strpos($result, '#'); if ($pos !== false) { $result = substr($result, 0, $pos); } $pos = strpos($result, '?'); if ($pos !== false) { $result = substr($result, 0, $pos); } } return $result; }
Uses native PHP function to retrieve infos about a filename etc. Improves it by not returning non-file-name characters from url files if specified. So "filename.ext?foo=bar#hash" would simply be "filename.ext" then. @deprecated Use native method instead @param string $filename to check on @param string|null $type (extension/ext, filename/file, basename/base, dirname/dir) @param bool $fromUrl @return mixed
extractPathInfo
php
dereuromark/cakephp-tools
config/bootstrap.php
https://github.com/dereuromark/cakephp-tools/blob/master/config/bootstrap.php
MIT
public function change() { if ($this->table('tokens')->exists()) { $this->table('tokens') ->renameColumn('key', 'token_key') ->update(); return; } $this->table('tokens') ->addColumn('user_id', 'integer', [ 'limit' => null, 'null' => true, ]) ->addColumn('type', 'string', [ 'comment' => 'e.g.:activate,reactivate', 'default' => null, 'limit' => 20, 'null' => false, ]) ->addColumn('token_key', 'string', [ 'default' => null, 'limit' => 60, 'null' => false, ]) ->addColumn('content', 'string', [ 'comment' => 'can transport some information', 'default' => null, 'limit' => 255, 'null' => true, ]) ->addColumn('used', 'integer', [ 'default' => 0, 'limit' => null, 'null' => false, ]) ->addColumn('created', 'datetime', [ 'default' => null, 'limit' => null, 'null' => true, ]) ->addColumn('modified', 'datetime', [ 'default' => null, 'limit' => null, 'null' => true, ]) ->addIndex(['user_id']) ->addIndex(['token_key'], ['unique' => true]) ->create(); }
Change Method. More information on this method is available here: https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method @return void
change
php
dereuromark/cakephp-tools
config/Migrations/20200430170235_MigrationToolsTokens.php
https://github.com/dereuromark/cakephp-tools/blob/master/config/Migrations/20200430170235_MigrationToolsTokens.php
MIT
public static function roundTo($number, $increment = 1.0) { $precision = static::getDecimalPlaces($increment); $res = round($number, $precision); if ($precision <= 0) { $res = (int)$res; } return $res; }
Round value. @param float $number @param float $increment @return float result
roundTo
php
dereuromark/cakephp-tools
src/I18n/Number.php
https://github.com/dereuromark/cakephp-tools/blob/master/src/I18n/Number.php
MIT
public static function roundUpTo($number, int $increment = 1) { return ceil($number / $increment) * $increment; }
Round value up. @param float $number @param int $increment @return float|int Result
roundUpTo
php
dereuromark/cakephp-tools
src/I18n/Number.php
https://github.com/dereuromark/cakephp-tools/blob/master/src/I18n/Number.php
MIT
public static function roundDownTo($number, int $increment = 1) { return floor($number / $increment) * $increment; }
Round value down. @param float $number @param int $increment @return float result
roundDownTo
php
dereuromark/cakephp-tools
src/I18n/Number.php
https://github.com/dereuromark/cakephp-tools/blob/master/src/I18n/Number.php
MIT
public static function ageRange(int $year, ?int $month = null, ?int $day = null, int $steps = 1) { if ($month == null && $day == null) { $age = (int)date('Y') - $year - 1; } elseif ($day == null) { if ($month >= (int)date('m')) { $age = (int)date('Y') - $year - 1; } else { $age = (int)date('Y') - $year; } } else { if ($month > (int)date('m') || ($month == (int)date('m') && $day > (int)date('d'))) { $age = (int)date('Y') - $year - 1; } else { $age = (int)date('Y') - $year; } } if ($age % $steps == 0) { $lowerRange = $age - $steps + 1; $upperRange = $age; } else { $lowerRange = $age - ($age % $steps) + 1; $upperRange = $age - ($age % $steps) + $steps; } if ($lowerRange == $upperRange) { return $upperRange; } return [$lowerRange, $upperRange]; }
Rounded age depended on steps (e.g. age 16 with steps = 10 => "11-20") //FIXME //TODO: move to helper? @param int $year @param int|null $month @param int|null $day @param int $steps @return array<int>|int
ageRange
php
dereuromark/cakephp-tools
src/I18n/DateTime.php
https://github.com/dereuromark/cakephp-tools/blob/master/src/I18n/DateTime.php
MIT