idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
6,000
public function is ( $ role , $ all = true ) { if ( ! $ this -> check ( ) ) { return false ; } return $ this -> lockdown -> is ( $ this -> getUserId ( ) , $ role , $ all ) ; }
Is the user a member of this role?
6,001
public function has ( $ permission , $ all = true ) { if ( ! $ this -> check ( ) ) { return false ; } return $ this -> lockdown -> has ( $ this -> getUserId ( ) , $ permission , $ all ) ; }
Does the user have this permission?
6,002
protected function convertClassParamToClassName ( $ configuration ) { if ( ! $ configuration instanceof ParamConverterConfig ) { return ; } if ( preg_match ( '/^%(.*)%$/' , $ configuration -> getClass ( ) , $ matches ) ) { $ param = $ this -> container -> getParameter ( $ matches [ 1 ] ) ; $ configuration -> setClass (...
Converts a Class parameter to a class name
6,003
public function dispatch ( $ method , $ args = array ( ) ) { if ( is_callable ( array ( $ this , $ method ) ) ) { $ response = call_user_func_array ( array ( $ this , $ method ) , $ args ) ; } else { throw new InvalidMethodException ( 'Invalid controller method ' . $ method ) ; } if ( $ response instanceof Response ) {...
Dispatches a Controller action .
6,004
public function process ( Request $ request , $ next ) { $ this -> adaptorNext = $ next ; return $ this -> run ( $ request ) ; }
PSR15 single - pass entrypoint .
6,005
public function applyPatch ( Patch $ patch , PackageInterface $ package ) { $ this -> io -> write ( '<info>Applying patch ' . $ patch -> getFromPackage ( ) -> getName ( ) . '/' . $ patch -> getDescription ( ) . ' to ' . $ package -> getName ( ) . '... </info>' , false ) ; $ baseDirectory = $ this -> installationManager...
Apply a patch to a package .
6,006
public function getPossibleCalls ( ReflectionParameter ... $ params ) : array { if ( ! count ( $ params ) ) { return [ [ ] ] ; } $ options = [ ] ; $ opts = [ ] ; $ annotations = new Annotations ( $ this ) ; foreach ( $ params as $ i => $ param ) { if ( ! $ param -> hasType ( ) ) { if ( isset ( $ annotations [ 'param' ]...
Return an array of all possible combinations of variable types .
6,007
public function getPossibleReturnTypes ( ) : array { $ types = [ ] ; if ( $ this -> hasReturnType ( ) ) { $ types [ ] = $ this -> getReturnType ( ) ; if ( $ types [ 0 ] -> allowsNull ( ) ) { $ types [ ] = null ; } } return $ types ; }
Returns an array of all possible return types as instances of Monomelodies \ Reflex \ ReflectionType .
6,008
protected function buildTransportConfig ( ) { switch ( $ this -> transport ) { case Module :: TRANSPORT_SMTP : { return [ 'class' => 'Swift_SmtpTransport' , 'host' => $ this -> smtpHost , 'username' => $ this -> smtpUsername , 'password' => $ this -> smtpPassword , 'port' => $ this -> smtpPort , 'encryption' => $ this ...
Build transport configurations by transport type
6,009
public function getTotal ( ) { $ rawQuery = "SELECT count(*) as total FROM orders" ; $ rawResults = DB :: select ( DB :: raw ( $ rawQuery ) ) ; return $ rawResults [ 0 ] -> total ; }
Get the total count of this repository .
6,010
protected function Init ( ) { $ submit = ContentSubmit :: Schema ( ) -> ByContent ( $ this -> Content ( ) ) ; $ this -> value = $ submit -> GetValue ( ) ; $ this -> name = $ submit -> GetName ( ) ; $ this -> id = $ this -> CssID ( ) ; $ this -> classes = $ this -> CssClass ( ) ; return parent :: Init ( ) ; }
Initializes the submit element
6,011
public function createConnection ( $ parameters ) { $ path = FileUtils :: normalizePath ( $ parameters [ 'database' ] ) ; $ connection = new \ PDO ( 'sqlite:' . $ path ) ; return $ connection ; }
Creates an SQLiteConnection
6,012
public function load ( Repo $ repo ) { $ id = $ repo -> getId ( ) ; $ this -> client -> fetchRepository ( $ repo ) ; $ repo -> setId ( $ id ) ; return $ repo ; }
Load travis infos for repository
6,013
public function performCheck ( ) { $ this -> emailCheck ( $ this -> getEmailSendCheck ( ) , self :: EMAIL_SEND_CHECK_MSG ) ; $ this -> emailCheck ( $ this -> getEmailReceiveCheck ( ) , self :: EMAIL_RECEIVE_CHECK_MSG ) ; }
Check email send&receive .
6,014
public function sanitizeString ( $ str , $ min = null , $ max = null ) : string { $ pattern = '/(;|\||`|>|<|&|^|"|' . "\n|\r|'" . '|{|}|[|]|\)|\()/i' ; $ str = preg_replace ( $ pattern , '' , $ str ) ; $ str = preg_replace ( '/\$/' , '\\\$' , $ str ) ; if ( $ this -> isValidStringLength ( $ str , $ min , $ max ) ) { re...
Sanitize a string .
6,015
public function integerIsBetween ( int $ integer , int $ min , int $ max ) : bool { return ( ( $ integer >= $ min ) && ( $ integer <= $ max ) ) ; }
Check if integer is between MAX and MIN .
6,016
public function getStringPositionX ( $ haystack , $ needle , $ number = 1 ) : int { if ( 1 === $ number ) { return ( int ) strpos ( $ haystack , $ needle ) ; } elseif ( 1 < $ number ) { return ( int ) strpos ( $ haystack , $ needle , $ this -> getStringPositionX ( $ haystack , $ needle , $ number - 1 ) + strlen ( $ nee...
Find the position of the Xth occurrence of a substring in a string .
6,017
public function isInteger ( $ number , int $ min = null , int $ max = null ) : bool { return isset ( $ min ) || isset ( $ max ) ? filter_var ( $ number , FILTER_VALIDATE_INT , $ this -> getIntegerOptionsBetween ( $ min , $ max ) ) : filter_var ( $ number , FILTER_VALIDATE_INT ) ; }
Validate as integer .
6,018
private function queryFor ( MapInterface $ entities ) : Query { $ query = new Query \ Query ; $ this -> variables = new Stream ( 'string' ) ; $ partitions = $ entities -> partition ( function ( Identity $ identity , object $ entity ) : bool { $ meta = ( $ this -> metadata ) ( \ get_class ( $ entity ) ) ; return $ meta ...
Build the query to delete all entities at once
6,019
private function matchRelationship ( Identity $ identity , object $ entity , Query $ query ) : Query { $ meta = ( $ this -> metadata ) ( \ get_class ( $ entity ) ) ; $ name = $ this -> name -> sprintf ( \ md5 ( $ identity -> value ( ) ) ) ; $ this -> variables = $ this -> variables -> add ( ( string ) $ name ) ; return...
Add clause to match the relationship we want to delete
6,020
private function matchAggregate ( Identity $ identity , object $ entity , Query $ query ) : Query { $ meta = ( $ this -> metadata ) ( \ get_class ( $ entity ) ) ; $ name = $ this -> name -> sprintf ( \ md5 ( $ identity -> value ( ) ) ) ; $ this -> variables = $ this -> variables -> add ( ( string ) $ name ) ; $ query =...
Add clause to match the node we want to delete and all of its children
6,021
public function logQuery ( $ path , $ method , $ data , $ time , $ connection = array ( ) , $ query = array ( ) , $ engineTime = 0 , $ itemCount = 0 ) { if ( $ this -> debug ) { $ e = new Exception ( ) ; $ this -> queries [ ] = array ( 'path' => $ path , 'method' => $ method , 'data' => $ data , 'executionMS' => $ time...
Logs a query .
6,022
public function match ( Request $ request ) { $ method = $ request -> httpmethod ( ) ; if ( strtoupper ( $ method ) != strtoupper ( $ this -> method ) ) { return false ; } $ regex = $ this -> uriRegex ( $ this -> uri ) ; $ path = parse_url ( trim ( $ request -> uri ( ) , '#' ) , PHP_URL_PATH ) ; $ match = preg_match ( ...
check is match
6,023
public function openOrchestraCss ( $ themeId ) { $ tags = '' ; if ( isset ( $ this -> themes [ $ themeId ] ) && isset ( $ this -> themes [ $ themeId ] [ 'stylesheets' ] ) ) { $ stylesheets = $ this -> themes [ $ themeId ] [ 'stylesheets' ] ; foreach ( $ stylesheets as $ stylesheet ) { $ tags .= $ this -> getHtmlTag ( $...
Return the html tags including the css from the theme
6,024
public function openOrchestraJs ( $ themeId ) { $ tags = '' ; if ( isset ( $ this -> themes [ $ themeId ] ) && isset ( $ this -> themes [ $ themeId ] [ 'javascripts' ] ) ) { $ javascripts = $ this -> themes [ $ themeId ] [ 'javascripts' ] ; foreach ( $ javascripts as $ javascript ) { $ tags .= $ this -> getHtmlTag ( $ ...
Return the html tags to include js files from the theme
6,025
protected function getHtmlTag ( $ file , $ fileType ) { list ( $ bundleName , $ themeName , $ filePath ) = explode ( ':' , $ file ) ; $ assetsPath = $ this -> assetsHelper -> getUrl ( $ themeName . DIRECTORY_SEPARATOR . $ filePath , $ bundleName ) ; switch ( $ fileType ) { case self :: FILETYPE_CSS : $ tag = '<link typ...
Generate html tag for a javascript or stylesheet asset
6,026
public static function matchCookieDomain ( $ cookieDomain , $ host ) { if ( ! $ cookieDomain ) { throw new Zend_Http_Exception ( "\$cookieDomain is expected to be a cookie domain" ) ; } if ( ! $ host ) { throw new Zend_Http_Exception ( "\$host is expected to be a host name" ) ; } $ cookieDomain = strtolower ( $ cookieD...
Check if a cookie s domain matches a host name .
6,027
public static function matchCookiePath ( $ cookiePath , $ path ) { if ( ! $ cookiePath ) { throw new Zend_Http_Exception ( "\$cookiePath is expected to be a cookie path" ) ; } if ( ! $ path ) { throw new Zend_Http_Exception ( "\$path is expected to be a host name" ) ; } return ( strpos ( $ path , $ cookiePath ) === 0 )...
Check if a cookie s path matches a URL path
6,028
public function discover ( $ directory , $ base_namespace ) { if ( is_string ( $ directory ) ) { $ directory = [ $ directory ] ; } return $ this -> doDiscovery ( $ directory , $ base_namespace ) ; }
Run console form discovery .
6,029
protected function doDiscovery ( array $ directories , $ base_namespace ) { $ forms = [ ] ; $ filter = $ this -> filterByNamespace ( $ base_namespace ) ; foreach ( $ this -> searchFiles ( $ directories , $ filter ) as $ file ) { $ ext = $ file -> getExtension ( ) ; $ classname = $ base_namespace . '\\' . $ file -> getB...
Do form discovery .
6,030
protected function searchFiles ( array $ directories , $ filter = null ) { $ finder = new Finder ( ) ; $ finder -> files ( ) -> name ( '*.php' ) -> in ( $ directories ) -> depth ( $ this -> depth ) ; if ( isset ( $ filter ) && is_callable ( $ filter ) ) { $ finder -> filter ( $ filter ) ; } return $ finder ; }
Finder search files .
6,031
protected function filterByNamespace ( $ namespace ) { return function ( $ file ) use ( $ namespace ) { $ content = file_get_contents ( $ file ) ; $ tokens = token_get_all ( $ content ) ; $ count = count ( $ tokens ) ; $ token_namespace = null ; for ( $ i = 0 ; $ i < $ count ; ++ $ i ) { $ token = $ tokens [ $ i ] ; if...
Filter by class namespace .
6,032
public function updateAction ( $ data , $ object ) { return $ this -> forward ( ) -> dispatch ( $ this -> getEvent ( ) -> getRouteMatch ( ) -> getParam ( 'controller' ) , [ 'action' => 'notFound' ] ) ; }
Updates persitence object
6,033
protected function takeAttributeFromDOM ( $ attribute ) { switch ( $ attribute -> localName ) { case 'seconds' : $ this -> _seconds = $ attribute -> nodeValue ; break ; default : parent :: takeAttributeFromDOM ( $ attribute ) ; } }
Given a DOMNode representing an attribute tries to map the data into instance members . If no mapping is defined the name and valueare stored in an array .
6,034
public static function make ( $ path , $ variables = [ ] , $ include_once = false ) { $ view_path = self :: find ( $ path ) ; if ( Arr :: iterable ( $ variables ) ) { extract ( $ variables ) ; } ob_start ( ) ; if ( $ include_once ) { include_once $ view_path ; } else { include $ view_path ; } return ob_get_clean ( ) ; ...
Include file with scoped variables
6,035
private static function find ( $ path ) { $ view_path = null ; foreach ( self :: $ directories as $ directory ) { $ formatted_path = self :: formatPath ( $ directory . '/' . $ path ) ; if ( self :: isValidPath ( $ formatted_path ) ) { $ view_path = $ formatted_path ; break ; } } if ( empty ( $ view_path ) ) { if ( self...
Find matching view
6,036
public function check ( ) { $ siteroots = $ this -> siterootManager -> findAll ( ) ; if ( ! count ( $ siteroots ) ) { $ problem = new Problem ( ) ; $ problem -> setId ( 'siteroots_no_siteroots' ) -> setCheckClass ( __CLASS__ ) -> setSeverity ( Problem :: SEVERITY_WARNING ) -> setMessage ( 'No Siteroots defined.' ) -> s...
Check for problems .
6,037
protected function removeKeyFromJsonData ( $ key , & $ getJsonData ) { $ this -> crontab -> remove ( ( int ) ltrim ( $ key , 'ID' ) ) ; if ( isset ( $ getJsonData [ $ key ] ) ) { unset ( $ getJsonData [ $ key ] ) ; } }
Protected remove key from json data
6,038
public function register ( $ key , $ object ) { $ this -> _registry [ $ key ] = $ this -> _memoize ( $ object ) ; return $ this ; }
Registers an object for later retrieval by key . Any existing key is overwritten .
6,039
public function trigger ( $ keys , $ callable ) { $ keys = is_array ( $ keys ) ? $ keys : array ( $ keys ) ; foreach ( $ keys as $ key ) { $ this -> _triggers [ $ key ] = $ callable ; } return $ this ; }
Sets a closure that is called on a lookup miss
6,040
public function setFrom ( $ value ) { if ( is_array ( $ value ) ) { $ value = new Person ( $ value ) ; } return $ this -> setParameter ( 'from' , $ value ) ; }
Set document from
6,041
public function setItems ( $ value ) { if ( is_array ( $ value ) ) { $ bag = new Bag ( ) ; foreach ( $ value as $ itemParameters ) { $ bag -> add ( new Item ( $ itemParameters ) ) ; } $ value = $ bag ; } return $ this -> setParameter ( 'items' , $ value ) ; }
Set invoice items
6,042
public function getTaxes ( ) { $ taxesList = [ ] ; foreach ( $ this -> getItems ( ) as $ item ) { foreach ( $ item -> getTaxes ( ) as $ tax ) { $ taxKey = md5 ( $ tax -> getName ( ) . $ tax -> getType ( ) . $ tax -> getRate ( ) ) ; if ( ! isset ( $ taxesList [ $ taxKey ] ) ) { $ newTax = new Tax ( [ 'type' => $ tax -> ...
Get invoice taxes
6,043
public function setDiscounts ( $ value ) { if ( is_array ( $ value ) ) { $ bag = new Bag ( ) ; foreach ( $ value as $ discountParameters ) { $ bag -> add ( new Discount ( $ discountParameters ) ) ; } $ value = $ bag ; } return $ this -> setParameter ( 'discounts' , $ value ) ; }
Set invoice discounts
6,044
public function getSubtotal ( ) { $ subtotal = 0 ; foreach ( $ this -> getItems ( ) as $ item ) { $ subtotal += $ item -> getQuantity ( ) * $ item -> getPrice ( ) ; } return $ subtotal ; }
Get invoice subtotal
6,045
public function getTaxesAmount ( ) { $ taxesAmount = 0 ; foreach ( $ this -> getTaxes ( ) as $ tax ) { $ taxesAmount += $ tax -> getAmount ( $ tax -> getBaseAmount ( ) ) ; } return $ taxesAmount ; }
Get invoice taxes amount
6,046
public function getDiscountsAmount ( ) { $ discountsAmount = 0 ; if ( count ( $ this -> getDiscounts ( ) ) ) { foreach ( $ this -> getDiscounts ( ) as $ discount ) { $ discountsAmount += $ discount -> getAmount ( ) ; } } else { foreach ( $ this -> getItems ( ) as $ item ) { $ discountsAmount += $ item -> getDiscount ( ...
Get ticket discounts amount
6,047
public function run ( ) { $ searchModel = $ this -> newSearchModel ( ) ; $ dataProvider = $ this -> dataProvider ( $ searchModel ) ; return $ this -> controller -> render ( $ this -> view , [ $ this -> nameVariableModel => $ searchModel , $ this -> nameVariableDataProvider => $ dataProvider , ] ) ; }
Displays models list .
6,048
public function getSource ( ) { $ targets = array_map ( 'strtolower' , $ this -> getTargets ( ) ) ; $ nick = strtolower ( $ this -> getConnection ( ) -> getNickname ( ) ) ; if ( in_array ( $ nick , $ targets ) ) { return $ this -> getNick ( ) ; } return reset ( $ targets ) ; }
Returns the source of this event .
6,049
private function init ( ) { $ this -> headers [ 'Date' ] = date ( 'r' ) ; $ allowReply = true ; if ( defined ( 'REPLYEMAIL' ) ) { $ sendEmail = REPLYEMAIL ; $ allowReply = false ; } else if ( defined ( 'ADMINEMAIL' ) ) { $ sendEmail = ADMINEMAIL ; } else { return ; } if ( defined ( 'SITENAME' ) ) { $ this -> setSender ...
Initialize the object
6,050
public function setHeader ( $ key , $ value ) { if ( ! isset ( $ this -> headers [ $ key ] ) ) { throw new \ Exception ( 'UnknownHeader' ) ; return false ; } $ this -> headers [ $ key ] = $ value ; }
Set the value of a header
6,051
public function removeFile ( $ filename ) { if ( ( $ key = array_search ( $ filename , $ this -> attachedFiles ) ) === false ) { throw new \ Exception ( 'FileNotContained' ) ; } unset ( $ this -> attachedFiles [ $ key ] ) ; }
Remove a file from the files list
6,052
public function setText ( $ text ) { if ( ! is_string ( $ text ) ) { throw new \ Exception ( 'RequireStringParameter' ) ; } $ this -> setTEXTBody ( strip_tags ( $ text ) ) ; $ this -> setHTMLBody ( nl2br ( $ text ) ) ; }
Set the mail content
6,053
public function setSender ( $ senderEmail , $ senderName = null , $ allowReply = true ) { $ this -> setHeader ( 'From' , $ senderName === NULL ? $ senderEmail : static :: escapeB64 ( $ senderName ) . ' <' . $ senderEmail . '>' ) ; $ this -> setHeader ( 'Sender' , $ senderEmail ) ; if ( $ allowReply && empty ( $ this ->...
Set the Sender value of the mail
6,054
public function getBoundary ( $ boundaryInd = 0 ) { if ( empty ( $ this -> mimeBoundary [ $ boundaryInd ] ) ) { $ this -> mimeBoundary [ $ boundaryInd ] = 'ORPHEUS_' . md5 ( microtime ( 1 ) + $ boundaryInd ) ; } return $ this -> mimeBoundary [ $ boundaryInd ] ; }
Get a boundary
6,055
public function registerCSRFString ( ) { mt_srand ( time ( ) ) ; $ string = md5 ( mt_rand ( ) . '_' . time ( ) . '_' . mt_rand ( ) . '_' . mt_rand ( ) ) ; $ _SESSION [ $ this -> csrfTokenString ] = $ string ; }
register csrf string
6,056
public function setEncoding ( $ encoding , $ convertEncoding = null ) { $ supportedEncodings = static :: getSupportedEncodings ( ) ; $ encodingUpper = strtoupper ( $ encoding ) ; if ( ! in_array ( $ encodingUpper , $ supportedEncodings ) ) { throw new Exception \ InvalidArgumentException ( 'Wrapper doesn\'t support cha...
Set character encoding working with and convert to
6,057
public function call ( ServerRequestInterface $ request , DelegateInterface $ delegate ) { return $ this -> middleware -> process ( $ request , $ delegate ) ; }
Call the associate middleware .
6,058
public function isValidLoginToken ( string $ loginToken ) : bool { $ hashes = $ this -> getTokenHashes ( ) ; if ( $ hashes === null ) { return false ; } else { return password_verify ( $ loginToken , $ hashes [ "login_hash" ] ) ; } }
Checks if a give login token is valid
6,059
public function isValidApiToken ( string $ apiToken ) : bool { $ hashes = $ this -> getTokenHashes ( ) ; if ( $ hashes === null ) { return false ; } else { return password_verify ( $ apiToken , $ hashes [ "api_hash" ] ) ; } }
Checks if a give API token is valid
6,060
public function getTokenHashes ( ) : ? array { $ stmt = $ this -> db -> prepare ( "SELECT login_hash, api_hash FROM sessions WHERE user_id=?" ) ; $ stmt -> bind_param ( "i" , $ this -> user -> id ) ; $ stmt -> execute ( ) ; return $ stmt -> get_result ( ) -> fetch_array ( MYSQLI_ASSOC ) ; }
Retrieves the login and API token hashes from the database
6,061
public function login ( ) : string { $ token = bin2hex ( random_bytes ( 64 ) ) ; $ loginHash = password_hash ( $ token , PASSWORD_BCRYPT ) ; $ stmt = $ this -> db -> prepare ( "INSERT INTO sessions (user_id, login_hash, api_hash) " . "VALUES (?, ?, NULL) " . "ON DUPLICATE KEY UPDATE login_hash=?;" ) ; $ stmt -> bind_pa...
Logs the user in . Generates a new login session token and stores the corresponding hash in the database
6,062
public function storeApiKey ( string $ apiKey ) { $ hash = password_hash ( $ apiKey , PASSWORD_BCRYPT ) ; $ stmt = $ this -> db -> prepare ( "INSERT INTO sessions (user_id, login_hash, api_hash) " . "VALUES (?, NULL, ?) " . "ON DUPLICATE KEY UPDATE api_hash=?;" ) ; $ stmt -> bind_param ( "iss" , $ this -> user -> id , ...
Stores a hash of a new API key in the database . The previously stored hash will be deleted
6,063
public function wipeLoginSession ( ) { $ stmt = $ this -> db -> prepare ( "DELETE FROM sessions WHERE user_id = ?;" ) ; $ stmt -> bind_param ( "i" , $ this -> user -> id ) ; $ stmt -> execute ( ) ; $ this -> db -> commit ( ) ; }
Deletes the Login token hash from the database
6,064
public function set ( $ html_string ) { $ libxml_use_internal_errors = libxml_use_internal_errors ( true ) ; $ this -> loadHtml ( '<?xml encoding="UTF-8">' . $ html_string ) ; libxml_use_internal_errors ( $ libxml_use_internal_errors ) ; $ this -> xpath = new \ DOMXPath ( $ this ) ; }
Set the HTML source you want to work with .
6,065
public function query ( $ css_selector ) { $ xpath_selector = $ this -> _css_toxpath_selector ( $ css_selector ) ; $ nodelist = $ this -> xpath -> query ( $ xpath_selector ) ; return $ nodelist ; }
Return found nodes for a given CSS or XPATH selector .
6,066
public function exists ( $ css_selector ) { $ xpath_selector = $ this -> _css_toxpath_selector ( $ css_selector ) ; $ nodelist = $ this -> xpath -> query ( $ xpath_selector ) ; if ( $ nodelist -> item ( 0 ) === null ) return false ; return true ; }
Check if a selector exists .
6,067
public function delete ( $ css_selector ) { $ xpath_selector = $ this -> _css_toxpath_selector ( $ css_selector ) ; $ nodelist = $ this -> xpath -> query ( $ xpath_selector ) ; if ( $ nodelist -> item ( 0 ) === null ) return 0 ; $ counter = 0 ; foreach ( $ nodelist as $ node ) { $ counter ++ ; $ node -> parentNode -> r...
Removes all matched elements from the HTML source .
6,068
public function get ( ) { foreach ( $ this -> childNodes as $ item ) { if ( $ item -> nodeType == XML_PI_NODE ) { $ this -> removeChild ( $ item ) ; break ; } } return $ this -> saveHtml ( ) ; }
Returns the current state of the HTML source .
6,069
protected function _css_toxpath_selector ( $ css_selector ) { $ xpath = $ css_selector ; if ( strpos ( $ xpath , 'xpath:' ) !== false ) return substr ( $ xpath , 6 ) ; $ xpath = preg_replace ( '/([a-z0-9_-])\s+([a-z0-9_-])/' , '$1//$2' , $ xpath ) ; $ xpath = preg_replace ( '/\s*>\s*/' , '/' , $ xpath ) ; $ xpath = pre...
Converts a CSS selector to a XPATH 1 . 0 selector . It does not support all CSS selectors but the most .
6,070
public static function generateSpyClassRepresenting ( $ type ) { $ spyClassName = str_replace ( '\\' , '_' , $ type ) . '_NarkSpy' ; if ( in_array ( $ spyClassName , self :: $ loadedSpyClasses ) ) { return "\\Nark\\{$spyClassName}" ; } if ( class_exists ( $ type ) ) { $ spyClassCode = self :: createSpyClassExtendingCla...
Generates and loads code for a spy double extending a given class or implementing a given interface and returns the name of the generated class
6,071
private static function getSpyBaseCode ( ) { if ( empty ( self :: $ baseClassCode ) ) { $ spyBaseClassFile = dirname ( __FILE__ ) . '/SpyBase.php' ; self :: $ baseClassCode = new UnorderedList ( file ( $ spyBaseClassFile , FILE_IGNORE_NEW_LINES ) ) ; } return self :: $ baseClassCode -> toArray ( ) ; }
Returns an array of source lines for the SpyBase class . This class is used as the base code for all generated spy classes . This class is modified based on the interface or class we want to spy on before it is loaded .
6,072
private static function createSpyClassExtendingClass ( $ spyClassName , $ baseClassName ) { $ spyClassCode = self :: getSpyBaseCode ( ) ; $ spyClassCode [ self :: CLASS_NAME_LINE_INDEX ] = str_replace ( 'SpyBase' , "{$spyClassName} extends {$baseClassName}" , $ spyClassCode [ self :: CLASS_NAME_LINE_INDEX ] ) ; $ spyCl...
Creates the source for a spy class extending a given concerete or abstract class
6,073
private static function getSpyClassCodeLinesWithOverriddenMethodsForClassOrInterface ( array $ spyClassCode , $ classOrInterface ) { $ reflection = new ReflectionClass ( $ classOrInterface ) ; $ baseClassPublicMethods = $ reflection -> getMethods ( ReflectionMethod :: IS_PUBLIC ) ; $ baseClassMethodsThatMustBeOverridde...
Loads an array of source code lines for the SpyBase class with method overrides from the given class or interface name
6,074
private static function getReflectedMethodAsSpyClassCode ( ReflectionMethod $ method ) { $ methodName = $ method -> getName ( ) ; if ( $ methodName === '__construct' ) { return "// can't override constructor in generated spy class" ; } if ( $ methodName === '__call' ) { return "// __call magic method not carried over f...
Converts a given reflection method to source code to be injected into the SpyBase class to ensure it passes as an instance of a given interface or class
6,075
private static function createSpyClassImplementingInterface ( $ spyClassName , $ interfaceName ) { $ spyClassCode = self :: getSpyBaseCode ( ) ; $ spyClassCode [ self :: CLASS_NAME_LINE_INDEX ] = str_replace ( 'SpyBase' , "{$spyClassName} implements {$interfaceName}" , $ spyClassCode [ self :: CLASS_NAME_LINE_INDEX ] )...
Creates the source for a spy class implementing a given interface
6,076
public function getLinkToAction ( $ actionName , $ params , $ pk_link = false ) { $ action = isset ( $ params [ 'action' ] ) ? $ params [ 'action' ] : 'List' . sfInflector :: camelize ( $ actionName ) ; $ url_params = $ pk_link ? '?' . $ this -> getPrimaryKeyUrlParams ( ) : '\'' ; $ params [ 'icon' ] = ( isset ( $ para...
Returns HTML code for an action link .
6,077
public function calculateWeeks ( string $ deliveryDate , string $ referenceDate ) : int { $ timestampDeliveryDate = $ this -> DM -> convertDateToTimestamp ( $ deliveryDate ) ; $ timestampReferenceDate = $ this -> DM -> convertDateToTimestamp ( $ referenceDate ) ; $ timestampConceptionDate = $ timestampDeliveryDate - $ ...
Calculate the weeks of pregnancy
6,078
public function calculateDays ( string $ deliveryDate , string $ referenceDate ) : int { $ timestampDeliveryDate = $ this -> DM -> convertDateToTimestamp ( $ deliveryDate ) ; $ timestampReferenceDate = $ this -> DM -> convertDateToTimestamp ( $ referenceDate ) ; $ timestampConceptionDate = $ timestampDeliveryDate - $ t...
Calculate the days of pregnancy
6,079
public function calculateWeeksByTimestamp ( int $ timestampDeliveryDate , int $ timestampReferenceDate ) : int { $ timestampConceptionDate = $ timestampDeliveryDate - $ this -> pregnancyDuration ; return ceil ( ( $ timestampReferenceDate - $ timestampConceptionDate ) / $ this -> periodWeek ) ; }
Calculate the weeks of pregnancy by Timestamp
6,080
public function calculateDaysByTimestamp ( int $ timestampDeliveryDate , int $ timestampReferenceDate ) : int { $ timestampConceptionDate = $ timestampDeliveryDate - $ this -> pregnancyDuration ; return ceil ( ( $ timestampReferenceDate - $ timestampConceptionDate ) / $ this -> periodDay ) ; }
Calculate the days of pregnancy by Timestamp
6,081
public static function getMetas ( \ DOMDocument $ html ) { $ metas = [ ] ; foreach ( $ html -> getElementsByTagName ( 'meta' ) as $ meta ) { $ name = trim ( strtolower ( $ meta -> getAttribute ( 'property' ) ? : $ meta -> getAttribute ( 'name' ) ) ) ; $ value = $ meta -> getAttribute ( 'content' ) ? : $ meta -> getAttr...
Extract all meta elements from html
6,082
public static function getLinks ( \ DOMDocument $ html , $ tagName = 'link' ) { $ links = [ ] ; foreach ( $ html -> getElementsByTagName ( $ tagName ) as $ link ) { if ( $ link -> hasAttribute ( 'rel' ) && $ link -> hasAttribute ( 'href' ) ) { $ rel = trim ( strtolower ( $ link -> getAttribute ( 'rel' ) ) ) ; $ href = ...
Extract all link elements from html
6,083
public static function getData ( array $ providers , $ name , Url $ url = null ) { $ method = 'get' . $ name ; $ values = [ ] ; foreach ( $ providers as $ key => $ provider ) { $ value = $ provider -> $ method ( ) ; if ( empty ( $ value ) ) { continue ; } if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } foreac...
Search and returns all data retrieved by the providers
6,084
public static function sortByProviders ( array $ values ) { $ sorted = [ ] ; foreach ( $ values as $ value ) { foreach ( $ value [ 'providers' ] as $ provider ) { if ( ! isset ( $ sorted [ $ provider ] ) ) { $ sorted [ $ provider ] = [ $ value ] ; } else { $ sorted [ $ provider ] [ ] = $ value ; } } } return $ sorted ;...
Order the data by provider
6,085
public static function unshiftValue ( array & $ values , $ value ) { $ key = Utils :: searchValue ( $ values , $ value [ 'value' ] , true ) ; if ( $ key === false ) { return array_unshift ( $ values , $ value ) ; } $ value = array_merge ( $ values [ $ key ] , $ value ) ; array_splice ( $ values , $ key , 1 ) ; return a...
Unshifts a new value if it does not exists
6,086
public static function searchValue ( array $ values , $ value , $ returnKey = false ) { foreach ( $ values as $ k => $ each ) { if ( $ each [ 'value' ] === $ value ) { return $ returnKey ? $ k : $ each ; } } return false ; }
Search by a value and returns its key
6,087
public static function getMostPopularValue ( array $ values , $ returnKey = false ) { $ mostPopular = null ; foreach ( $ values as $ k => $ value ) { if ( $ mostPopular === null || count ( $ value [ 'providers' ] ) > count ( $ values [ $ mostPopular ] [ 'providers' ] ) ) { $ mostPopular = $ k ; } } if ( isset ( $ mostP...
Returns the most popular value in an array
6,088
public static function getBiggerValue ( array $ values , $ returnKey = false ) { $ bigger = null ; foreach ( $ values as $ k => $ value ) { if ( $ bigger === null || $ value [ 'size' ] > $ values [ $ bigger ] [ 'size' ] ) { $ bigger = $ k ; } } if ( $ bigger !== null ) { return $ returnKey ? $ bigger : $ values [ $ big...
Returns the bigger value
6,089
public function render ( ) : string { $ html = "<meta charset=\"utf-8\">" ; $ html .= '<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">' ; $ html .= preg_match ( "/^\/admin/" , array_key_exists ( 'path' , $ parsed = parse_url ( app ( 'request' ) -> url ( ) ) ) ? $ parsed [ 'path' ] : '' ) ? Helper :: ...
Function for return rendered head html
6,090
public static function with ( $ preset ) { $ cname = get_called_class ( ) ; if ( ! array_key_exists ( $ cname , self :: $ preset_cache ) || is_null ( self :: $ preset_cache [ $ cname ] ) ) { self :: $ preset_cache [ $ cname ] = array ( ) ; } if ( ! array_key_exists ( $ preset , self :: $ preset_cache [ $ cname ] ) || i...
Create a preset proxy
6,091
public function selectValue ( $ sql ) { $ result = $ this -> execute ( $ sql ) ; if ( $ result -> count ( ) ) { $ row = $ result -> current ( ) ; return reset ( $ row ) ; } }
Returns a single value ; i . e . the first column value of the first row . E . g . SELECT id FROM users WHERE name = foo - > 1
6,092
public function __async_save ( $ navID = 0 , $ parentId = 0 ) { $ data = null ; if ( dbQuery ( '\samson\cms\web\navigation\CMSNav' ) -> StructureID ( $ navID ) -> first ( $ data ) ) { $ data -> update ( ) ; } else { $ nav = new \ samson \ cms \ web \ navigation \ CMSNav ( false ) ; $ nav -> Created = date ( 'Y-m-d H:m:...
Saving or creating new structure
6,093
public function __async_handle_application ( $ navID = 0 ) { $ data = null ; $ generate = ( int ) $ _REQUEST [ 'generate' ] ; $ output = $ generate === 0 ? 0 : ( int ) $ _REQUEST [ 'output' ] ; if ( dbQuery ( '\samson\cms\web\navigation\CMSNav' ) -> StructureID ( $ navID ) -> first ( $ data ) ) { $ data -> applicationO...
Saving data about generation and output the application of structure
6,094
private function send ( RequestInterface $ request , ResponseInterface $ response ) { if ( ! headers_sent ( ) ) { $ this -> sendHeaders ( $ response ) ; } if ( ob_get_level ( ) > 1 ) { while ( ob_get_level ( ) >= $ this -> outputBufferLevel ) { ob_end_flush ( ) ; } } $ this -> outputBufferLevel = null ; if ( $ request ...
Send the response to the client by first sending all headers and then echoing the response body .
6,095
private function sendHeaders ( ResponseInterface $ response ) { if ( $ response -> getReasonPhrase ( ) ) { header ( sprintf ( 'HTTP/%s %d %s' , $ response -> getProtocolVersion ( ) , $ response -> getStatusCode ( ) , $ response -> getReasonPhrase ( ) ) ) ; } else { header ( sprintf ( 'HTTP/%s %d' , $ response -> getPro...
Send all headers to the client
6,096
private function sanitizeHeaderName ( $ name ) { $ name = str_replace ( '-' , ' ' , $ name ) ; $ name = ucwords ( $ name ) ; return str_replace ( ' ' , '-' , $ name ) ; }
Filter header by making all words first letter uppercase and making sure all spaces are replaced with dashes - .
6,097
public function PreDispatch ( ) { $ form = & $ this -> form ; if ( $ this instanceof \ MvcCore \ Ext \ Forms \ Fields \ IVisibleField && $ this -> renderMode === NULL ) $ this -> renderMode = $ form -> GetDefaultFieldsRenderMode ( ) ; if ( $ this -> translate && $ this instanceof \ MvcCore \ Ext \ Forms \ Fields \ ILab...
This INTERNAL method is called from \ MvcCore \ Ext \ Form just before field is naturally rendered . It sets up field for rendering process . Do not use this method even if you don t develop any form field . - Set up field render mode if not defined . - Translate label text if necessary .
6,098
public function Submit ( array & $ rawRequestParams = [ ] ) { $ result = NULL ; $ fieldName = $ this -> name ; if ( $ this instanceof \ MvcCore \ Ext \ Forms \ Fields \ IVisibleField && ( $ this -> readOnly || $ this -> disabled ) ) { $ result = $ this -> value ; } else { $ result = NULL ; if ( isset ( $ rawRequestPara...
This INTERNAL method is called from \ MvcCore \ Ext \ Form in submit processing . Do not use this method even if you don t develop form library or any form field .
6,099
public function & GetValidatorData ( $ fieldPropsDefaultValidValues = [ ] ) { $ result = [ ] ; foreach ( $ fieldPropsDefaultValidValues as $ propName => $ defaultValidatorValue ) { if ( property_exists ( $ this , $ propName ) ) $ result [ $ propName ] = $ this -> { $ propName } ; } return $ result ; }
Default implementation for any extended field class to get field specific data for validator purposes . If you want to extend any field you could implement this method better and faster . It s only necessary in your implementation to return array with keys to be field specific properties in camel case and values to be ...