undefined built in functions in Zend Studio 13 - php

I have created PHP7 project in Zend Studio 13 and I get warnings like this Call to undefined function 'dba_open'. Why Zend Studio didnt recognize these functions?
dba_open
dba_close
dba_fetch
mhash
Any ideas how to solve this?

Zend doesn't ship language support for all the extensions in Zend Studio.
The most efficient way of adding support for language entities provided by unsupported extensions is definitely creating stubs.
The description "stub" files for all supported PHP entities can be found in this directory:
/.metadata/.plugins/org.eclipse.php.core/language
And this is also the location where you should put your stub files.

Copy PHP code from below. Create a file DBA.php and put it into a folder
workspace/.metadata/.plugins/org.eclipse.php.core/__language__/languagecode/DBA.php
languagecode - 8 hex digit name
You won't be able to debug a code having those functions, but at least there will be no warnings anymore.
<?php
/**
dba_open() establishes a database instance for path with mode using handler.
#link http://php.net/manual/en/function.dba-open.php
#param path string <p>Commonly a regular path in your filesystem.</p>
#param mode string <p>It is r for read access, w for read/write access to an already existing database,
c for read/write access and database creation if it doesn't currently exist, and n for create,
truncate and read/write access. The database is created in BTree mode, other modes (like Hash or Queue)
are not supported.<br>
<strong>Note:</strong><br>
There can only be one writer for one database file. When you use dba on a web server and more than
one request requires write operations they can only be done one after another. Also read during write
is not allowed. The dba extension uses locks to prevent this.
</p>
#param handler string <p>The name of the handler which shall be used for accessing path. It is passed all
optional parameters given to dba_open() and can act on behalf of them.</p>
#return FALSE on failure or positive handle on success.
*/
function dba_open ( $path , $mode, $handler=null) {}
/**
* dba_exists() checks whether the specified key exists in the database.
* #link http://php.net/manual/en/function.dba-exists.php
*
* #param string $key <p>The key the check is performed for.</p>
* #param mixed $handle <p>The database handler, returned by dba_open() or dba_popen().</p>
* #return Returns TRUE if the key exists, FALSE otherwise.
*/
function dba_exists ( $key , $handle ) {}
/**
* dba_fetch() — Fetch data specified by key
* #link http://php.net/manual/en/function.dba-fetch.php
*
* #param string $key The key the data is specified by.
* <p><div><h3>Note:</h3></div>
* When working with inifiles this function accepts arrays as keys where index 0 is the group and index 1 is the value name. See: dba_key_split().
* </p>
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns the associated string if the key/data pair is found, FALSE otherwise.
*/
function dba_fetch ( $key , $handle ) {}
/**
* dba_fetch() — Fetch data specified by key
* #link http://php.net/manual/en/function.dba-fetch.php
*
* #param string $key The key the data is specified by.
* <p><div><h3>Note:</h3></div>
* When working with inifiles this function accepts arrays as keys where index 0 is the group and index 1 is the value name. See: dba_key_split().
* </p>
* #param $skip The number of key-value pairs to ignore when using cdb databases. This value is ignored for all other databases which do not support multiple keys with the same name.
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns the associated string if the key/data pair is found, FALSE otherwise.
*/
function dba_fetch ( $key , $skip , $handle ) {}
/**
* dba_delete — Delete DBA entry specified by key
* #link http://php.net/manual/en/function.dba-delete.php
*
* #param mixed $key The key of the entry which is deleted.
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns TRUE on success or FALSE on failure.
*/
function dba_delete ( $key , $handle ) {}
/**
* dba_replace — Replace or insert entry
* #link http://php.net/manual/en/function.dba-replace.php
*
* #param mixed $key The key of the entry to be replaced.
* #param mixed $value The value to be replaced.
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns TRUE on success or FALSE on failure.
*/
function dba_replace ( $key , $value , $handle ) {}
/**
* dba_insert() inserts the entry described with key and value into the database.
* #link http://php.net/manual/en/function.dba-insert.php
*
* #param string $key <p>The key of the entry to be inserted. If this key already exist in the database, this function will fail. Use dba_replace() if you need to replace an existent key.</p>
* #param string $value <p>The value to be inserted.</p>
* #param mixed $handle <p>The database handler, returned by dba_open() or dba_popen().</p>
*
* #return Returns TRUE on success or FALSE on failure.
*/
function dba_insert ( $key , $value , $handle ) {}
/**
* dba_firstkey() returns the first key of the database and resets the internal key pointer. This permits a linear search through the whole database.
*
* #link http://php.net/manual/en/function.dba-firstkey.php
*
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns the key on success or FALSE on failure.
*/
function dba_firstkey ( $handle ) {}
/**
* dba_nextkey() returns the next key of the database and advances the internal key pointer.
*
* #link http://php.net/manual/en/function.dba-nextkey.php
*
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return Returns the key on success or FALSE on failure.
*/
function dba_nextkey ( $handle ) {}
/**
*
* #link http://php.net/manual/en/function.dba-close.php
*
* #param mixed $handle The database handler, returned by dba_open() or dba_popen().
* #return No value is returned.
*/
function dba_close ( $handle ) {}

Related

Remove cache files in Laravel

I am beginner in Laravel.
I use in my project Laravel 7.
I have cache system in my project.
I have cache in my project with keys:
category
category.id
category.subcategory.id
product.all
etc.
I need function to remove cache.
I write this:
private function deleteCache(string $keyToRemove)
{
Cache::forget($keyToRemove);
}
Is universal cache removal possible?
I need a function that will be
Remove selected keys:
deleteCache(['category.100', 'product.all', 'category.1'])
Remove all cache with category (for example: category.1, category.all, category, category.tree, category.subcategory.1 etc).
deleteCache(['category.*'])
How can I make it?
TL:DR What you need is not available by default, you need customized, wrapper methods that requires "technical" knowledge about the cache driver(underlying technology) you choose.
Laravel cache supports multiple technologies(drivers) including redis, database, file, memcached etc. All these drivers implement the same interface.
namespace Illuminate\Contracts\Cache;
interface Store
{
/**
* Retrieve an item from the cache by key.
*
* #param string|array $key
* #return mixed
*/
public function get($key);
/**
* Retrieve multiple items from the cache by key.
*
* Items not found in the cache will have a null value.
*
* #param array $keys
* #return array
*/
public function many(array $keys);
/**
* Store an item in the cache for a given number of minutes.
*
* #param string $key
* #param mixed $value
* #param float|int $minutes
* #return void
*/
public function put($key, $value, $minutes);
/**
* Store multiple items in the cache for a given number of minutes.
*
* #param array $values
* #param float|int $minutes
* #return void
*/
public function putMany(array $values, $minutes);
/**
* Increment the value of an item in the cache.
*
* #param string $key
* #param mixed $value
* #return int|bool
*/
public function increment($key, $value = 1);
/**
* Decrement the value of an item in the cache.
*
* #param string $key
* #param mixed $value
* #return int|bool
*/
public function decrement($key, $value = 1);
/**
* Store an item in the cache indefinitely.
*
* #param string $key
* #param mixed $value
* #return void
*/
public function forever($key, $value);
/**
* Remove an item from the cache.
*
* #param string $key
* #return bool
*/
public function forget($key);
/**
* Remove all items from the cache.
*
* #return bool
*/
public function flush();
/**
* Get the cache key prefix.
*
* #return string
*/
public function getPrefix();
}
Depending on the driver you choose - you need customized methods to achieve what you need.
For your first question, the following method would be useful to remove multiple keys.
public function deleteCache(array $keys)
{
foreach ($keys as $key) {
Cache::forget($key);
}
}
I am familiar with redis so i will give examples around it. If you are going to use redis as cache driver - it is better to modify that method like this; Since redis's delete command supports deleting multiple keys at once. This one is more effective than the previous one.
public function deleteCache(array $keys)
{
Redis::del($keys);
}
One trick is to be careful about cache prefix. If you are using cache prefix(defined in your cache config file) - then you need to prepend those prefix to keys.
For your second question(Remove all cache with category) there are several ways to do it but some of them wouldn't be performance/production friendly. In redis you may execute some command such as keys or scan to iterate through database and then invoke the previously defined method with the returned results.
Especially keys command should only be used in production environments with extreme care.
redis key
redis scan
Redis is only example - if you are going to use database cache driver - then you need to implement methods to satisfy your case. It will require technical knowledge about the both how laravel implements it via database(tables, queries etc) and how your extended methods will use it(tables, queries, columns, indexes etc)

Specify an array index type [duplicate]

This question already has answers here:
Best way to document Array options in PHPDoc?
(9 answers)
Closed 1 year ago.
How can I specify an array index and sub-index type? Note: I will use it with PHPStorm.
Array example:
function name ($options) {
// $options['length'] => integer
// $options['more'] => array
// $options['more']['test1'] => boolean
// $options['more']['test2'] => boolean
}
Example (that not works):
/**
* #param array $options
* #var int $length
* #var array $more
* #var bool $test1
* #var bool $test2
*/
In general, PhpStorm only support simple syntax, just as Sam has stated, e.g.
/**
* #param string[] $options
*/
The code above described parameter which is array of strings.
Install Options completion plugin -- it supports new proposed syntax for hashes (describing array keys and its' types) in PHPDoc: https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#7-describing-hashes
This plugin will add code completion for array keys.
<?php
class Element {
/**
* Initializes this class with the given options.
*
* #param array $options {
* #var bool $required Whether this element is required
* #var string $label The display name for this element
* }
*/
public function __construct(array $options = array())
{
// some code here
}
}
new Element(['label' => 'Bob', '|' ]);
// | Ctrl+Space will show supported attributes
NOTE: Main purpose of this plugin is to offer array keys completion -- I'm not sure how well it supports type resolutions for each of array elements (in case if they are different like in your example).
It looks like, according to the docs, that it's only possible to define an array as a set of one specific type (instead of setting a type for each index):
/**
* #param string[] $options
*/
The better solution would probably be to make $options a class, so length and test1 could be properties with default values and pre-defined types.

How to doc a variable number of parameters

How do I doc a variable number of parameters? I am writing an application in PHP and JavaScript. Currently I have (in JavaScript):
/**
* Description
* #param {String} description
*/
function fn()
{
// arguments holds all strings.
}
So, how do I doc n-number of string params?
E.g. PhpDocumentor suggests using an ellipsis
/**
* Example of unlimited parameters.
* Returns a formatted var_dump for debugging purposes
* (since the recurrences of $v are not listed in the actual function signature in the code,
* you may wish to highlight they are "optional" in their description)
* #param string $s string to display
* #param mixed $v variable to display with var_dump()
* #param mixed $v,... unlimited OPTIONAL number of additional variables to display with var_dump()
*/
function fancy_debug($s,$v)
{

facebook set_status facebook api

I have
$facebook->api_client->status_set('is the Eagle has landed.','');
as part of a test page, and i get errors
Call to undefined method FacebookRestClient::status_set()
please help, thank you
Did you even bother opening up the file and looking at the available methods?
Copy/pasted from the SDK
/**
* Sets the users' current status message. Message does NOT contain the
* word "is" , so make sure to include a verb.
*
* Example: setStatus("is loving the API!")
* will produce the status "Luke is loving the API!"
*
* #param string $status text-only message to set
* #param int $uid user to set for (defaults to the
* logged-in user)
* #param bool $clear whether or not to clear the status,
* instead of setting it
* #param bool $status_includes_verb if true, the word "is" will *not* be
* prepended to the status message
*
* #return boolean
*/
public function &users_setStatus($status,
$uid = null,
$clear = false,
$status_includes_verb = true) {
So, in usage
$facebook->api_client->users_setStatus( $status, $uid, $clear, $status_includes_verb );

How to document an accessor/mutator method in phpDoc/javaDoc?

Given a function which behaves as either a mutator or accessor depending on the arguments passed to it, like this:
// in PHP, you can pass any number of arguments to a function...
function cache($cacheName) {
$arguments = func_get_args();
if (count($arguments) >= 2) { // two arguments passed. MUTATOR.
$value = $arguments[1]; // use the second as the value
$this->cache[$cacheName] = $value; // *change* the stored value
} else { // 1 argument passed, ACCESSOR
return $this->cache[$cacheName]; // *get* the stored value
}
}
cache('foo', 'bar'); // nothing returned
cache('foo') // 'bar' returned
How do you document this in PHPDoc or a similar automated documentation creator? I had originally just written it like this:
/**
* Blah blah blah, you can use this as both a mutator and an accessor:
* As an accessor:
* #param $cacheName name of the variable to GET
* #return string the value...
*
* As a mutator:
* #param $cacheName name of the variable to SET
* #param $value the value to set
* #return void
*/
However, when this is run through phpDoc, it complains because there are 2 return tags, and the first #param $cacheName description is overwritten by the second.
Is there a way around this?
as you found out, you cannot document 2 different signatures of a single function. what you can do, however - if you use phpDocumentor -, is to document optional function parameters and multiple possible return types:
/**
* Blah blah blah, you can use this as both an accessor and a mutator, e.g.
* <code>cache('name') // get cache value</code>
* and
* <code>cache('name', 'value') // set new cache value</code>.
*
* #param string $cacheName name of the variable to GET|SET
* #param string $value optional new value
*
* #return string|void value of $cacheName or, in case of mutator, void
*/
for clarity, i would also include the usage example.

Categories